API declaration in codes, how to do setting in object
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
21-05-21 10:47 AM
May I have your help based on the below codes:
Option Explicit
Private Declare Function PostMessage Lib "User32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Const WM_CLOSE = &H10
Private Sub Command1_Click()
Dim winHwnd As Long
Dim RetVal As Long
winHwnd = FindWindow(vbNullString,
Debug.Print winHwnd
If winHwnd <> 0 Then
RetVal = PostMessage(winHwnd, WM_CLOSE, 0&, 0&)
If RetVal = 0 Then
MsgBox "错误!"
Else
MsgBox "成功关闭WINDOWS窗口!"
End If
Else
MsgBox "WINDOWS窗口没有发现!"
End If
End Sub
------------------------------
Eric Li
Operation Analysis
AIG
Asia/Hong_Kong
------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
21-05-21 11:01 AM
Although, I wonder why would you need to use winapi, when blueprism can do the same natively - try attaching to a window and close it.
MsgBox (one of the MessageBox*) would need to be declared too and then bot would stop every time it pops up and wait for result.. do you really want that? There is no debug.print either.
p.s. code is not complete here: winHwnd = FindWindow(vbNullString, ???
------------------------------
Andrey Kudinov
Project Manager
MobileTelesystems PJSC
Europe/Moscow
------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
21-05-21 11:52 AM
Thank you, Andrey
The target window cannot be attached on whatever ways I have tried. So want to use code to close it.
The MsgBox I will revised it later.
Yes, winHwnd is not complete, I missed something when doing copy.
Eric Li
AIG
Automation Delivery Team | China Service Center
9F, The Centerpoint (Shuion), 374-2 Beijing Road, Guangzhou, China 510030
Tel: (+86 20) 2882 5022
Eric-F.Li@aig.com | www.aig.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
21-05-21 03:02 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
24-05-21 04:26 AM
Thanks, Andrey. Using check code function, system indicate the compiler error as attached screen.
Eric Li
AIG
Automation Delivery Team | China Service Center
9F, The Centerpoint (Shuion), 374-2 Beijing Road, Guangzhou, China 510030
Tel: (+86 20) 2882 5022
Eric-F.Li@aig.com | www.aig.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
24-05-21 07:57 AM
------------------------------
Andrey Kudinov
Project Manager
MobileTelesystems PJSC
Europe/Moscow
------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
26-05-21 03:00 AM
Many thanks! Andrey. It works after replaced with Nothing.
Eric Li
AIG
Automation Delivery Team | China Service Center
9F, The Centerpoint (Shuion), 374-2 Beijing Road, Guangzhou, China 510030
Tel: (+86 20) 2882 5022
Eric-F.Li@aig.com | www.aig.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
26-05-21 03:09 AM
One more question, is it possible to use wildcard on the windows name. Because the windows I am suffering have different name, but they have the same prefix name.
Eric Li
AIG
Automation Delivery Team | China Service Center
9F, The Centerpoint (Shuion), 374-2 Beijing Road, Guangzhou, China 510030
Tel: (+86 20) 2882 5022
Eric-F.Li@aig.com | www.aig.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
26-05-21 08:39 AM
Otherwise, you'd have to use EnumWindows API to get all windows and look for the one you need afaik.
https://www.pinvoke.net/default.aspx/user32.EnumWindows
------------------------------
Andrey Kudinov
Project Manager
MobileTelesystems PJSC
Europe/Moscow
------------------------------
