|
-
Nov 14th, 2000, 09:37 AM
#1
Thread Starter
New Member
Hello all,
I am displaying a Windows message box using the 'MessageBoxEx' API call. Now I am trying to implement an auto loggoff feature in my application that closes all the application windows and re-displays the Log-On dialog box after X minutes of inactivity in my application. But the problem is that the message box is still on the screen after auto loggoff. I now need a way to automatically close the message box if it is displayed. Does anyone know how to do this?
Thanks
Anthony
-
Nov 14th, 2000, 03:23 PM
#2
After the messagebox pops up, you can use SendMessage to send the Enter Key to dismiss the dialog box.
-
Nov 14th, 2000, 03:37 PM
#3
Thread Starter
New Member
The only problem with using the SendMessage is that I do not have the hwnd of the Message Box. I am using the currently active window as the Message Box "parent" in the call to MessageBoxEx, but I am not sure how to go about getting the hwnd for the Message Box to use the SendMessage call.
-
Nov 14th, 2000, 08:29 PM
#4
How are you calling the message box? Can you show your code?
-
Nov 15th, 2000, 09:00 AM
#5
Thread Starter
New Member
Hello Matthew,
Here is the code that I am using...
Just create a form with a command button on it and add this code...
Code:
Option Explicit
Private Const LANG_ENGLISH As Long = &H9
Private Declare Function MessageBoxEx Lib "user32" Alias "MessageBoxExA" (ByVal hWnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal uType As Long, ByVal wLanguageId As Long) As Long
Private Sub Command1_Click()
Dim bResult As VbMsgBoxResult
bResult = MessageBoxEx(Me.hWnd, "Displaying Message Box with 'MessageBoxEx' API Call.", "Test Message", VbMsgBoxStyle.vbExclamation Or VbMsgBoxStyle.vbOKOnly, LANG_ENGLISH)
End Sub
-
Nov 16th, 2000, 09:16 AM
#6
New Member
I can only presume from what you have said that the message
box is floating without the original 'parent' window (ie me.hwnd) existing. If this is the case then you need to
use GetWindow and GetWindowText to search through all current windows that are open and get the handle to your message box by searching for the "Test Message" window text (as in the example in your posting). You can start the search by using the GetDesktopWindow call and then calling GetWindow using the desktop window's handle ID.
Create a module with this code:
Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, _
ByVal wCmd As Long) As Long
Declare Function GetWindowText Lib "user32" Alias _
"GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, _
ByVal cch As Long) As Long
Declare Function GetDesktopWindow Lib "user32" () As Long
Public Const GW_CHILD = 5
Public Const GW_HWNDNEXT = 2
Insert this code for a command button (eg.):
Dim hwnd1 As Long
Dim hwnd2 As Long
Dim stringholder As String
stringholder = Space(255)
hwnd1 = GetDesktopWindow()
hwnd1 = GetWindow(hwnd1, GW_CHILD)
hwnd2 = GetWindowText(hwnd1, stringholder, 255)
hwnd1 = GetDesktopWindow()
hwnd1 = GetWindow(hwnd1, GW_CHILD)
hwnd2 = GetWindowText(hwnd1, stringholder, 255)
Do While hwnd1 <> 0
hwnd1 = GetWindow(hwnd1, GW_HWNDNEXT)
hwnd2 = GetWindowText(hwnd1, stringholder, 255)
If Left(stringholder, 12) = "Test Message" Then
MsgBox "Handle to msgbox=" & hwnd1
End If
DoEvents
hwnd1 = GetWindow(hwnd1, GW_HWNDNEXT)
hwnd2 = GetWindowText(hwnd1, stringholder, 255)
If Left(stringholder, 12) = "Test Message" Then
MsgBox "Handle to msgbox=" & hwnd1
End If
Loop
This code was tested in a separate app. from the application which displayed your messagebox.
It is not an elegant solution but will work.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|