Professional Documents
Culture Documents
Assignment: 4: CSE 361: Windows Programming
Assignment: 4: CSE 361: Windows Programming
Assignment: 4: CSE 361: Windows Programming
• When a program displays a modal dialog box, the user can’t switch between
the dialog box and another window in your program.
• The user must explicitly end the dialog box by using EndDiaolg() function.
• The user can, however, switch to another program while the dialog box is still
displayed
System Modal:
• User can’t switch to another program while the dialog box is still displayed.
• They must be ended before the user can do anything else in Windows.
Modeless Dialog Boxes: They are basically popup windows that remain on the screen
for extended period of time.
• Modeless dialog boxes allow the user to switch to other applictions ,and to other
windows in the application that created the dialog box.
• They are frequently used for small “tool” windows ,which can be moved on the
screen.
• Modeless dialog boxes are defined in the dialog box template exactly the same
as regular modal dialog box.
HWND hModeless=NULL;
While(Getmessage(&msg,NULL,NULL,NULL,NULL))
If(hModeless==NULL || !IsDialogMessage(hModeless,&msg))
{
Translate message(&msg);
DispatchMessage(&msg);
Ans 2:
Popup window:-Popup wndows are not restricted to the parent window’s client
area. Popups can appear anywhere on the screen, and they can cover up portion of
the parent window and other programs window.
The main menu bar will hold only a few menu items. If u put in more menu items
than will fit on a single line, windows automatically will wrap the menu , creating a
two line menu bar. Two line menus are awkward and take up valuable space from
the window’s client area. It is much better to use popup menus.
Popup menus are defined inside the menu definition, between the BEGIN and
END menu statements. The keyword “POPUP” is followed by the title that will head
the popup menu.
Used for obtaining additional input from the user that can be easily managed
through a menu.
These are generally in form of popup window containing various child window
controls.
Size and placement of these controls are specified in a dialog box template in the
program's resource script file.
Also designed in the Visual C++ Developer Studio which further generates the
dialog template
When popup window do almost all of the functionality, the need of using
dialog boxes:-
Window procedure returns LRESULT or long far pascal; a dialog box procedure
returns BOOL..
A dialog box procedure will not receive a WM_CREATE message; instead, the
dialog box procedure performs initialization during the special WM_INITDIALOG
message.
Dialog box procedure within program handles messages to the dialog box.
Ans 3:
CS_PARENTDC: - It can be used for child windows. Child windows created from a
class using the CS_PARENTDC styles use their parent’s device context. This
presumes the parent was created with either the CS_OWNDC or CS_CLASSDC style,
so that the child has data to read.
Creating pop up windows is just like creating child windows, except the ws_popup
window style which is used in place of ws_child when calling Createwindow()
function. We cannot use the ws_child and ws_popup windows styles at the same
time to create a window . The ws_child style makes the window a child window
whereas ws_popup create a popup window for the program window.
Ans 4:
yes, we can define menu for the child window,popup window as well as dialog box.
Popup menus: pop up menus are used to give the user access to more selections,without
requiring additional space on top menu bar. Popup menus are defined inside the menu
definition ,between BEGIN and END menu statements.
Menu1 MENU
BEGIN
BEGIN
BEGIN
MENUITEM ‘’ &low‘’, 40
End
End
MENUITEM ‘’&QUIT’’, 50
END
A dialog box is a secondary window that allows users to perform a command, asks users
a question, or provides users with information or progress feedback.
Ans 5:
list boxes are commonly called "controls", as are all the window classes in the "common
controls library". In the world of the window manager, a "control" is a window whose
purpose is to provide some degree of interactivity (which, in the case of the static
control, might be no interactivity at all) in the service of its parent window. The fact that
the WM_COMMAND is used primarily in the context of dialog boxes further emphasizes
the point that the term "control" here is just a synonym for "child window".
switch(message)
{
case WM_PAINT:
hdc = BeginPaint(hwnd,&ps);
TextOut(hdc,10,10,TEXT("Vishaldeep Singh"),lstrlen(TEXT("Vishaldeep
SIngh")));
EndPaint(hwnd,&ps);
break;
case WM_COMMAND:
switch(wparam)
{
case ID_SHOW1:
hdc = GetDC(hwnd);
SetBkColor(hdc,RGB(0,0,255));
SetBkMode(hdc,OPAQUE);
SetTextColor(hdc,RGB(255,255,0));
SelectObject(hdc,GetStockObject(500));
TextOut(hdc,120,120,TEXT("abc"),lstrlen(TEXT("abc")));
ReleaseDC(hwnd,hdc);
break;
case ID_SHOW2:
hdc = GetDC(hwnd);
SetBkColor(hdc,RGB(0,0,255));
SetBkMode(hdc,TRANSPARENT);
SetTextColor(hdc,RGB(255,255,0));
SelectObject(hdc,GetStockObject(500));
TextOut(hdc,140,140,TEXT("def"),lstrlen(TEXT("def")));
ReleaseDC(hwnd,hdc);
break;
case ID_SHOW3:
hdc = GetDC(hwnd);
SetBkColor(hdc,RGB(0,0,255));
SetBkMode(hdc,OPAQUE);
SetTextColor(hdc,RGB(255,255,0));
SelectObject(hdc,GetStockObject(500));
TextOut(hdc,160,160,TEXT("ghi"),lstrlen(TEXT("ghi")));
ReleaseDC(hwnd,hdc);
break;
case ID_SHOW_4:
hdc = GetDC(hwnd);
SetBkColor(hdc,RGB(0,0,255));
SetBkMode(hdc,TRANSPARENT);
SetTextColor(hdc,RGB(255,255,0));
SelectObject(hdc,GetStockObject(500));
TextOut(hdc,180,180,TEXT("jkl"),lstrlen(TEXT("jkl")));
ReleaseDC(hwnd,hdc);
break;
case ID_QUIT:
DestroyWindow(hwnd);
break;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hwnd,message,wparam,lparam);
}
Ans 6:
The message decoding was done right in the message loop at the bottom of the
WinMain() function. The message data is passed to another function, usually named
WndProc (), which figures out which action to take depending on the message received.
We must modify the program’s message loop to allow processing of messages in a
separate function.
The key to passing the message data on the WndProc() function is the DispatchMessage
() function. This DispatchMessage () sends the message data to the function specified in
the window’s class definition.
WndProc () function will always have the same four parameter type passed as the
function arguments and are always have declared “long FAR PASCAL.” If you compare
the MSG data structure to the parameter list for WndProc (), you will realize that the first
four members of the MSG structure are being passed directly to WndProc (), as they are
seldom used. If you need those values, windows provides the GetMessageTime () and
GetMessagePos() function to fetch them.
Long FAR PASCAL WndProc (HWND hWnd, WORD wMessage, WORD wParam, LONG
lParam)
{
Switch(wMessage) /*process windows message */
{
case WM_DESTROY: /*stop application */
PostQuitMessage (0); /*this will exit message loop */
Break;
default: /*default windows message processing */
return DefWindowProc (hWnd , wMessage ,wParam, lParam);
}
Return (oL);
}