Docsity

Understanding Dialog Boxes in Win32 Applications: A Comprehensive Guide, Slides of Windows Programming

Partial preview of the text

Download Understanding Dialog Boxes in Win32 Applications: A Comprehensive Guide and more Slides Windows Programming in PDF only on Docsity!

Our good old first Win32 programme of lecture 8

#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MessageBox(NULL, "This is our first Windows Programming Application.", "Virtual University", MB_OK);

return 0; }

Modal Dialog Box contains a Modal Loop

DialogBox() API function creates a Modal

Dialog.

DialogBox() does not return until the dialog

is dismissed.

Controls in a Dialog Resource Definition statement

LTEXT Left-aligned static control

RTEXT Right-aligned static control

CTEXT Centre-aligned static control

DialogBox() API

INT_PTR DialogBox(

HINSTANCE hInstance, // handle to module

LPCTSTR lpTemplate, // dialog box template

HWND hWndParent, // handle to owner window DLGPROC lpDialogFunc // dialog box procedure

);

Dialog Box Procedure

BOOL CALLBACK AboutAuthorDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_INITDIALOG: return TRUE;

case WM_COMMAND: switch(LOWORD(wParam)) { case IDOK: case IDCANCEL: EndDialog(hDlg, 0); return TRUE; } break; } return FALSE; }

WM_INITDIALOG message

Sent by system just after creating the dialog and just

before making it visible

If FALSE is returned, it prevents the system from setting

the default keyboard focus.

If TRUE is returned, keyboard focus is set to the control

specified by wParam.

About dialog

Modal Dialogs

SetWindowText

Set the text of a control or the title bar of a window

BOOL SetWindowText(

HWND hWnd, // handle to window or control LPCTSTR lpString // title or text

);

GetDlgCtrlID

Retrieve the identifier of the specified control.

int GetDlgCtrlID(

HWND hwndCtl // handle to control

);

SendDlgItemMessage

sends a message to the specified control in a dialog box

LRESULT SendDlgItemMessage(

HWND hDlg, // handle to dialog box int nIDDlgItem, // control identifier

UINT Msg, // message to send WPARAM wParam, // first message parameter

LPARAM lParam // second message parameter

);

Edit control messages

EM_LIMITTEXT,

wParam, // text length

lParam // not used; must be zero

Sets the text limit of an edit control

Window/control messages

Set or retrieve current selection in an edit control

EM_SETSEL or EM_GETSEL

wParam, // starting position

lParam // ending position

Parameters to a Dialog

Passing information to the dialog

INT_PTR DialogBoxParam(

HINSTANCE hInstance, // handle to module LPCTSTR lpTemplateName, // dialog box template

HWND hWndParent, // handle to owner window DLGPROC lpDialogFunc, // dialog box procedure

LPARAM dwInitParam // initialization value

);

lParam parameter of WM_INITDIALOG contains dwInitParam