ebmDevMag.com home
ebm Developer's Magazine
links

developer's mag
main page

article
part 1
part 2
part 3
part 4
part 5


4 - Time for a Little Action

Despite the obvious improvement in extendibility, this program still seems rather static - all you can do is look at it and then close it. A real program responds to more messages, so we've added the message handler function to respond to the button press:

S32 CWindow1::MsgHandler(MSG_TYPE type,CViewable *from,S32 data)
{
// message handler solely to change color of rectangle
if ( MSG_BUTTON_SELECT==type && CWindow1_Button1==from->GetID() )
{
++m_count;
if (m_count&1) // odd?
Rect1->SetForegroundColor(COLOR_GRAY80);
else
Rect1->SetForegroundColor(COLOR_GRAY27);
return 1;
}
return CWindow::MsgHandler(type, from, data);
}
In a real program, you would be checking for several messages, and would use a case statement. Since we're only concerned with one message in this example however, this works fine.

This highlights another point of working with the Form Editor - object IDs are the numeric values referring to objects, and which are associated with them when they are constructed (in this case, CWindow1_Button1 is the ID for object Button1). You can refer to an object in two ways - the pointer value, and the ID. However, the ID is defined at compile time, while the pointer value is only determined at run time. This means that time-critical code benefits from using the ID value, since the compiler has a chance to optimize code using it. For example, in MsgHandler(), we can use a switch/case statement to look at IDs, but couldn't for pointer values, resulting in code (and speed) savings. And with message processing, timesavings are preeminent.

Looking at the IDs (the enums in the eg_2.h file), you also see the naming conventions of the form variables. The ID is composed of the window name and the object name spliced together; to change these, edit the Name property in the Form Editor for each object and export again.

At this point, you have a program that displays a screen designed on the Form Editor, includes additional source code, responds to a button press, and (most significantly!) works. As well, it's easy to modify: if you decide to move the rectangle or resize the button, the changes are localized to eg_2.cpp and eg_2.h, and your custom code isn't affected.

Previous Section
Next Section

Copyright © 2001-2006 ebmDevMag.com - Legal Notice