Class-time Lab 2 - Message Passing

Introduction

Write a program that has two windows, a message sender and a messagereceiver. The message sender will have a menu with three choices:

  1. Color Blue
  2. Color Yellow
  3. Color Red
Each menu choice will result in the message WM_COLOR_xxx with the appropriatecolor in place of xxx. This message will be sent to the main window (a TWindow) whichwill have three message handlers. Each will call on a function in the receiver window thatchanges the color of the window. The EvPaint function for the receiver will fill that window in the current color. Download the shell for this program by clicking here . The interface for this program appears below.

In The Resource Workshop

Add the messages WM_COLOR_xxxxx to the list of identifers. To do this

  1. Select Identifiers from the Resouce menu.
  2. Use the new button in the Identifiers dialog to create the three new identifiers (WM_COLOR_BLUE, WM_COLOR_YELLOW, and WM_COLOR_RED as 19001, 19002, and 19003 respectively).

The Message Sender

The message sender will be a minimal window and corresponding class. Create the menu for this class and the window in the resource workshop. (Youmight as well create the receiver window also. It is just a simple window withno extras). Make sure to define your message constants WM_COLOR_xxx inthe workshop Identifers window. The actual handlers will simply have the line:

     Parent->SendMessage(WM_COLOR_xxx);

The Main Window

The main window will simply forward message from the sender to the receiver.You are creating the handlers, so you must establish the tie between themessage and handler names in the response table.

DEFINE_RESPONSE_TABLE1(Cldemo12Window, TWindow)//{{Cldemo12WindowRSP_TBL_BEGIN}}	 EV_WM_PAINT,	 EV_MESSAGE(WM_COLOR_BLUE, EvColorBlue),	 EV_MESSAGE(WM_COLOR_RED, EvColorRed),	 EV_MESSAGE(WM_COLOR_YELLOW, EvColorYellow),//{{Cldemo12WindowRSP_TBL_END}}END_RESPONSE_TABLE;
Then add each of the EvColorxxx functions to the class header for your main windowand add the functions to the cpp file. Here is a sample of one such function.
LRESULT Cldemo12Window::EvColorBlue(WPARAM,LPARAM){	_receiver->fillBlue();}
Finally make sure to create the SetupWindow function for you TWindow. This will createeach of the windows and I added something to spread out the windows.
void Cldemo12Window::SetupWindow (){	 TWindow::SetupWindow();	 // INSERT>> Your code here.	 _receiver = new Reciever(this,IDD_RECEIVER,0);	 _receiver->Create();	 _sender = new Sender(this,IDD_SENDER,0);	 _sender->Create();	// The following positions the windows so they are separated	HWND rWind = HWindow;	 _sender->SetWindowPos(rWind, 50,70,0,0, SWP_NOSIZE|SWP_NOACTIVATE);	 rWind = _sender->HWindow;	 _receiver->SetWindowPos(rWind,350,70,0,0, SWP_NOSIZE|SWP_NOACTIVATE);}

The Receiver

The receiver window has a WM_PAINT handler that does all the work. The othermessages, such as fillBlue simply change the value of a member data item _color,and call Invalidate. The EvPaint function follows:

void Receiver::EvPaint (){	 TDialog::EvPaint();	 // INSERT>> Your code here.	TDC *dc = new TClientDC(*this);	TPoint p(1,1);	TBrush brush(_color);	dc->SelectObject(brush);	dc->FloodFill(p, TColor::White);	p.Offset(280,180);	dc->FloodFill(p,TColor::White);	delete dc;}
I used two flood fills to make sure that if the sender was moved over the receiver,the receiver would refill in most cases.