Article View: borland.public.cppbuilder.nativeapi
Article #5879Unregistered HWND_BROADCAST messages
From: Alexandre S�
Date: Wed, 29 Jun 2005 16:08
Date: Wed, 29 Jun 2005 16:08
108 lines
4351 bytes
4351 bytes
Invited by Bob Gonder, I�m here again (on the
right newsgroup, I hope) to bring an old question:
The unregistered broadcast messages works "fine" on BC++
and doesn�t work on BCB6 and VC++.
(Sorry if the email is too long. But it�s necessary to avoid
stops on the main question to answer small questions.)
I�m trying to migrate an old BC++ 4.5 project to the BCB6.
After the migration to BCB6, the unregistered broadcast
messages didn�t work any more.
But can someone say why it works like that?
Think I need to understand it to be able to
solve the problem I have.
I put here a fully functional piece of code that reproduce
a different behavior on such compilers.
Does BC++ 4.5 use a different Windows API (3.1?) to compiler this code?
(even if I create a Win32 project)?
Is there a way to make BCB6 work like BC++ does?
Any help?
Best regards,
Alexandre S�
PS.:
You know that it�s better register broadcast messages
(RegisterWindowMessage), you know that this code
is not a good programming practice, etc.
But the project was entirely made to use unregistered broadcast
messages and any change may lead to a complete refactoring.
//----------------------------���----------------------------�-�-�----------
--
//---------------------------���-----------------------------�-��-----------
--
//This code creates a window class (WNDCLASS), register the
//class (RegisterClass), creates a window instance (CreateWindow),
//shows that window instance (ShowWindow, UpdateWindow),
//sends a (user defined and unregistered) broadcast message and tries to
//peek this message (PeekMessage). On BC++, the message is peeked,
//and on the BCB6 (or VC++) it�s not peeked.
#include <windows.h>
//---------------------------���-----------------------------�-��-----------
--
LRESULT __stdcall WINAPI WndProc (HWND hWnd, UINT msg,
WPARAM wParam, LPARAM lParam) {
return (DefWindowProc(hWnd,msg,wParam,lParam));
}
//------------------------�---��---------------------------�-�-�------------
--
#pragma argsused
WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASS windowClass = {0};
windowClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC ;
windowClass.lpfnWndProc = (WNDPROC)WndProc;
windowClass.cbClsExtra = 0;
windowClass.cbWndExtra = 0;
windowClass.hInstance = hInstance ;
windowClass.hbrBackground = (HBRUSH)(GetStockObject(BLACK_BRUSH));
windowClass.lpszMenuName = NULL;
windowClass.lpszClassName = "TMyForm";
if(!RegisterClass(&windowClass)) {
MessageBox(NULL, "!RegisterClass", "", MB_OK);
}
HWND hWindow = CreateWindow (
"TMyForm", "MyForm", WS_POPUPWINDOW,
10, 10, 200, 200,
NULL, NULL,
hInstance, NULL);
if(!hWindow) {
MessageBox(NULL, "!CreateWindow", "", MB_OK);
}
ShowWindow(hWindow, SW_SHOW);
UpdateWindow(hWindow);
PostMessage(HWND_BROADCAST, WM_USER+2, 0, 0L);
MSG m;
while(PeekMessage (&m, NULL, 0, 0, PM_REMOVE)) {
if(m.message == (WM_USER+2)) {
MessageBox(NULL, "Work!", "", MB_OK);
}
}
MessageBox(NULL, "end", "", MB_OK);
return 0;
}
//---------------------------���-----------------------------�-��-----------
--
//---------------------------���-----------------------------�-��-----------
--
Technical Details
Message-ID:
<42c2c8b7$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.maxwell.syr.edu!news-out.nntp.be!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,165a0162272fa9dd,start X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII From: "Alexandre S�" <alexandre@daccord.com.br> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Unregistered HWND_BROADCAST messages Date: Wed, 29 Jun 2005 13:08:44 -0300 Lines: 110 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: 200.249.236.130 Message-ID: <42c2c8b7$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1120061623 200.249.236.130 (29 Jun 2005 09:13:43 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.maxwell.syr.edu!news-out.nntp.be!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail