



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A tutorial on implementing common dialogs and windows controls in windows programming. It covers the use of command dialog procedures, choose color dialog, and creating custom functions. The document also includes examples of repainting controls and creating an about box.
Typology: Study notes
1 / 5
This page cannot be seen from the preview
Don't miss anything!




In this lecture, we will discuss more about the dialog boxes and their commands implementations.
case WM_CTLCOLORSTATIC: switch(GetDlgCtrlID((HWND)lParam)) { case IDC_STATIC_TEXT_COLOR: if(hBrush) // if some brush was created before DeleteObject(hBrush); hBrush = CreateSolidBrush(textColour); // create a brush return (BOOL)hBrush; break;
case IDC_STATIC_BRUSH_COLOR: if(hBrush) // if some brush was created before DeleteObject(hBrush); hBrush = CreateSolidBrush(brushColour); // create a brush return (BOOL)hBrush; break;
default: return FALSE;// perform default message handling
ChooseColor(&chooseclr);
typedef struct { DWORD lStructSize; HWND hwndOwner; HWND hInstance; COLORREF rgbResult; COLORREF * lpCustColors; DWORD Flags; CC_RGBINIT | CC_FULLOPEN | CC_ANYCOLOR LPARAM lCustData; LPCCHOOKPROC lpfnHook; LPCTSTR lpTemplateName; } CHOOSECOLOR, *LPCHOOSECOLOR; return Val???
case WM_CTLCOLORSTATIC: switch(GetDlgCtrlID((HWND)lParam)) {
case IDC_BUTTON_BRUSH_COLOR:
if(ShowChooseColorDialog(hDlg, brushColour, &brushColour)) { GetClientRect(GetDlgItem(hDlg, IDC_STATIC_BRUSH_COLOR), &rect);
InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_BRUSH_COLOR), &rect, TRUE); } Break;
BOOL ShowChooseColorDialog(HWND Owner, COLORREF initClr, LPCOLORREF chosenClr) { CHOOSECOLOR cc; static COLORREF customColors[16];
memset(&cc, 0, sizeof(cc));
cc.lStructSize = sizeof(CHOOSECOLOR); cc.hwndOwner = hwndOwner; cc.rgbResult = initialColor; cc.lpCustColors = customColors; cc.Flags = CC_RGBINIT | CC_FULLOPEN | CC_ANYCOLOR;
if(ChooseColor(&cc)) // OK pressed { *chosenColor = cc.rgbResult; return TRUE; } return FALSE; }
Continue from Command Dialog Procedure:
case IDC_BUTTON_BRUSH_COLOR: if(ShowChooseColorDialog(hDlg, brushColour, &brushColour))
LPTSTR strings[5][2] = {{"Application", "Lecture 22"}, {"Author", "M. Shahid Sarfraz"}, {"Institution", "Virtual University"}, {"Year", "2003"}, {"Copyright", "2003 Virtual University"}};
case WM_INITDIALOG: for(i=0; i<5; ++i) { index = SendDlgItemMessage(hDlg,IDC_LIST_ABOUT, LB_ADDSTRING, 0, (LPARAM)strings[i][0]); SendDlgItemMessage(hDlg, IDC_LIST_ABOUT, LB_SE TITEMDATA,index,(LPARAM)strings[i][1]) }
// set current selection to 0 SendDlgItemMessage(hDlg, IDC_LIST_ABOUT, LB_SETCURSEL, 0, 0);
//Check notification messaqges in about dialog box LPTSTR str; case WM_COMMAND: wNotificationCode = HIWORD(wParam); wID = LOWORD(wParam);
switch(wID) { case IDC_LIST_ABOUT: if(wNotificationCode == LBN_SELCHANGE) { index = SendDlgItemMessage(hDlg, wID, LB_GETCURSEL, 0, 0); str = (LPTSTR)SendDlgItemMessage(hDlg, IDC_LIST_ABOUT, LB_GETITEMDATA, index, 0); SetDlgItemText(hDlg, IDC_STATIC_ABOUT, str); } }
We have been studying dialogs from previous two lectures. In this lecture, we have implemented some of the command implementation of dialog boxes. Common dialogs are very much useful in windows. Using common dialogs, you can show user to choose colors, files and printer, etc. Dialog resources are easy to use and easier to handle. Controls can be displayed on the dialogs. Dialogs by default set the font and dimensions of the controls. Dialogs are used in many areas like configuration of hardware devices, internet connections, properties and database configurations. Another important dialogs are called property sheets. This property sheet enables you to select any category from the tabs.