From: Jake Thompson on
On Feb 4, 2:40 pm, Armin Zingler <az.nos...(a)freenet.de> wrote:
> Jake Thompson schrieb:
>
> > Private Declare Function OpenProcess Lib "kernel32" (ByVal
> > dwDesiredAccess As UInt32, ByVal blnheritHandle As Boolean, ByVal
> > dwAppProcessId As UInt32) As UInt32
>
> Why did you change the type of the return value? IntPtr was correct.
>
> >     Private Declare Function ShowWindow Lib "user32" (ByVal handle As
> > UInt32, ByVal nCmdShow As UInt32) As UInt32
>
> Now the 1st argument is wrong. Must be IntPtr. nCmdShow should be Int32 (Integer),
> but that's no problem in practice. Return value can be declared As Boolean.
>
> > Private Sub BTNShow_Click(ByVal sender As System.Object, ByVal e As
> > System.EventArgs) Handles BTNShow.Click
> >       Dim hWnd As UInt32
>
>         hwnd as intptr
>
> >             Dim theid As String = selection.Substring(40, 4)
>
> Store the IDs in appropriate types, Integer in this case.
>
>              Dim theid As integer = integer.parse(selection.Substring(40, 4))
>
> >             Dim pid As String
>
>               Dim pid As integer
>
> >                 pid = p.Id.ToString
>
>                   pid = p.Id
>
> >                     theerror = GetLastError()
>
> Use Marshal.GetLastWin32Error instead as I told you.
>
> --
> Armin



Got it working using MainWindowHandle turns out i did not have to use
openprocess after all

Private Declare Function ShowWindow Lib "user32" (ByVal handle As
UInt32, ByVal nCmdShow As Integer) As Integer

Const SW_MAXIMIZE As Integer = 3
Const SW_RESTORE As Integer = 9
Const SHOWNORMAL As Integer = 1
Const SW_MINIMIZE As Integer = 6
Const SW_HIDE As Integer = 0

Dim hWnd As UInt32
Dim theid As String = selection.Substring(26, 6)
Dim pid As String
Dim theProcesses() As Process = Process.GetProcessesByName("Foo")
For Each p As Process In theProcesses
pid = p.Id.ToString("000000")
If theid = pid Then
hWnd = p.MainWindowHandle.ToInt32
ShowWindow(hWnd, SHOWNORMAL)


Thanks Jake


From: Armin Zingler on
Jake Thompson schrieb:
> Got it working using MainWindowHandle turns out i did not have to use
> openprocess after all
>
> Private Declare Function ShowWindow Lib "user32" (ByVal handle As
> UInt32, ByVal nCmdShow As Integer) As Integer

Still: ByVal handle As IntPtr. Otherwise it fails on 64 bit OS.
And if you will ever be interested in the return value, it's
not wrong to declare it As Boolean.

> Dim hWnd As UInt32

Dim hWnd As IntPtr


> Dim theid As String = selection.Substring(26, 6)
> Dim pid As String
> Dim theProcesses() As Process = Process.GetProcessesByName("Foo")
> For Each p As Process In theProcesses
> pid = p.Id.ToString("000000")
> If theid = pid Then

Why do you treat numbers as Strings?

> hWnd = p.MainWindowHandle.ToInt32

hWnd = p.MainWindowHandle


--
Armin