Windows程序设计 读书笔记 - 对话框。

一、对话框过程和窗口过程直接的区别。

  1,返回值:

    窗口 LRESULT

    对话框 BOOL

  2,不处理的消息:

    窗口 交给DefWindowProc

    对话框 处理返回TRUE 不处理返回FALSE.

  3,特定消息:

    对话框过程不处理WM_PAINT,WM_DESTROY,不接收WM_CREATE,而是在WM_INITDIALOG里面初始化。

    WM_INITDIALOG是对话框接收到的第一个消息。

 

二、在MFC对话框中获取HINSTANCE

  1,HINSTANCE hInstance = AfxGetInstanceHandle();

  2,HINSTANCE hInstance = (HINSTANCE)GetWindowLong(hwmd,GWL_HINSTANCE);

 

三、模态对话框和非模态对话框。

    domodal或dialogbox的是模态的。

    createdialog或createwindow的是非模态的

  非模态对话框,在对话框属性里指定了“可见”,即WS_VISIBLE风格后,createdialog即可显示。如果没指定,则必须调用ShowWindow才能显示。

  非模态对话框的消息要要经过程序的消息队列。消息队列的处理要判断是否是对话框消息:

  while (GetMessage (&msg, NULL, 0, 0))
     {
          if (hDlgModeless == 0 || !IsDialogMessage (hDlgModeless, &msg))
          {
               TranslateMessage (&msg) ;
               DispatchMessage  (&msg) ;
          }
     }

  模态对话框用EndDialog结束,非模态用DestroyWindow结束。

 

带参数的对话框:

带参数的DialogBox :  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;

 

四、用.dlg文件布局窗口。

  view - 资源包括 - compile-time directives 输入“#include "xxxx.dlg"”

  就相当于在rc文件中加入了上述文件中的内容。

  例子:

  xxxx.dlg:

 

/*---------------------------

   HEXCALC.DLG dialog script

  ---------------------------*/



HexCalc DIALOG -1, -1, 102, 122

STYLE WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX

CLASS "HexCalc"

CAPTION "Hex Calculator"

{

     PUSHBUTTON "D",       68,  8,  24, 14, 14

     PUSHBUTTON "A",       65,  8,  40, 14, 14

     PUSHBUTTON "7",       55,  8,  56, 14, 14

     PUSHBUTTON "4",       52,  8,  72, 14, 14

     PUSHBUTTON "1",       49,  8,  88, 14, 14

     PUSHBUTTON "0",       48,  8, 104, 14, 14

     PUSHBUTTON "0",       27, 26,   4, 50, 14

     PUSHBUTTON "E",       69, 26,  24, 14, 14

     PUSHBUTTON "B",       66, 26,  40, 14, 14

     PUSHBUTTON "8",       56, 26,  56, 14, 14

     PUSHBUTTON "5",       53, 26,  72, 14, 14

     PUSHBUTTON "2",       50, 26,  88, 14, 14

     PUSHBUTTON "Back",     8, 26, 104, 32, 14

     PUSHBUTTON "C",       67, 44,  40, 14, 14

     PUSHBUTTON "F",       70, 44,  24, 14, 14

     PUSHBUTTON "9",       57, 44,  56, 14, 14

     PUSHBUTTON "6",       54, 44,  72, 14, 14

     PUSHBUTTON "3",       51, 44,  88, 14, 14

     PUSHBUTTON "+",       43, 62,  24, 14, 14

     PUSHBUTTON "-",       45, 62,  40, 14, 14

     PUSHBUTTON "*",       42, 62,  56, 14, 14

     PUSHBUTTON "/",       47, 62,  72, 14, 14

     PUSHBUTTON "%",       37, 62,  88, 14, 14

     PUSHBUTTON "Equals",  61, 62, 104, 32, 14

     PUSHBUTTON "&&",      38, 80,  24, 14, 14

     PUSHBUTTON "|",      124, 80,  40, 14, 14

     PUSHBUTTON "^",       94, 80,  56, 14, 14

     PUSHBUTTON "<",       60, 80,  72, 14, 14

     PUSHBUTTON ">",       62, 80,  88, 14, 14

}



五、

 

打开文件GetOpenFileName
保存文件GetSaveFileName

查找 FindText
替换 ReplaceText

判断是否unicode    IsTextUnicode

获取颜色   ChooseColor

你可能感兴趣的:(windows)