Implementing Common Dialogs and Windows Controls in Windows Applications, Study notes of Computer Engineering and Programming

The code implementation of various dialog boxes and their commands using common dialogs in windows. It covers the command dialog procedure, choose color dialog, and the about box. The code demonstrates how to create and use these dialogs in a windows application.

Typology: Study notes

2011/2012

Uploaded on 11/06/2012

ahsen
ahsen 🇵🇰

4.6

(88)

84 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Chapter 22
22.1 DIALOGS (CONTINUE FROM PREVIOUS LECTURE) 2
22.2 COMMAND DIALOG PROCEDURE 2
22.3 CHOOSE COLOR DIALOG 2
22.4 OUR OWN DEFINED FUNCTION SHOWCHOOSECOLORDIALOG 3
22.5 COMMAND DIALOG PROCEDURE (DRAWING) 4
22.6 THE ABOUT BOX (MAIN WINDOW PROCEDURE) 4
22.7 LIST BOX MESSAGES ERROR! BOOKMARK NOT DEFINED.
22.8 ABOUT BOX DIALOG PROCEDURE 5
SUMMARY 6
EXERCISES 6
pf3
pf4
pf5

Partial preview of the text

Download Implementing Common Dialogs and Windows Controls in Windows Applications and more Study notes Computer Engineering and Programming in PDF only on Docsity!

22.7 LIST BOX MESSAGES E RROR! BOOKMARK NOT DEFINED.

  • Chapter
  • 22.1 DIALOGS (C ONTINUE FROM P REVIOUS LECTURE )
  • 22.2 COMMAND DIALOG P ROCEDURE
  • 22.3 CHOOSE COLOR DIALOG
  • 22.4 OUR OWN DEFINED FUNCTION S HOWCHOOSECOLORDIALOG
  • 22.5 COMMAND DIALOG P ROCEDURE (D RAWING )
  • 22.6 THE ABOUT BOX (M AIN W INDOW P ROCEDURE )
  • 22.8 ABOUT BOX DIALOG P ROCEDURE
  • S UMMARY
  • EXERCISES

22.1 Dialogs ( Continue from the Previous Lecture )

In this lecture, we will discuss more about the dialog boxes and their commands implementations.

22.2 Command Dialog Procedure

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

22.3 Choose Color Dialog

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

// REPAINT CONTROL: send WM_CTLCOLORSTATIC druing repainting

GetClientRect(GetDlgItem(hDlg, IDC_STATIC_BRUSH_COLOR), &rect);

InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_BRUSH_COLOR), &rect, TRUE); } Break;

22.5 Command Dialog Procedure ( Drawing )

case IDC_BUTTON_DRAW: hDC = GetDC(GetParent(hDlg)); if(IsDlgButtonChecked(hDlg, IDC_RADIO_RECTANGLE) == BST_CHECKED) { hOwnerBrush = CreateHatchBrush(HS_BDIAGONAL, brushColour);

hOldBrush = SelectObject(hDC, hOwnerBrush); Rectangle(hDC, 10, 10, 200, 200);

SelectObject(hDC, hOldBrush); // restore old selection DeleteObject(hOwnerBrush); }

22.6 The About Box ( Main Window Procedure)

Now create a Modal Dialog box on the about event.

case ID_HELP_ABOUT: DialogBox(hAppInstance, MAKEINTRESOURCE(IDD_DIALOG_ABOUT), hWnd, aboutDialogProc);

22.7 About Box Dialog Procedure

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