🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #5931

Re: HWND_BROADCAST doesn�t work!

#5931
From: Bob Gonder
Date: Mon, 20 Jun 2005 16:23
78 lines
3697 bytes
Alexandre S� wrote:

>> You are not getting a window that is capable of receiving
>> HWND_BROADCAST
>
>That�s not the question...

Umm..in this example case, it is.

>Here is the solution/explanation by Peter Below (TeamB):

Yes, that is to be considered, but it is not the problem I see here.

>But still remain the question: why on a different IDE (Borland C++ anyway)
>it works without register the broadcast message?
>
>That�s why the problem arises... I had to migrate a Borland C++ project to
>the Borland C++ Builder 6 (a Delphi like IDE) and on such "Delphi like IDE"
>it�s necessary to register the broadcast message (like it have to be).

I compiled your example code, and that wasn't the problem.
The problems was RegisterClass failed
Here is your example, with error checks...

#include <windows.h>

#pragma	argsused
 LRESULT CALLBACK  WndProc(HWND hWnd, unsigned msg,
		 WPARAM wParam, LPARAM lParam)
{  return 0;
}
//--------------------------------------------------------------------------
#pragma argsused
WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
lpCmdLine, int nCmdShow)
{
  WNDCLASS windowClass;
  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( 0 == RegisterClass(&windowClass) )
{	/* add code here to evaluate GetLastError() */
	MessageBox(0,"No Register","Peek",MB_OK);
	return 0;
}
 HWND hWindow = CreateWindow ("TMyForm", "MyForm",
  WS_POPUP | WS_BORDER,
  10,10,200,200,
  NULL, NULL, hInstance, NULL);
if( NULL == hWindow )
{	/* add code here to evaluate GetLastError() */
	MessageBox(0,"No Create","Peek",MB_OK);
	return 0;
}
  PostMessage(HWND_BROADCAST, WM_USER, 0, 0L);

  MSG msg;
  if(PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) {
     MessageBox(NULL, "Work!", "", MB_OK);
  } else {
     MessageBox(NULL, "Don�t work!", "", MB_OK);
  }
  return 0;
}

Further testing shows this line to be incorrect:
  WNDCLASS windowClass;
Ir should be
  WNDCLASS windowClass = {0};
That gets the class registered.
Then the CreateWindow() fails with
"Cannot create a file when that file already exists"
That I'll leave up to you.
Technical Details
Message-ID: <a7pdb11bft48i6ph03n3nrl8afr01p24rc@4ax.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!news-out.newsfeeds.com!propagator3-LAX.newsfeeds.com!news-in.newsfeeds.com!news-in.superfeed.net!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <42b30d0a$1@newsgroups.borland.com> <42b317d0$1@newsgroups.borland.com> <42b31b9a@newsgroups.borland.com> <42b3322d$1@newsgroups.borland.com> <42b34cfc$1@newsgroups.borland.com> <cjj6b1hc3t1tjnju46lto298h1h7k3bjvg@4ax.com> <42b6c0f1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,af4f253f03c4e6fb
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII
From: Bob Gonder <notbg@notmindspring.invalid>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: HWND_BROADCAST doesn�t work!
Date: Mon, 20 Jun 2005 09:23:45 -0700
Organization: MindSpring Enterprises, Inc.
Reply-To: notbg@notmindspring.invalid
Message-ID: <a7pdb11bft48i6ph03n3nrl8afr01p24rc@4ax.com>
References: <42b30d0a$1@newsgroups.borland.com> <42b317d0$1@newsgroups.borland.com> <42b31b9a@newsgroups.borland.com> <42b3322d$1@newsgroups.borland.com> <42b34cfc$1@newsgroups.borland.com> <cjj6b1hc3t1tjnju46lto298h1h7k3bjvg@4ax.com> <42b6c0f1@newsgroups.borland.com>
X-Newsreader: Forte Agent 1.93/32.576 English (American)
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
NNTP-Posting-Host: 67.77.200.249
X-Trace: newsgroups.borland.com 1119284625 67.77.200.249 (20 Jun 2005 09:23:45 -0700)
Lines: 80
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!news-out.newsfeeds.com!propagator3-LAX.newsfeeds.com!news-in.newsfeeds.com!news-in.superfeed.net!caladan.landsraad.net!newsgroups.borland.com!not-for-mail