Vous êtes sur la page 1sur 8

Assignment : 4

CSE 361: Windows


Programming

Name :- Sahil Mehta Submitted To :


Section :- A1812 Mr. Virrat Devaser
Roll No : A11
Reg No :- 10802569
Ans 1:
Modal Dialog Boxes: A modal dialog box takes control from the application while it
is visible.

• Modal dialog box is commonly used.

• 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:

• System modal do not allow even this.

• 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.

• EndDiaolg() function will not work properly ,simply use DestroyWindow to


remove the modeless 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.

Dialog box:- In a graphical user interface of computers, a dialog box (or


dialogue box) is a type of window used to enable reciprocal communication or
"dialog" between a computer and its user. It may communicate information to the
user, prompt the user for a response, or both. A dialog box is most often used to
provide the user with the means for specifying how to implement a command, or to
respond to a question or an "alert.

 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.

 We can define a dialog box template manually.

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..

 DefWindowProc called if message not processed;

 While a dialog box procedure returns TRUE (nonzero) if it processes a message


and FALSE (0) if it does not.

 A dialog box procedure does not need to process WM_PAINT or WM_DESTROY


messages.

 A dialog box procedure will not receive a WM_CREATE message; instead, the
dialog box procedure performs initialization during the special WM_INITDIALOG
message.

 Instead of calling DestroyWindow(), it calls EndDialog() to terminate.

 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.

Menu for child window: A handle to a menu, or specifies a child-window identifier


depending on the window style. For an overlapped or pop-up window, hMenu identifies
the menu to be used with the window; it can be NULL if the class menu is to be used. For
a child window, hMenu specifies the child-window identifier, an integer value used by a
dialog box control to notify its parent about events. The application determines the child-
window identifier; it must be unique for all child windows with the same parent window.

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

POPUP “& First Popup”;

BEGIN

MEUITEM ‘’Sel1 &1’’,10

MENUITEM ‘’SEL &2 ‘’, 20

POPUP “& second level Popup”;

BEGIN

MEUITEM ‘’& high’’,30

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".

Every notification code specifies in its documentation whether it arrives as


a WM_COMMAND notification or a WM_NOTIFY notification. A modern control designer is
more likely to use WM_NOTIFY notifications since they allow additional information to be
passed with the notification. The WM_COMMAND message, by comparison, passes only
the notification itself; the other parameters to the WM_COMMAND message are forced, as
we'll see below. If WM_NOTIFY is superior to WM_COMMAND, why do some controls use
WM_COMMAND. Because WM_NOTIFY wasn't available until Windows 95. Controls that
were written prior to Windows 95 had to content themselves with
the WM_COMMAND message.

LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wparam,LPARAM


lparam)
{
HDC hdc;
PAINTSTRUCT ps;

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.

while (GetMessage (&msg ,NULL,NULL,NULL)) /*MESSAGE LOOP */


{
DispatchMessage (&msg); /* send message to WndProc() */
}

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);
}

Vous aimerez peut-être aussi