close msgbox programmatically

  • Thread starter Thread starter Matteo Gabella
  • Start date Start date
M

Matteo Gabella

hi all, is there a way to close msgbox programmatically?
(i need to drop a system "Pocket Pc Networking" msgbox...)
i've checked for "SetWindowsHookEx" but it seems to be absent from CF APIs...
any suggestion?
tx
matteo gabella
www.stranigiorni.com
 
There may be a better way but this VB code works for me and should give you
a starter if your scenario is different...

' only ever 1 msgbox in our scenario
' else we have to check for title with GetWindowTextW
Dim hwnd As IntPtr
hwnd = Win32Api.FindWindow("Dialog", Nothing)
If IntPtr.op_Equality(hwnd, IntPtr.Zero) = False Then
Win32Api.PostMessage(hwnd, Win32Api.WM_CLOSE, 0, 0)
Win32Api.PostMessage(hwnd, Win32Api.WM_DESTROY, 0,
0)
End If

Cheers
Daniel
 
Wouldn't it be better to send WM_COMMAND with WPARAM set to IDOK or
IDCANCEL?
 
Dunno :-) It looks cleaner and less brutal (although I doubt it makes any
difference in the case of a message box)...

The question is will that work with YES|NO boxes etc? In my use case the
code wants to close any messagebox that happens to be up...

Cheers
Daniel
 
That's what I thought... there should be a IDDEFAULT for those bad devs
amongst us (that's me!) that want to close anybody's msgbox... Until then
I'll stick with WM_DESTROYing the universe... :-)

On a more serious note the code runs on our unit with no other apps [1], so
our approach is not the end of the world... Just added a comment to review
this if I ever move the code to a PocketPC...

Cheers
Daniel

[1]
http://www.zen13120.zen.co.uk/Blog/2004/08/my-cf-application-and-platform-it.html
 
your solution is right, because i don't know if this msgbox really
exists and if it's focused (maybe is under my app)...
but i have a problem: i try your code but i get a
"System.MissingMethodException" Exception on PostMessage

here's my code... (I could not find Win32Api namespace... is it any of
your classes?)

Declare Function PostMessage Lib "user32" (ByVal hWnd As IntPtr, ByVal
Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As
Integer

Const WM_CLOSE = &H10
Const WM_DESTROY = &H2

Dim hwnd As IntPtr

Dim a As Integer
a = PostMessage(hwnd, WM_CLOSE, 0, 0)
a = PostMessage(hwnd, WM_DESTROY, 0, 0)


what's wrong?
thank you!
matteo
 
Hi

<DllImport(DllName4)> _
Public Shared Function PostMessage(ByVal hWnd As IntPtr, ByVal wMsg As
Int32, ByVal wParam As Int32, ByVal lParam As Int32) As IntPtr
End Function

Cheers
Daniel
 
Sorry... DllName4 was cryptic... Paul has answered your question already..
use coredll... also look at openetcf for a wealth of good code...

My Win32Api class conditionally compiles for the desktop/CE... it starts
something like this (where FULL_FRAME defined in your project properties):

#If FULL_FRAME = True Then
Private Const DllName As String = "advapi32.dll"
Private Const DllName2 As String = "kernel32.dll"
Private Const DllName3 As String = "Version.dll"
Private Const DllName4 As String = "user32.dll"
#Else
Private Const DllName As String = "coredll.dll"
Private Const DllName2 As String = "coredll.dll"
Private Const DllName3 As String = "coredll.dll"
Private Const DllName4 As String = "coredll.dll"
#End If

Cheers
Daniel
 
Back
Top