|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
SendMessage vs. PostMessageI'm closing applications from my app. These are the declarations. Private Declare Function SendMessage Lib "user32" _ Alias "SendMessageA" (ByVal hWnd As Long, _ ByVal wMsg As Long, ByVal wParam As Long, _ lParam As Any) AsLong Private Declare Function PostMessage Lib "user32" _ (ByVal hWnd As Long, ByVal wMsg As Long, _ ByVal wParam As Long, lParam As Any) As Long Is there any reason that using PostMessage, the applications will not close but if I use SendMessage it will ? This works: SendMessage iHwnd, WM_CLOSE, 0&, 0& This doesn't: PostMessage iHwnd, WM_CLOSE, 0&, 0& TIA, DanS DanS <t.h.i.s.n.t.h.a.t@a.d.e.l.p.h.i.a..n.e.t> wrote in
news:Xns978B6A7FDC136idispcom@216.196.97.142: Dammit. I didn't see it until I read this post.Bad Declare. Show quoteHide quote > Hello all, > > I'm closing applications from my app. > > These are the declarations. > > Private Declare Function SendMessage Lib "user32" _ > Alias "SendMessageA" (ByVal hWnd As Long, _ > ByVal wMsg As Long, ByVal wParam As Long, _ > lParam As Any) AsLong > Private Declare Function PostMessage Lib "user32" _ > (ByVal hWnd As Long, ByVal wMsg As Long, _ > ByVal wParam As Long, lParam As Any) As Long > > Is there any reason that using PostMessage, the applications will not > close but if I use SendMessage it will ? > > This works: SendMessage iHwnd, WM_CLOSE, 0&, 0& > > This doesn't: PostMessage iHwnd, WM_CLOSE, 0&, 0& > > > TIA, > > DanS > On Sun, 19 Mar 2006 11:03:53 -0600, DanS
<t.h.i.s.n.t.h.a.t@a.d.e.l.p.h.i.a..n.e.t> wrote: >DanS <t.h.i.s.n.t.h.a.t@a.d.e.l.p.h.i.a..n.e.t> wrote in I don't see that.>news:Xns978B6A7FDC136idispcom@216.196.97.142: > >Dammit. I didn't see it until I read this post. > >Bad Declare. You are invoking both incorrectly :- SendMessage iHwnd, WM_CLOSE, 0&, ByVal 0& <--- The ByVal is essential as otherwise you are sending the address of a Long containing 0& PostMessage and SendMessage are really the same thing (well for Apps in different Processes) PostMessage expects no return result so it returns immediately SendMessage expects a return result, so your App waits until the other App has processed the Message. Within the same App SendMessage behaves just like a Call, I don't think it ever really gets put on the App's Message Queue PostMessage definitely gets shoved on the Message Queue and is not processes until you do an explicit or implicit DoEvents. erew***@nowhere.uk (J French) wrote in news:441e620d.508798062
@news.btopenworld.com: > On Sun, 19 Mar 2006 11:03:53 -0600, DanS I don't know where the PostMessage declare came from originally, I would ><t.h.i.s.n.t.h.a.t@a.d.e.l.p.h.i.a..n.e.t> wrote: > >>DanS <t.h.i.s.n.t.h.a.t@a.d.e.l.p.h.i.a..n.e.t> wrote in >>news:Xns978B6A7FDC136idispcom@216.196.97.142: >> >>Dammit. I didn't see it until I read this post. >> >>Bad Declare. > > I don't see that. have thought it was from the API viewer, but there was no Alias in it. On Mon, 20 Mar 2006 06:26:26 -0600, DanS
<t.h.i.s.n.t.h.a.t@a.d.e.l.p.h.i.a..n.e.t> wrote: <snip> >I don't know where the PostMessage declare came from originally, I would I did not spot that - it should have crunched>have thought it was from the API viewer, but there was no Alias in it. There are bad declares in at least one of the AllAPI examples, but mostly they are solid erew***@nowhere.uk (J French) wrote in news:441eac6b.527838706
@news.btopenworld.com: > On Mon, 20 Mar 2006 06:26:26 -0600, DanS I did find another, I can't remeber what it was, but it was wrong in both ><t.h.i.s.n.t.h.a.t@a.d.e.l.p.h.i.a..n.e.t> wrote: > ><snip> > >>I don't know where the PostMessage declare came from originally, I would >>have thought it was from the API viewer, but there was no Alias in it. > > I did not spot that - it should have crunched > > There are bad declares in at least one of the AllAPI examples, but > mostly they are solid > the VB API AND API Viewer 2004. On Tue, 21 Mar 2006 06:23:31 -0600, DanS
<t.h.i.s.n.t.h.a.t@a.d.e.l.p.h.i.a..n.e.t> wrote: <snip> >I did find another, I can't remeber what it was, but it was wrong in both The All API example contains this :->the VB API AND API Viewer 2004. Private Declare Function SendMessage _ Lib "user32" _ Alias "SendMessageA" _ (ByVal hwnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Integer, _ <----- EH ? ---- ByVal lParam As Any) As Long |
|||||||||||||||||||||||