0% found this document useful (0 votes)
12 views

Windows Programming2

The document discusses differences between modal and modeless dialog boxes, how to create and close each type, and provides code examples. It also covers initializing and interacting with common dialog box controls like list boxes, edit boxes, and scroll bars through functions like DialogBox, CreateDialog, EndDialog, DestroyWindow, SendDlgItemMessage, GetDlgItemText, SetDlgItemText, and EnableWindow. The document is divided into multiple chapters with questions and answers about implementing and using dialog boxes and controls in code.

Uploaded by

Taqe Saad
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Windows Programming2

The document discusses differences between modal and modeless dialog boxes, how to create and close each type, and provides code examples. It also covers initializing and interacting with common dialog box controls like list boxes, edit boxes, and scroll bars through functions like DialogBox, CreateDialog, EndDialog, DestroyWindow, SendDlgItemMessage, GetDlgItemText, SetDlgItemText, and EnableWindow. The document is divided into multiple chapters with questions and answers about implementing and using dialog boxes and controls in code.

Uploaded by

Taqe Saad
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

By: Ali

Chapter1:

Q) What is difference between Modal and Modeless? ✯ ✯ ✯ ✯ ✯


A)
By Modal Modaless
Definition A modal dialog box prevents interaction A modeless dialog box allows the user
with the rest of the Program until the to interact with other parts of the GUI
user dismisses the dialog box. while the dialog box is posted.
Create By DialogBox( ) Function By CreateDialog( ) Function
Dialog Box
int DialogBox(HINSTANCE hThisInst, LPCSTR lpName, HWND CreateDialog(HINSTANCE hTlnsInst,
HWND hwnd, DLGPROC lpDFunc); LPCSTR lpName, HWND hwnd, DLGPROC
lp.DFunc);

Visibility Is automatically visible. Is not automatically visible, so you


may need to call ShowWindow()

• If you add WS_VISIBLE to RC File


dialog box will be automatically
visible.
Close By EndDialog( ) Function By DestroyWindow( ) Function
Dialog Box
BOOL EndDialog(HWND hdwnd, int nStatus); BOOL DestroyWindow(HWND hwnd);

Q) What is the Prototype of the DialogBox( ) API function ( )? Or


What is the Prototype used for Activate a modal Dialog Box?
A) That is:
int DialogBox(HINSTANCE hThisInst, LPCSTR lpName, HWND hwnd, DLGPROC lpDFunc);

• hThisInst is a handle to the current application

• The name of the dialog box as defined in the resource file is pointed
to by lpName.
• The handle to the window that owns the dialog box is passed in
hwnd.
• The lpDFunc parameter contains a pointer to the dialog function
described in the preceding section.
1
Q) What is the function of the EndDialug( ) function?
A) A dialog box procedure can call EndDialog at any time, its used to destroy the dialog box,
but not immediately the function must not be used it for any other purpose.
BOOL EndDialog(HWND hdwnd, int nStatus);

• hdwnd is the handle to the dialog box.

• nStatus is a status code returned by the DialogBox( ) function.

Chapter2:
Q) Write the general form for The Dialog Box Resource File? ✯ ✯ ✯ ✯ ✯
A) That is:
Dialog-name DIALOG [DISCARDABLE] X, Y, Width, Height
Features
{
Dialog-items
}

Q) What is the Prototype of the push button sample?


A) That is:
PUSHBUTTON "string", PBID, X, Y, Width, Height [, Style]

• string is the text that will be shown inside the push button.

• PDID is the value associated with the push button.

• The button's upper left corner will be at X, Y and the button will
have the dimensions specified by Width and Height. Style determines
the exact nature of the push button.

2
*

Chapter3:
Q) Which Value Responsible for identifies the of list box? (With Prototype)
A) That is LBID
LISTBOX LBID, X, Y, Width, Height [, Style]

• LBID is the value that identifies the list box.

• The box's upper left corner will be at X, Y and the box will have the
dimensions specified by Width and Height.
• Style determines the exact nature of the list box.

Q) What return if we can't find item in our dialog box? And what when we find it?
A) LB_ERR and LB_FINDSTRING

3
Q) Which command or function used for send list box message? (With Prototype)
A) You can send a list box several different messages. To send a message to the list box (or
any other control) use the SendDlgItemMessage( ) API function. Its prototype is shown here:

LONG SendDlgItcmMessage(HWND Hwnd, int ID, UINT IDMsg, WPARAM wParam, LPARAM lParam);

• sends the message specified by IDMsg

• control ID is specified by ID.

• The handle of the dialog box is specified in hdwnd .

• Any additional information required f the message is specified in


wParam and lParam.

Q) How we can initialize list box? and write the sup-program for it. ✯ ✯ ✯ ✯ ✯
A) That is:
case WM_INITDIALOG: /* initialize list box */

for(i=0; i<NUMBOOKS; i + +)
SendDlgItemMessage(hdwnd, IDD_LB1,LB_ADDSTRING, 0, (LPARAM)books[i].title);
/*select first item*/ SendDlgItemMessage(hdwnd, IDD_LB1,LB_SETCURSEL, 0, 0); return1;

Chapter4:
Q) Which is responsible for Create Standard Edit Box?
A) IDD_EB1

Q) How we can obtain current contents of the edit box?


A) By GetDlgItemText().

4
Q)What is Function of GetDlgItemText() in Edit Box, Explain That?
A) The Function for GetDlgItemText() to obtain current contents of the edit box, This function
causes the edit box to copy the current contents of the box to the string pointed to by lpstr.
The handle of the dialog box is specified by hdwnd. The ID of the edit box is specified by ID.
The maximum number of characters to copy is specified by Max. The function returns the
length of the string.

Q) Write the Prototype of GetDlgItemText() Function?


A) UINT GetDlgItemText(HWND hdwnd, int ID, LPSTR lpstr, int Max);

• Edit box to copy the current contents of the box to the string
pointed to by lpstr.
• The handle of the dialog box is specified by hdwnd.

• The ID of the edit box is specified by ID.

• The maximum number of characters to copy is specified by Max.

Q) Which is responsible for initialize the contents of an Edit Box?


A) SetDlgItemText( )

Q) Write the Prototype for SetDlgItemText( ) Function?


A) That is:
BOOL SetDlgItemText(HWND hdwnd, int ID, LPSTR lpstr);

• Sets the contents of the edit box to the string pointed to by lpstr.

• The handle of the dialog box is specified by hdwnd.

• The ID of the edit box is specified by ID.

***dialog box is specified by hdwnd. The ID of the edit box is specified by ID. The function
returns nonzero if successful or zero on failure.

5
Q) How we can initialize dialog box each time it is activated? (with example) Or
-How we can initialize Edit Box?
A) by add this line of code to the INITDIALOG case. It causes the edit box to be initialized each
time the dialog box is activated.
/* initialize the edit box */ SetDlgItemText(hdwnd, IDD_EB1, books[0].title);

Chapter5:
Q) How To Converted From Modal Into A Modeless Dialog Box? ✯ ✯ ✯ ✯ ✯
A) The first change that you need to make is to the dialog box definition in the DIALOG. RC
resource file, add WS_VISIBLE to the dialog box definition, then make this Four steps:
1. Create a global handle called hDlg.
2. Add IsDiaLogMessage( ) to the message loop.
3. Create the dialog box using CreateDialog() rather than DialogBox().
4. Close the dialog box using DestroyWindow( ) instead of EndDialog().

Q) What we mean by “Disabling a Control”?

A) Sometimes, you will have a control that is not applicable to all situations. When
a control is not applicable it can be (and should be) disabled. (Remember, controls
are simply specialized windows.) If How is nonzero, then the control is enabled. That
is, it is activated. If How is zero, the control is disabled. A control that is disabled is
displayed in gray and may not be selected. To disable a control, use the
EnableWindow( ) API function, shown here:
BOOL EnableWindow(HWND hCntl, BOOL How);
• Here, hCntl specifies the handle of the window to be affected.

