Article View: borland.public.cppbuilder.nativeapi
Article #8071Re: Retrieving Windows Messages without window
From: Remy Lebeau (TeamB)
Date: Wed, 01 Dec 2004 20:12
Date: Wed, 01 Dec 2004 20:12
43 lines
2252 bytes
2252 bytes
"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
Technical Details
Message-ID:
<41ae25a6$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!tiscali!newsfeed1.ip.tiscali.net!border2.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<41adeee2@newsgroups.borland.com> <41adf778@newsgroups.borland.com> <41ae1698@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: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <41adeee2@newsgroups.borland.com> <41adf778@newsgroups.borland.com> <41ae1698@newsgroups.borland.com> Subject: Re: Retrieving Windows Messages without window Date: Wed, 1 Dec 2004 12:12:20 -0800 Lines: 45 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 68.69.17.41 Message-ID: <41ae25a6$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1101931942 68.69.17.41 (1 Dec 2004 12:12:22 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!tiscali!newsfeed1.ip.tiscali.net!border2.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail