Windows Programming2
Windows Programming2
Chapter1:
• 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);
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
}
• string is the text that will be shown inside 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]
• 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);
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
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.
• 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.
• Sets the contents of the edit box to the string pointed to by lpstr.
***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().
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.
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_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
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.
• 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.
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.
• string is the text that will be shown alongside the check box.
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,
• string is the text that will be shown alongside the check box.
Chapter9:
Q) What is AUTORADIOBUTTON Prototype?
A) That is:
AUTORADIOBUTTON "string", RB1D, X, Y, Width, Height [, Style]
• 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
• The value of ID specifies a value that will be associated with this timer.
• The function pointed to by lpTFunc is the timer function that will be called
when the timer goes off.
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:
• 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.
• 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
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.
BOOL BitBlt(HDC HDest, int X, int Y, int Width, int Height, HDC hSource, int
SouceX, int SourceY, DWORD dwHow);
16