6
Chapter6:
Q) Define Scroll Bars, and how many types are divided? With explanation. ✯ ✯ ✯ ✯ ✯
A) Scroll Bars: it is one of Windows NT's most important controls. Scroll bars exist in two
forms. The first type of scroll bar is an integral part of a normal window or dialog box. These
are called standard scroll bars. The other type of scroll bar exists separately as a control and
is called a scroll bar control. Both types of scroll bars are managed in much the same way.

• Describe this values


Values Description

SB_LINEUP Sent Each time the user moves the scroll bar up one position.
For vertical scroll bars

SB_LINEDOWN Sent Each time the scroll bar is moved down one position.
For vertical scroll bars

SB_PAGEUP Sent when the scroll bar is moved up one page.


For vertical scroll bars

SB_PAGEDOWN Sent when the scroll bar is moved down one page.
For vertical scroll bars

SB_LINELEFT Sent each time the user moves the scroll bar left one position.
For horizontal scroll bars

SB_LINERIGHT Sent Each time the scroll bar is moved right one position.
For horizontal scroll bars

SB_PAGELEFT Sent when the scroll bar is moved left one page.
For horizontal scroll bars

SB_PAGERIGHT Sent when the scroll bar is moved right one page.
For horizontal scroll bars

SB_THUMBPOSITION Sent after the slider box (thumb) of-the scroll bar has been dragged
to a new position.
For Both vertical and horizontal scroll bars

SB_THUMBTRACK Sent when the thumb is dragged to a new position


For Both vertical and horizontal scroll bars

7
Q) How Can We Activating the Standard Scroll Bars?
A) By including the styles WS_VSCROLL and/or WS_HSCROLL in the style parameter. In
the case of a dialog box, you include the WS_VSCROLL and/or WS_HSCROLL styles in the
dialog box's definition inside its resource file.

Q) For what use SetScrollInfo( )? And Write Prototype for it.


A) Used to set various attributes associated with a scroll bar. Its prototype is shown here:
int SetScrollInfo(HWND hwnd, int which, LPSCROLLINFO lpSI, BOOL repaint);

• hwnd is the handle that identifies the scroll bar.

• The value of which determines which scroll bar is affected.


• If repaint is true, then the scroll bar is redrawn. If false, the bar is not
redisplayed.

Q) For what use GctScroIIInfo()? And Write Prototype for it.


A) Used To obtain the attributes associated with a scroll bar, use GctScroIIInfo(), shown here:
BOOL GetScrollInfo(HWND hwnd, int which, LPSCROLLINFO lpSI);

• The hwnd and which parameters are the same as those just described for
SetScrollInfo( ).
• The information obtained by GetScrollInfo( ) is put into the structure pointed
to by lpSI.

8
Chapter7:
Q) What is a Scroll Bar Control?
A) A scroll bar control is a stand-alone scroll bar; it is not attached to a window. Scroll bar
controls are handled much like standard scroll bars.

Q) What is the difference between Scroll Bar Control and Standard Scroll Bars ?
A) There are two important differences:
1- The range of a scroll bar control must be set because it has a default range of zero. Thus, it is
initially inactive. This differs from standard scroll bars, whose default range is 0 to 100.
2- With the meaning of IParam when a scroll bar message is received. In standard scroll bar
IParam is always zero.

Q) How do You Creating a Scroll Bar Control? (With Prototype)


A) To create a scroll bar control in a dialog box, use the SCROLLBAR statement, which has
this general form:
SCROLLBAR SBID, X, Y, Width, Height [Style]

• SBID is the value associated with the scroll bar.

• Style determines the exact nature of the scroll bar

9
Chapter8:
Q) What is a Check Box?
A) Check Box is a control that is used to turn on or off an option. It consists of a small
rectangle which can either contain a check mark or not.

Q) How to add a check box to a dialog box definition? (With Prototype)


