Advanced Windows Controls

来源:互联网 发布:python工程师 编辑:程序博客网 时间:2024/06/05 13:21
#include <windows.h>#include <commctrl.h>#define ID_TABCTRL 1#define EDIT 2#define BTN_ADD 3#define BTN_DEL 4#define BTN_DELALL 5LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);HWND hTab, hEdit;HINSTANCE g_hinst;int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,     LPSTR lpCmdLine, int nCmdShow ){  MSG  msg ;      WNDCLASS wc = {0};  wc.lpszClassName = TEXT( "Application" );  wc.hInstance     = hInstance ;  wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);  wc.lpfnWndProc   = WndProc ;  wc.hCursor       = LoadCursor(0,IDC_ARROW);  g_hinst = hInstance;    RegisterClass(&wc);  CreateWindow( wc.lpszClassName, TEXT("Tab Control"),                WS_OVERLAPPEDWINDOW | WS_VISIBLE,                100, 100, 380, 230, 0, 0, hInstance, 0);    while( GetMessage(&msg, NULL, 0, 0)) {    TranslateMessage(&msg);    DispatchMessage(&msg);  }  return (int) msg.wParam;}LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){   TCITEM tie;  // 这是什么结构体?   TCHAR text[250];   LRESULT count, id;   INITCOMMONCONTROLSEX icex; //什么东东?   switch(msg) {       case WM_CREATE:  // 创建应用程序窗口时 初始化 icex                  icex.dwSize = sizeof(INITCOMMONCONTROLSEX);           icex.dwICC = ICC_TAB_CLASSES;           InitCommonControlsEx(&icex);//ID_TABCTRAL  --- tab control  :WC_TABCONTROL          hTab = CreateWindow(WC_TABCONTROL, NULL, WS_CHILD | WS_VISIBLE,              0, 0, 200, 150, hwnd,(HMENU) ID_TABCTRL, g_hinst, NULL); // edit control 怎么生成的输入框?因为带有 WS_BORDER,创建的控件就是输入框了?// 大小都是 100*25          hEdit = CreateWindow("edit",NULL,WS_CHILD | WS_VISIBLE | WS_BORDER,                250, 20, 100, 25, hwnd, (HMENU) EDIT, g_hinst, NULL);// 下面是三个按钮,大小是100*25            CreateWindow("button","add", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,              250, 50, 100, 25, hwnd, (HMENU) BTN_ADD, g_hinst, NULL);          CreateWindow("button", "del", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,              250, 80, 100, 25, hwnd, (HMENU) BTN_DEL, g_hinst, NULL);          CreateWindow("button","delall", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,              250, 110, 100, 25, hwnd, (HMENU) BTN_DELALL, g_hinst, NULL);          break;       case WM_COMMAND:  //比如按了某个button就会有WM_COMMAND消息产生 //BTN_ADD,BTN_DEL,BTN_DELALL是怎么保存到wParam的低位的?按鼠标键时系统写入对应的按钮ID到wParam ?           switch(LOWORD(wParam)) {// 下面的TCM_开头的都是控件消息类型               case BTN_ADD:                   GetWindowText(hEdit, text, 250);                   if (lstrlen(text) !=0 ) {                       tie.mask = TCIF_TEXT;                       tie.pszText = text;                       count = SendMessage(hTab, TCM_GETITEMCOUNT, 0, 0);                       SendMessage(hTab, TCM_INSERTITEM, count,                            (LPARAM) (LPTCITEM) &tie);                   }                   break;               case BTN_DEL://删除当前凸起的那个tab,通过消息也能获得它的的ID?还有这种用法                   id = SendMessage(hTab, TCM_GETCURSEL, 0, 0);                   if (id != -1) {                       SendMessage(hTab, TCM_DELETEITEM, 0, id);                   }                   break;               case BTN_DELALL:                   SendMessage(hTab, TCM_DELETEALLITEMS, 0, 0);                   break;           }            break;       case WM_DESTROY:           PostQuitMessage(0);           break;   }   return(DefWindowProc(hwnd, msg, wParam, lParam));}