Thread: Window messages

  1. #1
    Registered User
    Join Date
    Mar 2006

    Window messages

    I have a question about sending messages using ::SendMessage (). I am trying to communicate between windows using it like so:

    void FirstWindow::SendNotify (unsigned int notification)
    	::PostMessage (HWND_BROADCAST, NOTIFY_WINDOWS, (WPARAM) notification, (LPARAM) identifier);
    Where the class is:

    class FirstWindow : public AbstractWindow
    	int identifier;
    	FirstWindow (const TCHAR *className, int id) : AbstractWindow () { _className = className; identifier = id; }
    	virtual bool OnCommand  (int ctrlId, int notifyCode) { return false; }
    	virtual bool OnDestroy  () { ::PostQuitMessage (0); return false; }
    	virtual bool OnClose    () { ::DestroyWindow (_hwnd); return false; }
    	virtual bool OnNotify     (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
    	virtual void SendNotify (unsigned int notification);
    	//Commands to add controls
    	virtual bool AddComboBox (char *list[], int items, int x, int y, int width, int height, int id);
    	//Commands to change controls
    	virtual bool SetComboText (int ctrl, char *list[], int items);
    and the code to handle the NOTIFY_WINDOWS message is like so:

    bool FirstWindow::OnNotify (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    	MessageBox (NULL, "Received Notification!", "HEY!", MB_OK);
    	return false;
    Now, for some reason, when I change the first parameter of ::SendMessage to _hwnd, which is the variable for the window within AbstractWindow, I get a notification within that window; however, when I try to use HWND_BROADCAST, it doesn't do anything, even with multiple windows open. if anyone needs more source or code or anything else to help me with this, just say the word!
    HA! I WIN!

  2. #2
    Registered User
    Join Date
    Mar 2007
    SendMessage to _hwnd, which is the variable for the window within AbstractWindow
    If it's a child window of the main window, then it's not going to receive the message using HWND_BROADCAST.

    SendMessage() and HWND_BROADCAST

  3. #3
    Registered User
    Join Date
    Mar 2006
    Here is how my window is created:

    bool AbstractWindow::Create (char *name, int x, int y, int width, int height)
    	_hwnd = CreateWindowEx (0, _className, name, WS_OVERLAPPEDWINDOW, x, y, width, height,
    			NULL, NULL, GetModuleHandle (NULL), this);
    	if (!_hwnd)
    		return false;
    	return true;
    By my understanding of the article, windows created with the style WS_OVERLAPPEDWINDOW are not child windows, and none of the windows have the WS_CHILD style, so i don't quite understand why HWND_BROADCAST isn't working. Basically what i want to be able to do is send notification to all instances of FirstWindow when a particular event occurs in one of those windows. I'm not sure how to accomplish this though, because i just want to send that notification to windows within my application, not any outside of it. If someone has an idea how I can accomplish this, please feel free to let me know. I have no idea where to even start. Remember, too, that this is to be easy to use, meaning no sneaky global variables or anything like that, and if anyone needs more code, please ask.
    Last edited by xixpsychoxix; 03-25-2009 at 07:10 PM. Reason: more info needed
    HA! I WIN!

  4. #4
    train spotter
    Join Date
    Aug 2001
    near a computer
    Are both windows calling RegisterWindowsMessage()?


    HWND_BROADCAST tends to be unreliable form of interprocess communications (may not be delivered or arrive on time).

    I would look at named pipes, MSMQ, mailslots or sockets.

    Depends on your needs.
    Last edited by novacain; 03-27-2009 at 07:31 AM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Just starting Windows Programming, School me!
    By Shamino in forum Windows Programming
    Replies: 17
    Last Post: 02-22-2008, 08:14 AM
  2. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  3. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 02:33 PM
  4. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  5. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM