Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

close msgbox programmatically

246 views
Skip to first unread message

Matteo Gabella

unread,
Aug 25, 2004, 11:51:16 AM8/25/04
to
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

Daniel Moth

unread,
Aug 25, 2004, 2:08:26 PM8/25/04
to
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

"Matteo Gabella" <gabu...@tin.it> wrote in message
news:bda2e795.04082...@posting.google.com...

Alex Feinman [MVP]

unread,
Aug 25, 2004, 3:29:50 PM8/25/04
to
Wouldn't it be better to send WM_COMMAND with WPARAM set to IDOK or
IDCANCEL?

--
Alex Feinman
---
Visit http://www.opennetcf.org
"Daniel Moth" <dmo...@hotmail.com> wrote in message
news:%23Lwz17s...@TK2MSFTNGP09.phx.gbl...

Daniel Moth

unread,
Aug 25, 2004, 6:20:58 PM8/25/04
to
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


"Alex Feinman [MVP]" <publi...@alexfeinman.com> wrote in message
news:u7GTknti...@tk2msftngp13.phx.gbl...

Alex Feinman [MVP]

unread,
Aug 25, 2004, 8:54:01 PM8/25/04
to
That would be IDYES - less chances to close someone else's box :-)

--
Alex Feinman
---
Visit http://www.opennetcf.org
"Daniel Moth" <dmo...@hotmail.com> wrote in message

news:uIyR9Iv...@TK2MSFTNGP12.phx.gbl...

Daniel Moth

unread,
Aug 26, 2004, 6:21:44 AM8/26/04
to
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


"Alex Feinman [MVP]" <publi...@alexfeinman.com> wrote in message

news:uSiLtcwi...@TK2MSFTNGP09.phx.gbl...

Matteo Gabella

unread,
Aug 27, 2004, 11:55:41 AM8/27/04
to
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

Paul Monson (BSQUARE)

unread,
Aug 27, 2004, 12:05:11 PM8/27/04
to
PostMessage is in "coredll" on windows ce.

The Win32Api namespace is part of SDF which is found at http://opennetcf.org

-Paul

Paul Monson (BSQUARE)

unread,
Aug 27, 2004, 2:05:00 PM8/27/04
to
Sorry about that. Win32Api is not part of SDF

Daniel Moth

unread,
Aug 27, 2004, 2:37:56 PM8/27/04
to
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

"Matteo Gabella" <gabu...@tin.it> wrote in message
news:bda2e795.04082...@posting.google.com...

Alex Feinman [MVP]

unread,
Aug 27, 2004, 3:26:24 PM8/27/04
to
It was moved around v1.1. It is now a method of Win32.Win32Window for
consistency with the desktop:
http://www.opennetcf.org/library/OpenNETCF.Win32.Win32Window.PostMessage.html

--
Alex Feinman
---
Visit http://www.opennetcf.org

"Paul Monson (BSQUARE)" <"paulmonson_7 no spam AT hotmail DOT com"> wrote in
message news:ugGR6AGj...@TK2MSFTNGP09.phx.gbl...

Daniel Moth

unread,
Aug 27, 2004, 6:25:53 PM8/27/04
to
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

"Daniel Moth" <dmo...@hotmail.com> wrote in message

news:uHNXrVG...@tk2msftngp13.phx.gbl...

0 new messages