making an api call error 126 (findWindow)
I'm trying to get a handle to a window, so I need to make an call to the api to the findwindow function..
so I declare:
Declare
Function FindWindowLib "User32"Alias "FindWindowA" _
(ByVal lpClassNameAsString,ByVal lpWindowNameAsString)AsLongPublic
WinWndAsLong
and make the call inside a sub:
Dim windowNameAsString
windowName = "Title"
WinWnd = FindWindow(vbNullString, windowName)
WinWnd gets trash, end the error variable is set to 126, wich means specific module not loaded
I tried to put the auto keyword, not sure what it means but I saw it on an example on making api call in msn website (waltrough to making api call in vb.net or something like) but it instead of giving 126 he gives 127 error #What I am trying to accomplish is to get the window handle from it's name, what I need is to detect if the user pressed ctrl in other window than the app I'm working, so I need to set up a hook
any other way to get the window handle?
thanks in advance
marcel
[2253 byte] By [
punk] at [2007-12-16]
thanks, no error now, the problem might be elsewhere or not...
the difference was just in the declaration of findwindow
the error number after calling findwindow is 0
the value of the handle returned byt window appears to be trash, a very high number.. but
when testing the handle with : Const
SW_SHOWNORMAL = 1
Public WinWnd As New IntPtr(0)
Declare Auto Function FindWindow Lib "user32" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As IntPtr
Declare Function ShowWindow Lib "User32" (ByVal Hwnd As IntPtr, _
ByVal nCmdShow As Long) As Long 'the original Hwnd was long, but I changed to IntPtr because of the declaration of findWindowand call it as:
WinWnd = FindWindow(vbNullString, windowName)
ShowWindow(WinWnd, SW_SHOWNORMAL)error # is 0, but nothing happens, also the value returned by showWindow looks like trash..
thanks again
marcel
sorry for the bunch of replies, I'm still working with the code..
I was testing with a window called test.txt - Notepad
looks like the problem is with the .
if I rename the file just for test it woks.. but just for the first time, if I try to run it again it doesn't work, I have to close and open my app
anyway, I got it working by calling AppActivate(windowName)
just before ShowWindow since AppActive doesn't works properly sometimes..
now I have to hook the keyboard, I'll just create another thread...