Guidance
指路人
g.yi.org
Guidance Forums / Rapid-Q Basic / Api function

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. 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
Message2. Re: Api function
#746
Posted by: guidance 2003-01-23 23:03:20
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
Message3. 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
Message4. 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
Message5. 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 First 1 Last
掌柜推荐
 
 
¥287.00 ·
 
 
¥2,600.00 ·
 
 
¥289.00 ·
 
 
¥1,370.00 ·
 
 
¥289.00 ·
 
 
¥1,480.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0