| Forum List • Thread List • Refresh • New Topic • Search • Previous • Next 1 | 1. Api function #745 Posted by: 2003-01-23 22:46:32 | I'm trying to make a program that closes another program at a given time of the day, using the Api function to close the window. I found the code for the Api, it compiles but does not work. This is the code:
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Declare Function PostMessage2 Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long Declare Function ShowWindow Lib "user32" Alias "ShowWindow"(ByVal hwnd As Long, ByVal nCmdShow As Long) As Long Declare Function SetFocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long Const SW_SHOWNORMAL = 1 Const WM_CLOSE = &H10
Sub Vai(sender as QButton) Dim WinWnd As Long, Ret As String, RetVal As Long, lpClassName As String 'Ask for a Window title Ret = "Senza nome - Blocco note" 'Search the window WinWnd = FindWindow(vbnullstring, Ret) 'If WinWnd = 0 Then MsgBox "Couldn't find the window ...": Exit Sub 'Show the window ShowWindow WinWnd, SW_SHOWNORMAL 'Create a buffer lpClassName = Space(256) 'retrieve the class name RetVal = GetClassName(WinWnd, lpClassName, 256) 'Show the classname 'MsgBox "Classname: " + Left$(lpClassName, RetVal) 'Post a message to the window to close itself PostMessage2 (WinWnd, WM_CLOSE, 0&, 0&) End Sub
I think the problem is in the FindWindow function (it always returns 0). At least that should be the first problem...
Thank you all.
Cajino | 2. Re: Api function #746 | What's your VBNullString? I'm afraid that you must offer a ClassName for FindWindow(), like previnst.bas: http://h.ods.org/_scripts/file.php?f=1572&r=2330
There's an excellent tool to show what class name a window or control is: http://h.ods.org/_scripts/file.php?f=1829&r=2330#1713 | 3. Re: Api function #747 Posted by: 2003-01-24 00:56:22 | Hello Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByRef lpClassName As String, ByRef lpWindowName As String) As Long ' DefStr sAppName = "Your App Name" ' Found In Ctrl Alt Delete List IE DefStr sNullString = "" hApp = FindWindow (sNullString, sAppName)
' ' Note : ' - the ByRef in API Declaration ' - that the string arguments of apis must exist as Declared String
Jacques | 4. Re: Api function #748 Posted by: 2003-01-24 16:39:04 | Thank you guys, my program works now (and solved an annoying problem at work).
Have a nice day.
Cajino | 5. Re: Api function #754 Posted by: 2003-01-25 06:47:25 | Hehe, this is funny.. I made the program, and it was OK, but when I applied it to the situation it had to deal with it just didn't work! I tried and tried, but the damned program it had to close just didn't react at all. What was wrong? The genius who created it made so that the window's name ended with a space (which doesn't show when you press Ctrl-Alt-Canc). I tried it just because I started to go nuts and heard voices... Bye | Forum List • Thread List • Refresh • New Topic • Search • Previous • Next 1 |
|
|