PC Review


Reply
Thread Tools Rate Thread

close msgbox programmatically

 
 
Matteo Gabella
Guest
Posts: n/a
 
      25th Aug 2004
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
 
Reply With Quote
 
 
 
 
Daniel Moth
Guest
Posts: n/a
 
      25th Aug 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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




 
Reply With Quote
 
Alex Feinman [MVP]
Guest
Posts: n/a
 
      25th Aug 2004
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" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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

>
>
>



 
Reply With Quote
 
Daniel Moth
Guest
Posts: n/a
 
      25th Aug 2004
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]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > 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" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> >> 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

> >
> >
> >

>
>



 
Reply With Quote
 
Alex Feinman [MVP]
Guest
Posts: n/a
 
      26th Aug 2004
That would be IDYES - less chances to close someone else's box :-)

--
Alex Feinman
---
Visit http://www.opennetcf.org
"Daniel Moth" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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]" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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" <(E-Mail Removed)> wrote in message
>> news:%(E-Mail Removed)...
>> > 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" <(E-Mail Removed)> wrote in message
>> > news:(E-Mail Removed)...
>> >> 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
>> >
>> >
>> >

>>
>>

>
>



 
Reply With Quote
 
Daniel Moth
Guest
Posts: n/a
 
      26th Aug 2004
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/2...atform-it.html


"Alex Feinman [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> That would be IDYES - less chances to close someone else's box :-)
>
> --
> Alex Feinman
> ---
> Visit http://www.opennetcf.org
> "Daniel Moth" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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]" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> >> 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" <(E-Mail Removed)> wrote in message
> >> news:%(E-Mail Removed)...
> >> > 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" <(E-Mail Removed)> wrote in message
> >> > news:(E-Mail Removed)...
> >> >> 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
> >> >
> >> >
> >> >
> >>
> >>

> >
> >

>
>






 
Reply With Quote
 
Matteo Gabella
Guest
Posts: n/a
 
      27th Aug 2004
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
 
Reply With Quote
 
Paul Monson (BSQUARE)
Guest
Posts: n/a
 
      27th Aug 2004
PostMessage is in "coredll" on windows ce.

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

-Paul

Matteo Gabella wrote:
> 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

 
Reply With Quote
 
Paul Monson (BSQUARE)
Guest
Posts: n/a
 
      27th Aug 2004
Sorry about that. Win32Api is not part of SDF

Paul Monson (BSQUARE) wrote:
> PostMessage is in "coredll" on windows ce.
>
> The Win32Api namespace is part of SDF which is found at
> http://opennetcf.org
>
> -Paul
>
> Matteo Gabella wrote:
>
>> 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

 
Reply With Quote
 
Daniel Moth
Guest
Posts: n/a
 
      27th Aug 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Msgbox Close with vba art Microsoft Excel Programming 10 20th Nov 2008 01:23 PM
close msgbox =?Utf-8?B?RGFu?= Microsoft Excel Programming 4 30th Jul 2007 07:40 PM
Close a msgbox John Wright Microsoft VB .NET 2 22nd Apr 2006 06:36 AM
Close msgbox ? Buddy Lee Microsoft Excel Programming 3 22nd Nov 2005 04:14 PM
Close MsgBox dbl Microsoft Access Reports 3 24th Mar 2005 07:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:33 PM.