A) To add a check box to a dialog box definition, use either the CHECKBOX or
AUTOCHECKBOX command, which have these general forms:

CHECKBOX "string", CBID, X, Y, Width, Height [, Style]

AUTOCHECKBOX "string", CBID, X, Y, Width, Height [, Style]

• string is the text that will be shown alongside the check box.

• CBID is the value associated with the check box.


• The box's upper left corner will be at X, Y and the box plus its associated text
will have the dimensions specified by Width and Height.
• Style determines the exact nature of the check box.

Q) How to Checking a Check Box?


A) A check box can be checked by your program. To do this, send the check box a
BM_SETCHECK message using SendDlgItemMessage( ). In this case, wParam determines
whether the check box will be checked or cleared. If wParam is BST_CHECKED, the check
box is checked. If it is BST_UNCHECKED, the box is cleared. In both cases, lParam is zero.

10
Q) What is a 3-States Check Box? (With Prototype) ✯ ✯ ✯ ✯ ✯
A) A Check Box has three possible states: checked, cleared, or grayed. (When the control is
grayed, it is disabled.), In response to a BM_GETCHECK message, 3-state check boxes return
BST_UNCHECKED if unchecked, BST_CHECKED if checked, and BST_INDETERMINATE
if grayed. Correspondingly,

STATES "string", ID, X, Y, Width, Height [, Style]


AUTO3STATE "string1, ID, X, Y, Width, Height I Style]

• string is the text that will be shown alongside the check box.

• ID is the value associated with the check box.


• The box's upper left corner will be at X, Y and the box plus its associated text
will have the dimensions specified by Width and Height.
• Style determines the exact nature of the check box.

Chapter9:
Q) What is AUTORADIOBUTTON Prototype?
A) That is:
AUTORADIOBUTTON "string", RB1D, X, Y, Width, Height [, Style]

• string is the text that will be shown alongside the button.

• RBID is the value associated with the radio button.

• The button's upper left corner will be at X,Yand the button plus its associated
text will have the dimensions specified by Width and Height.
• Style determines the exact nature of the radio button.

11
Q) What we mean by Timer Messages? (With Prototype)
A) a timer that will interrupt your program at periodic intervals. Each time the timer goes off,
Windows NT sends a WM_TIMER message to your program. Using a timer is a good way to
"wake up your program" every so often. By Using SetTimer( ) API function

UINT SetTimer(HWND hwnd, UINT ID, UINT wLength, TIMERPROC lpTFunc);

• hwnd is the handle of the window that uses the timer.

• The value of ID specifies a value that will be associated with this timer.

• The value of wLength specifies the length of the period, in milliseconds.

• The function pointed to by lpTFunc is the timer function that will be called
when the timer goes off.

Q) For What KillTimer() Function used? (With Prototype)


A) Once a timer has been started, it continues to interrupt your program until you either
terminate the application or your program executes a call to the KillTimer() API function,
whose prototype is shown here:
BOOL KillTimer(HWND hwnd, UINT ID);

• hwnd is the window that contains the timer.

• ID is the value that Identifies that particular timer.

Chapter10:
Q) Define a Static Controls?
A) In short, the term static control is just a formal way of describing something that is simply
displayed in a dialog box. Static controls include CTEXT, RTEXT, and LTEXT, which are
static text controls; and GROUPBOX, which is used to visually group other controls.

12
Q) What do we mean by CTEXT, RTEXT, and LTEXT? (With Prototype) ✯ ✯ ✯ ✯ ✯
A) Static controls include CTEXT, RTEXT, and LTEXT, which are static text controls, The
general forms for these controls are shown here:

CTEXT "text", ID, X, Y, Width, Height [, Style]


RTEXT 'text", ID, X, Y, Width, Height [, Style]
LTEXT "text", ID, X, Y, Width, Height [, Style]

• text is the text that will be displayed.

• ID is the value associated with the text.

• The text will be shown in a box whose upper left corner will be at X, Y and
whose dimensions are specified by Width and Height.
• Style determines the exact nature of the text box.

Q) Define a Group Box? (With Prototype)


A) Group Box is simply a box the surrounds other dialog elements and is generally used to
visually group other items. The box may contain a title. The general form for GROUPBOX
is shown here:
GROUPBOX "title", ID, X, Y, Width, Height [, Style]

• title is the title to the box.

• ID is the value associated with the box.

• The upper left corner will be at X, Y and its dimensions are specified by Width
and Height.
• Style determines the exact nature of the group box.

13
Q) Write Standard control (free standing control) for SCROLLBAR? ✯ ✯ ✯ ✯ ✯
A)
hsbwnd = CreateWindow(
"SCROLLBAR", /* name of scroll bar class */
"", /* no title */
SBS_HORZ | WS_CHILD | WS_VISIBLE, /* horizontal scroll bar */
10, 10, /* position */
120, 20, /* dimensions
hwnd,
NULL,
hThisInst,
NULL

Q) Write Standard control (free standing control) for Push Button? ✯ ✯ ✯ ✯ ✯


A)
hpbwnd = CreateWindow(
"BUTTON", /* name of pushbutton class */
"Push Button", /* text inside button */
BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE, /* pushbutton*/
10, 60, /* position */
90, 30, /* dimensions */
hwnd, /* parent window */
(HWND) 500,
hThisInst,
NULL

Chapter11:

Q) Define a Bitmap?
A) Bitmap is a display object that contains a rectangular graphical image. The term
comes from the fact that a bitmap contains a set of bits which defines the image. Bitmap
resources are defined using textual statements in a resource file.
14
Q) What are Bitmap Types? Explain ✯ ✯ ✯ ✯ ✯
A) There are two general types of bitmaps supported by Windows NT Device-Dependent
and Device-Independent.
1- Device-Dependent Bitmaps (DDE): are designed for use with a specific device, were
initially the only type available in Windows.
2- Device-Independent Bitmaps (DIB): are not tied to a specific device, were initially
the only type available in Windows.

Q) Why Are The (DDE) The Most Widely Used?


A) DDEs are still commonly used when a program needs to create a bitmap for its own,
internal use.

Q) What are the steps to Using a Bitmap Resource? ✯ ✯ ✯ ✯ ✯


A) In general, to use a bitmap resource you must follow these three steps:
1. The bitmap must be specified within your program's resource file.
2. The bitmap must be loaded by your program.
3. The bitmap must be selected into a device context.

Q) Write a BITMAP statement Prototype?


A) That is:
BitmapName BITMAP Filename

• BitmapName is the name that identifies the bitmap.


• Filename is the name of the file that contains the bitmap.

Q) Write Prototype To load the bitmap LoadBitmap( ) ?


A) That is:
HBITMAP LoadBitmap(HINSTANCE hThisInst, LPCSTR lpszName);
15
Q) Write the steps to display the bitmap? ✯ ✯ ✯ ✯ ✯
A) The steps to display the bitmap:
1. Obtain the device context so that your program can output to the window.
2. Obtain an equivalent memory device context that will hold the bitmap until it is
displayed. (A bitmap is held in memory until it is copied to your window.)
3. Select the bitmap into the memory device context.
4. Copy the bitmap from the memory device context to the window device context.
This causes the bitmap to be displayed.

Q) Which function use to display a Bitmap? (With Prototype)


A) BitBlt() API function. This function copies a bitmap from one device context to
another. Its prototype is shown here:

BOOL BitBlt(HDC HDest, int X, int Y, int Width, int Height, HDC hSource, int
SouceX, int SourceY, DWORD dwHow);

*** we can delete a display or Release it by using DeleteDC( ) instant ReleaseDC( ).

Q) Write a Prototype or a general forms for Icon Courser Name


A)
IconName ICON filename
CursorName CURSOR filename

• IconName is the name that identifies the icon.


• CursorName is the name that identifies the cursor.

16

You might also like