分类: C/C++
2008-03-14 14:03:21
二、实例
//参数:窗口句柄,消息,消息参数,消息参数 LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { //处理感兴趣的消息 switch (message) { case WM_CREATE: CreateWindow(TEXT("BUTTON"), //控件"类名称" TEXT("按钮(&A)"), WS_CHILD | WS_VISIBLE |BS_PUSHBUTTON, 10, 10, 100, 100, hwnd, (HMENU)1000, //控件ID ((LPCREATESTRUCT) lParam)->hInstance, //实例句柄 NULL); return 0; case WM_DESTROY: //当用户关闭窗口,窗口销毁,程序需结束,发退出消息,以退出消息循环 PostQuitMessage (0) ; return 0 ; } //其他消息交给由系统提供的缺省处理函数 return ::DefWindowProc (hwnd, message, wParam, lParam) ; }三、关于WM_CREATE消息
typedef struct tagCREATESTRUCT { LPVOID lpCreateParams; HINSTANCE hInstance; //实例句柄 HMENU hMenu; HWND hwndParent; int cy; int cx; int y; int x; LONG style; LPCTSTR lpszName; LPCTSTR lpszClass; DWORD dwExStyle; } CREATESTRUCT, *LPCREATESTRUCT;四、控件与父窗口的协作
除了WM_COMMAND外,每种控件还有可能有其他的通知消息(如WM_DRAWITEM)。
2.父窗口需要控制控件时,向控件发控件消息。
事先应记录下控件句柄,或由ID获取控件句柄
3.备注:
各种控件的通知消码和控制消息可由
MSDN-> Platform SDK-> User Interface Services->Windows User Interface->Controls
查得。
五、控件"类名称"
1.标准控件
BUTTON :按钮
COMBOBOX :复合框
EDIT :编辑
LISTBOX :列表
RichEdit :Rich Edit version 1.0
RICHEDIT_CLASS :Rich Edit version 2.0
SCROLLBAR :滚动条
STATIC :静态
2.外壳附带的公用控件
注:建立前需要用InitCommonControlsEx进行初始化
INITCOMMONCONTROLSEX icex;// Ensure that the common control DLL is loaded. icex.dwSize = sizeof(INITCOMMONCONTROLSEX); icex.dwICC = ICC_LISTVIEW_CLASSES; InitCommonControlsEx(&icex); HWND hWndListView =CreateWindowEx(0,WC_LISTVIEW, //WC_LISTVIEW不需要加引号 TEXT(""), WS_CHILD | WS_VISIBLE|WS_BORDER | LVS_ICON | LVS_EDITLABELS | WS_EX_CLIENTEDGE , 10, 10, 100, 100, hwnd, (HMENU)1000, //控件ID ((LPCREATESTRUCT) lParam)->hInstance, //实例句柄 NULL); }ANIMATE_CLASS
3.特殊窗口
MDIClient :MDI客户区窗口
ComboLBox :The class for the list box contained in a combo box.
DDEMLEvent :Windows NT/2000: The class for DDEML events.
Message :Windows 2000: The class for a message-only window.
#32768 :The class for a menu.
#32769 :The class for the desktop window.
#32770 :The class for a dialog box.
#32771 :The class for the task switch window.
#32772 :Windows NT/2000: The class for icon titles.