Article View: borland.public.cppbuilder.nativeapi
Article #8078Re: Retrieving Windows Messages without window
From: Mike King
Date: Thu, 02 Dec 2004 14:29
Date: Thu, 02 Dec 2004 14:29
50 lines
2406 bytes
2406 bytes
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
news:41ae25a6$1@newsgroups.borland.com...
>
> "Mike King" <emailMK@excite.com> wrote in message
> news:41ae1698@newsgroups.borland.com...
>
> > Can I have the message pump run in a thread other then
> > the main thread?
>
> The main thread is still a thread like any other, so technically yes. I
> would not advice using TApplication::ProcessMessages() for that, though.
> AllocateHWnd() creates a basic window with no VCL handlings attached to
it,
> so a generic message pump via calling Get/PeekMessage(),
TranslateMessage(),
> and DispatchMessage() in a loop should suffice, ie:
>
> HWND FWnd;
>
> void __fastcall TMyThread::Execute()
> {
> MSG msg;
> FWnd = AllocateHWnd(WndProc);
> try
> {
> while( ::GetMessage(&msg, FWnd, 0, 0) > 0 )
> {
> ::TranslateMessage(&msg);
> ::DispatchMessage(&msg);
> }
> }
> __finally {
> DeallocateHWnd(FWnd);
> }
> }
>
> void __fastcal TMyThread::WndProc(TMessage &Message)
> {
> if( Message.Msg == WM_DEVICECHANGE )
> // process the message as needed...
>
> Message.Result = DefWindowProc(FWnd, Message.Msg, Message.WParam,
> Message.LParam);
> }
>
>
> Gambit
Thank you!
Technical Details
Message-ID:
<41af26d5$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!peer01.cox.net!cox.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<41adeee2@newsgroups.borland.com> <41adf778@newsgroups.borland.com> <41ae1698@newsgroups.borland.com> <41ae25a6$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,5ff06343caccb767 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Mike King" <emailMK@excite.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <41adeee2@newsgroups.borland.com> <41adf778@newsgroups.borland.com> <41ae1698@newsgroups.borland.com> <41ae25a6$1@newsgroups.borland.com> Subject: Re: Retrieving Windows Messages without window Date: Thu, 2 Dec 2004 09:29:43 -0500 Lines: 52 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 NNTP-Posting-Host: 64.45.143.248 Message-ID: <41af26d5$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1101997781 64.45.143.248 (2 Dec 2004 06:29:41 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!peer01.cox.net!cox.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail