Académique Documents
Professionnel Documents
Culture Documents
UNIT III
The description of the above illustration, which illustrates the components, involved in
creation of an application using MFC is elucidated in the following section. The
developer studio is the interface used in source code and creates sources. The Resource.h
file stores the information about the sources.
MFC Headers
Resource complier
The file is included in the source code using an #include statement. When the source code
is compiled, in addition to the Resource.h, the following headers are also included:
Windows Header Files: Header files containing prototypes for functions called by
windows.
Run-time Header Files: Header files containing prototypes for DLLs to be linked at run-
time.
MFC Header Files: Files containing prototypes for MFC classes. These header files are
included using the #include statement. The Compiler converts the source file int an object
(OBJ) file. The Compiler generates the code in binary format for the OBJ files. A
1
Unit III Visual Programming
Resource script file is generated whenever a resource is created. The Graphics editor
creates and maintains this file for information about the resources created by the user.
Project Workspace: It is for creating a new project, select New from the File menu and
the Project window appears as shown in fig7.2. Assume that a MFC Win 32 project is
selected and a project name is entered. Then OK button is clicked. A series of windows
follows in case of application wizards, which are discussed in detail in the forth-coming
chapters and after the entire steps have been completed, all the files associated with that
project are generated.
To view the various files on a project, select Workspace from the Project menu, which
opens into the Project Workspace. The Project workspace offers a provision of looking
at a project in three views. They are the class view. Resource View and File view.
The Resource View window will list the various resources that have been added in any
application and their properties can be edited by right clicking on any item and then
selecting the properties option.
The File View lists the entire project source files and dependencies. Double clicking on
any files opens the file for editing.
1.1 PROJECT TYPES
2
Unit III Visual Programming
On Clicking the New Command in the Developer Studio’s File menu, a New Project
wizard opens. This includes different project types from which a relevant application can
be chosen. The types of project that can be developed using MFC are as given below.
MFC ActiveX Control Wizard - It is used to create a project that consists of one or
more Activex Controls based on MFC control implementation.
Win32Static Library - To Create a Static Library file, which can be linked with other
object modules
Win32 DLL – To create a project file for Dynamic Link Library project.
ISAPI Extension Wizard - The ISAP (Internet Server Application Extension Wizard.)
Makefile - This type of wizard can be used to create a makefile-based project when an
external make file or some executable program is to be specified to rebuild a project.
The Foundation Class Library’s classes are broken into two main categories: those
derived from the Cobject Class and those that are not.
The CObject derived classes are the subsystems categorized as given below
The classes that are not derived from CObject are broken into the following application
framework subsystems.
3
Unit III Visual Programming
Documents and Views are classes where the code for a document/View application is
stored. A Document contains the data for an application archived to retrieve from a file.
MFC provides a Cdocument class that allows to us to design our own document classes.
A view is a window attached to a document. The View serves two purposes.
It acts as a window to a document’s data. The view renders the documents data on the
display and also renders the image for printing and prints preview operations.
Accepts user input for an application and translates it into changes within a document’s
data.
The Win32 API identifies a window object by its window handle (HWND). Win32 uses
many predefined structure and macros to define the attributes of a window. MFC
encapsulates the win32 API functions common to all window objects in class CWnd.
These Classes derived from CWnd inherit HWND. A CWnd object wraps and owns a
windows window.
The Main types of windows in the framework derived from CWnd are listed here
4
Unit III Visual Programming
The controls are objects that users can interact with, to enter or manipulate data. They
commonly appear in dialog boxes or on toolbars. Controls in a dialog box are often
represented by member variables in the corresponding dialog class. To facilitate the
exchange of data between controls in the dialog box object and member variables in the
dialog class, the Dialog Data Exchange mechanism can be used. The major three classes
are considered as very common controls for windows applications. These controls make
the task of getting information form the user directly.
CEdit
CListBox
CComboBox
When the user needs to get text information from another user, or when the user wants to
enter or edit text for some other purpose, an edit controls is used. When several data
items exist to that can be chosen and used in an application, a convenient means of letting
a user make a selection is by using a list box control. The forthcoming sections of this
session explain the styles, messages and messages relevant to these controls and offer a
look at how to use them in an application context. These standard controls are inherited
from 16 bit windows, but still play a valuable role in the windows user interface.
The edit control is a rectangular control window typically used in a dialog box to permit
the user to enter and edit text from the keyboard. There are two styles of edit controls.
A Single line edit control displays all text on a single line, regardless of hard return
characters. Multiple line edit controls display text on multiple line separately by hard-
return characters. The MFC provides the services of a standard Windows edit control in
the class CEdit.
The following figure gives the position of class CEdit in the MFC hierarchy of windows
class:
5
Unit III Visual Programming
CObject
CCmdTarget
CWnd
CEdit
Like all windows, edit controls can use the styles available to CWnd, in addition to the
edit styles shown in the following table. There are two general styles of CEdit controls:
Single line and multiple lines.
Edit Messages
As MFC wraps the standard edit Messages into CEdit class method a MFC program
usually handles only notification messages. An edit control sends notification messages
to its owner, which is usually a Cdialog- derived class. These messages can be trapped
and handled by writing message map entries and methods are implemented in the edit
control’s owner’s class. In a MFC program, the users map messages that a CEdit object
deals with to class methods. This is done by creating message map entries in the
control’s parent class.
The CEdit class offers a well-rounded set of methods for manipulating text in an
edit window. These methods are broken into the following categories.
i) General Purpose
ii) Multiple Specific Purpose
The single line edit control methods are Getsel ( ), ReplaceSel( ) , Setsel ( ) , Clear( ) ,
Copy ( ), Cut( ) , and Paste( ).
6
Unit III Visual Programming
The Multiple line edit control methods are Getline(), SetTabStops( ) , GetHandle( ) ,
SetHandle( ).
List Boxes are common user interface controls that allow the selection of one or more
items from a list. List box maintain their own scroll bars to allw the user to scroll among
the data in the list. There are two general styles of list box available in the VC++ MFC.
A single selection list Box allows the user to select only one item at a time, where as a
multiple selection list box allows the user to select any number of items. The CListBox
class provides the functionality of a windows list box. This class is derived from CWnd.
Which means that it is window and inherits all the capabilities of a CWnd Object. The
following figure illustrates the position of Clist Box class in the MFC hierarchy of
window classes.
CObject
CCmdTarget
CWnd
CListBox
ListBox Styles
Like all windows, list boxes can have a combination of windows styles. This is because
they are windows, list boxes can use any combination of CWnd styles in addition to the
list box styles shown in the following. These styles allow a lot of flexibility in the
activities of the list Box.
7
Unit III Visual Programming
The CListBox class provides many methods for dealing with and manipulating list boxes
and list box data. These methods are broken into the following categories.
An overview of each method is provided so that the users know what to look for when
they need help on the relevant topic.
ComboBox Control
Windows supports the combo box control, which combines an edit box with a list box.
Thus a combo box allows one to select either an item in the list box component or the
user can type in their own input. There are three kinds of combo boxes
The drop down combo box differ from the simple type by the fact that the list box
appears only when the user clicks the down scroll arrow. The drop-down list combo box
proves a drop down list that appears when the user clicks on the down scroll arrow.
There is no edit in this kind of combo box.
8
Unit III Visual Programming
The CComboBox class provides the functionality of a windows combo box. The
CComboBox class is derived directly from CWnd. This class provides a set of methods
that make working with the list box items relatively easy. The figure given below
illustrates the position of class CComboBox in the MF hierarchy of window classes.
CObject
CCmdTarget
CWnd
CComboBox
Like all windows Combo boxes can have a combination of window styles. Because they
are windows, combo boxes can use any combination of CWnd styles in addition to the
combo box styles shown in the following. These styles allow a lot of flexibility in what
the combo box can do.
The CComboBox class provides a full set of methods for manipulating lists in a combo
box. The methods are broken into the following categories.
AddString( ) - Adds a string to the end of the list in the list Box of Combo Box
DeleteString ( ) - Deletes a string from the list box of a combo box.
InsertString( ) - Inserts a string into the list box of a combo box
9
Unit III Visual Programming
FindString ( ) - Finds the first string that contains the specified prefix in the list box
The MFC provides many controls other than the major three controls such as CEdit
CListBox and CComboBox. These are Buttons, Spins Scrollbar and slider Controls are
commonly used windows controls that can lend luster to the user interface.
Button Controls
Buttons are rectangular windows that usually contain a caption describing the user of the
control . Buttons are among the most prevalent controls in windows application. There
are four major categories namely
Checkboxes
PushButtons
RadioButtons
GroupBoxes
Buttons can be created as child controls of any window by writing a code, but it is more
appropriate to define them in a dialog resource template- because buttons appear most
frequently in dialog boxes, either in groups or single. MFC provides all the functionality
of the standard windows buttons in the class CButton. The following figure shows the
position of Cbutton in the class hierarchy.
CObject
CCmdTarget
CWnd
Cbutton
Button Styles
10
Unit III Visual Programming
Like all windows, buttons can have a combination of window styles, because buttons are
windows, they can use any combination of CWnd Styles. In addition to the general
window styles, buttons can also make use of the special button styles.
Cbutton Messages
A MFC message map usually has to handle only button notification messages
The CButton constructor allocates a CButton object that is initialized with the
Button::Create( ) method to set attributes and ownership.
Spin Controls
A “Spin Button Control” (Known as Up and Down control) is a pair of arrow buttons that
the user can click to increment or decrement a value, such as scroll position or a number
displayed in a combination control. The value associated with a spin button control is
called its current position. A Spin Control is most often used with a companion control
known as a “Buddy Windows”.
A spin-button control without a buddy window functions as a sort of simplified scroll bar.
For Example, a Tab control sometimes displays a spin button control to enable the user to
scroll additional tabs into view. In order to manipulate the spin button, a member
variable of type CspinButtonCtrl should be created in the dialog class.
CObject
11
Unit III Visual Programming
CCmdTarget
CWnd
CspinButtonCtrl
SpinButton Styles
Like all windows, spin controls can use the general window styles to CWnd. In addtion
they use the spin styles shown in the table below. The Spin control’s styles determine its
appearance and operations. Style bits are typically set when the control is initialized with
the CspinButtonCtrl::Create( ) method.
CspinButtonCtrl Methods
The CpinButtonCtrl class offers a concise set of methods for manipulating the control
and its data. The CpinButtonCtrl constructor allocates a spin control object that is
initialized with the CpinButtonCtrl::Create( ) method to set attributes and ownership.
The methods list in the following table describe the methods used to get and set control
attributes:
A Scroll bar is an interactive control that responds to user input in several ways. It
consists of a Scroll Box that runs along the length of a bar, with arrow buttons on either
end of the bar. A scroll bar control is different from the scroll bar that belongs to a
window. A “Slider control” is a window containing a slider and optional ticks marks.
When the user moves the slider, using either the mouse or the direction keys, the control
sends notification message to indicate the change. The sections that follow discuss the
methods, styles and message of these controls.
12
Unit III Visual Programming
Like other MFC controls CscrollBar is derived directly from CWnd and inherits
all the functionality of CWnd
CObject
CCmdTarget
CWnd
CscrollBar
The CscrollBar offers a small set of methods for manipulating the control and its data.
Some of the important methods are discussed below. The ScrollBar Constructor,
CscrollBar::CscrollBar( ) allocates a scroll bar object that is initialized with the
CscrollBar::Create( ) allocates a scroll bar object that is initialized with the
CscrollBar::Create() method to set attributes and ownership.
The CsliderCtrl class provides the functionality of the window common slider control. A
Slider control can be created as windows’s child control by writing a code. Alternately it
can be defined for use in a dialog resource template. A Slider control sends windows
motification messages to its owner and these messages can be trapped and handled by
writing message map entries and message handler methods for each message. These
message map entries and methods are implemented in the slider control’s parent class.
CObject
13
Unit III Visual Programming
CCmdTarget
CWnd
CscrollBar
Like all windows slider controls can use the general window styles available to CWnd.
In addition, they use the controls styles show in the forthcoming listing.
TBS_AUTOTICKS – Gives a slider tick marks for each increment in its range of values.
An application can all the slider control’s member functions to retrieve information about
the slider control and to change its characteristics
2. MESSAGE HANDLING
Up to now we have explain how to send our own messages by using the MFC function
SendMessage( ) and PostMessage( ). Win32 programmers use the SendMessage( ) and
PostMessages( ) functions all the time. In fact, calls to many Win32 “functions are
actually macros that call a SendMessage( ) or PostMessage( ) functions. Handling event
14
Unit III Visual Programming
messages is a bit more involved than what we lead you to believe in section 4.1 and
subsequent sections.
Modeless Dialogs: A common Use - Most MFC books discuss the SendMessage( )
function because it is necessary for programming modeless dialog boxes. However the
SendMessage( ) and PostMessage ( ) function have other uses. Consequently, we
consider them in a more general setting.
Messages: We have been dealing with messages using MessageBox( ) functions and Up
to this point we have needed only a limited understanding of what messages specifically,
a Message describes some events. A message gets routed to a message map associated
with a window. From there the messages causes a function to be executed. Some
message handling functions have parameters that describe the details of the message.
hwnd - This handle field identifies the window to which the message is directed
message - This is a number that merely identifies the message.
wParam - This is a Win 32 message Parameter.
lParam - This is another win 32 bit message parameter
time - This is the time when the message was put in the message “queue”
2.2 PROCESSING A MESSAGE
When a “windows Procedure” receives a message the first thing it has to do is decide
what type of message it is. So the processing in a win 32 Program begins like this
Switch( MSG )
{
15
Unit III Visual Programming
case Wh_CREATE:
// process the create msg
break;
case WM_PAINT
// process the paint msg
break;
case WM_LBUTTONNDOWN;
// process this message
break;
......
......
One of the major annoyances with Win32 Programming is that important information
describing the message is encoded in the wParam and lParam parameters for many
messages. These parameters have be “broken apart” to get at the information.
When too many customers want to check out their groceries at the same time, some
customers will have to stand around waiting in line. The line of waiting people is often
called a “queue”.
There are two facts about “posted” messages:
1. Posted messages get put into a queue if the window is busy processing a previous
message.
2. Posted messages are processed only when there are no “Sent messges waiting to
be processed. In effect, “Sent messages are a priority”.
Messages that are put in the queue are those that result from user input such as
WM_KEY-DOWN, WM_CHAR and WM_LBUTTONDOWN messages. Other
message like WM_TIMER and WM_PAINT are also “posted” to the queue.
For our own messages, we can either Send them or Post them.
Notice that when you select menu item Test Send/Post” It invokes the OnTest ( )
function. The interesting part of this function is the sequence of the statements:
this->SendMessage ( WM_SAY_SOMETHING,4,(LPARAM)ps1);
this->PostMessage ( WM_SAY_SOMETHING,2,(LPARAM)ps2);
this->SendMessage ( WM_SAY_SOMETHING,3,(LPARAM)ps3);
I have chosen the strings S1,S2 and S3 in such a way that the output clearly shows
the Posted message is after the second Sent Message
16
Unit III Visual Programming
Logically speaking two very different kinds of member data and different member
function should be separated. For Larger demonstration programs we have incorporated
our application data into a class object. This is precisely the purpose of the MFC
Document / View architecture. This was first introduced in MFC 2.0 in 1993.
The Following diagram illustrates the major classes involved in the Document / View
architecture. As you read on I think you will find it helpful to refer back to this diagram
as a quick way to put the various relationships into perspective. Below we describe some
of these objects
Title
CFrameWnd Frame Work
M_wndStatusBa Menu
ToolBar
CFrameWnd
CViewObject
Messages
Status Bar
CxxxDocObject
CxxxViewObject KeyBoard
Member vars
MP_mStr OnDraw( )
Member function
ChangeTo( ) OnChar( )
DisplayDoc( )
Onl_ButtonDown( )
Virtual Fucntion
Virtual Fucntion
CDocument
CView
The CmainFrame Object acts as a container for the menu, toolbar, status bar,
and Cview Object. As the mainframe windows is resized, the CmainFrame object adjusts
the sizes of the windows it contrains and we will make modification to the CmainFrame
Object.
17
Unit III Visual Programming
Since our document and view classes are derived from Cdocument and Cview,
respectively, We inherit functions from these two classes. Some functions we use as
they are defined in he base class. Other functions – the virtual functions – exist so that
we can provide our own implementation for these functions. As you see, the MFC
Frame work makes frequent call to virtual functions.
User input is sent via event messages to the Cview object. The Cview object will
then invoke the appropriate document object member functions to perform the
appropriate actions the Cview object accesses the document object with a pointer the
named Pdoc.
Saving a Document
This topic explain that, How the program is being saved as document. We have a
program to do the above process. This program is similar to the general document
program. It has a few small but important changes. Before you read about these
changes, you should run the program .
Notice that you can now save and retrieve the document data. All the file menu
items – New, Open, Save , Save As – Work!. In the open dialog Box , You can see the
files I have created and saved with this program: First,STr, Second.Str. Try it for
yourself. When we use the Document / View Architecture we inherit much functionality.
This is clearly evident when you run this program .
The key to saving your application data is to serialize your document object. To
serialize our simple document, we add the two statements illustrated in the
Doc::Serialize( ) functions.
18
Unit III Visual Programming
ensure that the framework prompts the user save changes before closing a document. To
mark a document as clean call this function with a value of FALSE.
OnNewDocument
The AppWizard also expects every program to redefine this virtual function, so it
adds it to the document class, Here is how help describes this function: “Called by the
framework as part of the Fie New command. The default implement of this function calls
the Deletecontents( ) member function to ensure that the document is empty and then
marks the new document is empty and then marks the new document as clean. Override
this function to initialize the data structure for a new document. You should call the base
class version of this function from your override. For our document, what does it mean
to begin with an empty document? Probably an empty string, at some point.
DeleteContent( )
On Open Document( )
“Called by the framework as part of the File Open Command. The default
implementation of this function opens the specified files; calls the Delete Contents( )
member function to ensure that the document is empty; calls Cobject::Serialize( ) to read
the content of the file and then marks the document as clean. Override this function if
you want to use something other than the archive mechanism or the file mechanism.
Here are some other CDocument Functions you might find useful:
It is no surprise that the mouse icon moves when we move the mouse. However,
we can also move the mouse to a specific position with code. The mouse quite a familiar
device is a pointing device with one or more buttons. It is always possible to add a
19
Unit III Visual Programming
keyboard interface to duplicate mouse functions, but it is not possible to substitute the
latter’s functions. In windows programming environment, mouse has become an
indispensable input device. All windows based applications must provide support for
handling mouse. Physically mouse cursor is a small bitmap image that is displayed and
erased at various position to give the illusion of movement. Windows header file uses
LBUTTON, MBUTTON and RBUTTON for the left, middle and right buttons of the
mouse. The function, which determines whether the mouse is installed, is
GetSystemMetrics function.
GetSystemMetrics(SM_MOUSEPRESENT);
The function returns TRUE if the mouse is installed and FALSE otherwise. To
determine the number of buttons the function GetSystemMetrics is used with
SM_CMOUSEBUTTONS:
GetSystemMetrics(SM_CMOUSEBUTTONS);
Mouse Messages
A window procedure receives mouse messages whenever the mouse passes over the
window even if the window is inactive. On moving the mouse, the window procedure
receives WM_MOUSEMOVE message.
Message Description
WM_LBUTTONDOWN Left Button Pressed
WM_RBUTTONDOWN Right Button Pressed
WM_MBUTTONDOWN Middle Button Pressed
WM_LBUTTONUP Left Button Released
WM_RBUTTONUP Right Button Released
WM_MBUTTONUP Middle Button Released
WM_LBUTTONDBLCLK Left Button double Clicked
WM_RBUTTONDBLCLK Right Button double Clicked
WM_MBUTTONDBLCLK Middle Button double Clicked
The above table gives the meaning of the mouse messages received.
Tracking a Mouse
Tracking allows the user to move the mouse cursor in a window. All mouse messages
are processed in the WndProc function. Some of the functions associated with the mouse
movement are:
1. Line to
2. MoveToEx
20
Unit III Visual Programming
3. ClientToScreen
4. SetCapture
5. ReleaseCapture
There is a function called SetCursoPos(x,y) that lets us set the position of the cursor.
However, there is a catch. If we want to position the cursor to point in our client
window. We cannot just substitute the 5 and 8 for the x and y in the SetCursoPos
function. We must use screen coordinates, not client window coordincates.
The following figure illustrates client coordinates a screen coordinates. Notice that the
client window coordinates(5,8) correspond to the screen coordinates(22,20) because of
the way the client window is positioned on the desktop.
Screen - Desktop
Screen Coordinates
Of Points(17,12) Client Window Coordinate
(5,8)
Fortunately, there is a function that converts from client coordinates to screen co-
ordinates. Here is how we position the cursor to the point we have found to be the closest
to mouse point.
Right Mouse Button Up event provides us with a new point. Since the index position
was held in a global variable called ldxPos, we now make the replacement.
Suppose we’ve selected a point with our right mouse button down.” Then we move
outside the window and release the button. The window will never get the “right mouse
button up message” because the message will be sent to another window, perhaps the
desktop and the selected point will not be changed.
We can have our window receive the “RbuttonUp” message no matter where the event
occurs. All we have to do is add the SetCapture and :: ReleaseCapture function in our
21
Unit III Visual Programming
mouse event handlers as we have done in our code. To appreciate this, run the program
and try pulling one of the ShapePts ourtside the window.
MDI applications mostly use accelerator keys. The main application window
whereas the Alt key applies to the application window. For example, Ctrl+F4 closes the
document application and Alt+F4 closes the application window.
The document window does not have a menu bar. Instead, the menu bar on the
main application window contains the menu for the currently active document. While
switching between documents the application menu bar must be changed. Items that do
not apply to the current document must not be included in the menu. When no documents
are open, the menu should contain those items that always apply.
All menu bars should contain the window pop-up menu. The pop-up contains Tile
and Cascade selections and other items. The Tile option rearranges all the non-
minimized documents one over the other. The cascade option rearranges the non-
minimized documents by displaying them starting from the left corner like stacked index
cards. In both cases the active document is placed on the top.
22
Unit III Visual Programming
When a document is maximized, the title of that document is appended to the text
in the application window’s title bar. The document window’s system icon is inserted at
the beginning of the application window menu bar. Windows also appends an icon at the
right of the menu bar to restore the document window.
When creating a new document window there is no need to close the existing
document windows. The new document window coexists with the previously opened
document windows.
The MDI application requires a window to interact with the user. The main
application window for an MDI application called the frame window. Normally, nothing
is displayed within the client area of the frame window. Instead, a child window called
the MDI client window or client window is created using the predefined
“MDICLIENT” window class. The client window resizes itself to fit the client area of the
frame window and provides MDI support.
The client area of the MDI client window is called the application workspace.
Finally, a document window is created whenever necessary. The document windows are
called MDI child windows or just child windows. The document windows are displayed
within the application workspace and are clipped to its boundaries.
The frame window for a MDI application is similar to the main application
window of a conventional windows application. Calling the Create window function
creates the frame window. The window has a caption with a system menu icon, a
minimize icon and a maximize icon. It also has a menu bar and a sizing border. The
caption area and the menu area are not part of the client area.
23
Unit III Visual Programming
Calling the Create window function creates a MDI client window. A pointer can
be passed as the last parameter to a CLIENTCREATESTRUCT structure in the
Createwindow function call. The structure of CLIENTCREATESTRUCT is as given
below.
The hwindowMenufield contains the handle for menu item in the window pop-up
menu. The MDICLIENT class adds the title of each child window to the end of pop-up
menu. The idFirstChild field contains the child window Id that is assigned to the first
child window created. The child window Ids range from idFirstChild to idFirstchild +n-
1,where n is the current number of MDI child windows.
When the user selects one of the child window titles from the windows pop-up
menu, windows sends a wm_command message to the frame window function. The
menu ID accompanying this message indicates as to which child window needs to be
activated. The frame window function passes the WM_COMMAND message to the
active child window,which then passes the message to its default message-handling
function, the DefMDIChildproc funtion. This activates the chosen child window.
The MDICLIENT window typically fills the client area that is left over after
displaying the toolbars, status bar etc. the parent/child hierarchy for and MDI application
is given in the following figure.
Frame window
24
Unit III Visual Programming
A child window can be created by the following two methods. In the first method a
WM_MDICREATE message is sent to the MDI client window, ordering it to
createda child window. The MDICREATESTRUCT structure is initialized and a
pointer is passed to it. this structure contains information about the appearance of the
child window. The structure is given below.
the following code segment creates a MDI child window for the hwndClient window.
mdicreate.szclass=firstchile;
mdicreate.szTitle=”I” am the first”;
mdicreate.x=CW_USEDEFAULT;
mdicreate.y=CW_USEDEFAULT;
mdicreate.cx=CW_USEDEFAULT;
mdicreate.cy=CW_USEDEFAULT;
mdicreate.style=0;
mdicreate.lParam=0;
hwndChild=(HWND)
SendMessage(hwndclient,WM_MDICREATE,0,
(LPMDICREATESTRUCT)&mdicreate);
Each distinct child window must have a registered window class with a window
function. The sxClass field of the structure specifies the child window class. The MDI
client window uses these fields while calling the createwindow function.this method is
for compatibility with Win16.
In the second method the createMDIWindow is used
HWND CreateMDIWindow
(
LPCSTR szClass,
LPCSTR szTitlle,
DWORD style,
int x,
int y,
25
Unit III Visual Programming
int cx,
int cy,
HWND hOwner,
HINSTANCE hOwner,
LPARAM lparam);
An interesting aspect of MDI child windows is that thwy do bot ghave their own
menus.All MDI windows share the same menu of the frame window.All cheld windows
stay within the boundary of the frame window. The child windows can be minimized to
an icon within the bounds of the frame. They can also be maximized to fill the entire
frame hiding all the other child windows.
A frame window function never communicates directly with the MDI child
window. Instead, the child window messages are sent to the client window. These
messages request maximizing, minimizing, creating and destroying of the child window
is actually done by the client window. Similarly, a child window does not typically
communicated directly with the frame window. For example, if the cheld window is
activated the menu on the frame eindow needs to be changed. The cheld lwindow sends a
message to the client window informing it to chage the menu on the frame window.
If the child window needs to be affected in some way or if the stauts of the child
window needs to be inquired, the message must be sent to the client window. For
example,sending the message WM_MDUACTUVATE to the client window means that
the specific window needs to be activated. The newly activated child window receives the
WM_MDIACTIVATE message with hwnd==lParam,indicating that it is being activated.
The currently active child window receives a WM_DEACTIVATE message with
hwnd==lParam, indicating that it is being deactivated.
The message loop for a MDI application looks different from a normal message
loop.
While(getMessage(&msg,0,0,0))
{
if(!TranslatedMDISysAceel (hwndMDIClient,&msg)&&
!TranslateAccelerator(hwndFrame,haccel,&msg))
{
translateMessage(&msg);
dispatchmessage(&msg);
}
}
26
Unit III Visual Programming
The MDI application after retriving the message from the message queue passes it
to the TranslateMDIsusAccel function.This function translates the WM_KEYDOWN
and WM_KEYUP messages, for keys corresponding to the MDI system menu
accelerators, to WM_SYSCOMMAND messages. The translated messages are sent to the
MDI client window. This window handle will be specified while calling
TranslatteMDIsusAccel function. It returns TRUE if the message was translated and
processed.
When it returns FALSE, the message loop calls the TranslateAccelerator function.
Some of the components of the Microsoft Developer Studio, are the Graphic
Editor, the C/C++ compiler, the Resources Compiler, the Linker and the On-line Help.
To perform other operations such as programming, debugging, testing and readability of
code,a few other MDS components are offered.
Debugger : The debugger is still in the development stage and does not fix bugs.The
debugger works closely with the developer studio to save breakpoints on the disk.
Breakpoints are stops in a program where the execution of the program is halted to allow
27
Unit III Visual Programming
the programmer to debug program code. Toolbar buttons are available to toggle
breakpoints and control single-step execution.
Source Browser : In a project, when one individual takes over from another, there is
always the tedious task of reading and understanding another person’s code and classes.
The Source Browser helps us to examine an application from application from the class
or the function point of view.
Application wizard : The Application Wizard, is a code generator that creates the
working skeleton of a windows application.
Class wizard : The class wizard is a program that is accessible from the Developer
studio’s view menu. When we are in need of a new class, a new message , a new virtual
function or a message handler, the classwizard can be used to create prototypes, function
bodies and the code to link to the windows message function.
Component Gallery : This is a new feature that lets the user share large software
components among projects.
28