TOOLS.C
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:22k
源码类别:

Windows编程

开发平台:

Visual C++

  1. /******************************************************************************
  2. *       This is a part of the Microsoft Source Code Samples. 
  3. *       Copyright (C) 1993-1997 Microsoft Corporation.
  4. *       All rights reserved. 
  5. *       This source code is only intended as a supplement to 
  6. *       Microsoft Development Tools and/or WinHelp documentation.
  7. *       See these sources for detailed information regarding the 
  8. *       Microsoft samples programs.
  9. ******************************************************************************/
  10. #define NOMINMAX
  11. #include <windows.h>
  12. #include <stdlib.h> // For 'abs'
  13. #if !defined (APIENTRY)
  14. #define APIENTRY FAR PASCAL
  15. #endif
  16. HWND    hwndTools, hwndToolText, hwndToolCombo, hwndToolButton, hwndMain;
  17. HFONT   hfontTools=0;
  18. TEXTMETRIC tmToolFont;
  19. int     dyTools = 0, cxToolBorder, cyToolBorder, cntToolCtrls = 0, dyCombo;
  20. int     xCurrent = 10;
  21. HBRUSH  hbrBtnFace=0, hbrWindow=0;
  22. HANDLE  hInst=0;
  23. #define MAXCTRLS 25
  24. #define TC_SPACE 0
  25. #define TC_LABEL 1
  26. #define TC_COMBO 2
  27. #define TC_BUTTON 3
  28. typedef struct _tagTools {
  29.                         HWND    hwnd;
  30.                         WORD    wType;
  31.                         int     iWidth, iHeight;
  32.                         HICON   hIcon;
  33.                 } Tools;
  34. Tools  toolCtrl[MAXCTRLS];
  35. LONG APIENTRY ToolsProc       (HWND, UINT, UINT, LONG);
  36. LONG APIENTRY MyComboProc     (HWND, UINT, UINT, LONG);
  37. BOOL InitToolBar (HANDLE hInstance)
  38. {
  39.         WNDCLASS    wndclass;
  40.         hbrBtnFace = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
  41.         hbrWindow = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
  42.         wndclass.style         = CS_HREDRAW | CS_VREDRAW;
  43.         wndclass.lpfnWndProc   = (WNDPROC)ToolsProc;
  44.         wndclass.cbClsExtra    = 0;
  45.         wndclass.cbWndExtra    = 0;
  46.         wndclass.hInstance      = hInstance;
  47.         wndclass.hIcon     = NULL;
  48.         wndclass.hbrBackground = hbrBtnFace;
  49.         wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW);
  50.         wndclass.lpszMenuName  = NULL;
  51.         wndclass.lpszClassName = "SamplerTools";
  52.         if (!RegisterClass (&wndclass))
  53.                 return FALSE;
  54. }
  55. BOOL CreateToolBar (HWND hwnd, HANDLE hInstance, int iId)
  56. {
  57.         HWND hwndTmp;
  58.         RECT rect;
  59. #if defined (WIN32)
  60.         hInst = (HANDLE)GetWindowLong (hwnd, GWL_HINSTANCE);
  61. #else
  62.         hInst = GetWindowWord (hwnd, GWW_HINSTANCE);
  63. #endif
  64.         if (hbrBtnFace==0) {
  65.                 hbrBtnFace = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
  66.         }
  67.         if (hbrWindow==0) {
  68.                 hbrWindow = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
  69.         }
  70.         cxToolBorder = GetSystemMetrics (SM_CXBORDER);
  71.         cyToolBorder = GetSystemMetrics (SM_CYBORDER);
  72.         hwndTools = CreateWindow ("SamplerTools", "SamplerTools",
  73.                 WS_CHILD | WS_CLIPSIBLINGS | WS_BORDER | WS_VISIBLE,
  74.                 0, 0, 0, 0,
  75.         hwnd, (HMENU)iId, hInst, NULL);
  76.         if (!hwndTools) {
  77.                 return FALSE;
  78.         }
  79.         /* Lets find out how big a combo box is... */
  80.         hwndTmp = CreateWindow ("COMBOBOX", "Combo",
  81.                         WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST,
  82.                         0, 0, 0, 0,
  83.                         hwndTools, NULL, hInst, NULL);
  84.         if (hwndTmp) {
  85.                 SendMessage (hwndTmp, WM_SETFONT, (UINT)hfontTools, MAKELONG (TRUE, 0));
  86.                 GetClientRect (hwndTmp, &rect);
  87.                 dyCombo = rect.bottom - rect.top;
  88.                 DestroyWindow (hwndTmp);
  89.         } else {
  90.                 dyCombo = 30; // Just for a default value
  91.         }
  92.         hwndMain = hwnd; // So we can pass WM_CONTROL messages back to the master parent
  93.         return TRUE;
  94.         hInstance; // unreferenced formal parameter
  95. }
  96. int ToolBarHeight (HWND hwnd)
  97. {
  98.         RECT rect;
  99.         GetClientRect (hwndTools, &rect);
  100.         return rect.bottom-rect.top;
  101.         hwnd; //unreferenced formal parameter
  102. }
  103. BOOL AdjustToolBar (HWND hwnd)
  104. {
  105.         RECT rect;
  106.         GetClientRect (hwnd, &rect);
  107.         MoveWindow (hwndTools,
  108.                 rect.left-cxToolBorder,
  109.                 rect.top - cyToolBorder,
  110.                 rect.right - rect.left + (cxToolBorder*2),
  111.                 dyTools,
  112.                 TRUE);
  113.         return TRUE;
  114. }
  115. void UpdatePositions (void)
  116. {
  117.         int i, x, y, dx, dy, cnt;
  118.         x = 10;
  119.         for (i=0; i<cntToolCtrls; i++) {
  120.                 switch (toolCtrl[i].wType) {
  121.                         case TC_SPACE:
  122.                                 dx = toolCtrl[i].iWidth;
  123.                                 break;
  124.                         case TC_LABEL:
  125.                                 dy = toolCtrl[i].iHeight;
  126.                                 y = (dyTools/2) - (dy/2) - 1;
  127.                                 dx = toolCtrl[i].iWidth;
  128.                                 break;
  129.                         case TC_COMBO:
  130.                                 dy = toolCtrl[i].iHeight;
  131.                                 y = (dyTools/2) - (dy/2) - 1;
  132.                                 dx = toolCtrl[i].iWidth;
  133.                                 cnt = (int)SendMessage (toolCtrl[i].hwnd, CB_GETCOUNT, (UINT)0, (LONG)0);
  134.                                 if (cnt > 5) cnt = 5;
  135.                                 dy = dy * cnt;
  136.                                 break;
  137.                         case TC_BUTTON:
  138.                                 dy = toolCtrl[i].iHeight;
  139.                                 y = (dyTools/2) - (dy/2) - 1;
  140.                                 dx = toolCtrl[i].iWidth;
  141.                                 break;
  142.                         default:
  143.                                 dy = toolCtrl[i].iHeight;
  144.                                 y = (dyTools/2) - (dy/2) - 1;
  145.                                 dx = toolCtrl[i].iWidth;
  146.                                 break;
  147.                 }
  148.                 if (toolCtrl[i].wType != TC_SPACE) {
  149.                         MoveWindow (toolCtrl[i].hwnd, x, y, dx, dy, FALSE);
  150.                 }
  151.                 x += dx;
  152.         }
  153.         if (hwndTools) {
  154.                 UpdateWindow (hwndTools);
  155.         }
  156. }
  157. BOOL AddToolSpace (int iWidth, int iHeight)
  158. {
  159.         if (cntToolCtrls >= MAXCTRLS) return FALSE;
  160.         toolCtrl[cntToolCtrls].hwnd = 0;
  161.         toolCtrl[cntToolCtrls].wType = TC_SPACE;
  162.         toolCtrl[cntToolCtrls].iWidth = iWidth;
  163.         toolCtrl[cntToolCtrls].iHeight = iHeight;
  164.         if ((toolCtrl[cntToolCtrls].iHeight + (6*cyToolBorder)) > dyTools) {
  165.                 dyTools = (toolCtrl[cntToolCtrls].iHeight + (6*cyToolBorder));
  166.         }
  167.         UpdatePositions();
  168.         cntToolCtrls++;
  169.         return TRUE;
  170. }
  171. HWND AddToolLabel (HANDLE hInst, int iId, LPSTR szLabel, int iWidth, DWORD dwStyle)
  172. {
  173.         HDC hdc;
  174.         if (cntToolCtrls >= MAXCTRLS) return (HWND)0; // No room left in our fixed array
  175.         toolCtrl[cntToolCtrls].hwnd = CreateWindow ("STATIC", szLabel,
  176.                 WS_CHILD | WS_VISIBLE | dwStyle,
  177.                 0, 0, 0, 0,
  178.                 hwndTools, (HMENU)iId, hInst, NULL);
  179.         if (!toolCtrl[cntToolCtrls].hwnd) return (HWND)0; // CreateWindow failed for some reason
  180.         SendMessage (toolCtrl[cntToolCtrls].hwnd, WM_SETFONT, (UINT)hfontTools, MAKELONG (TRUE, 0));
  181.         toolCtrl[cntToolCtrls].wType = TC_LABEL;
  182.         hdc = GetDC (hwndTools);
  183.         if (iWidth < 0) {
  184.                 toolCtrl[cntToolCtrls].iWidth = tmToolFont.tmAveCharWidth * abs(iWidth);
  185.         } else if (iWidth == 0) {
  186. #if defined (WIN32)
  187.                 SIZE size;
  188.                 GetTextExtentPoint (hdc, szLabel, lstrlen(szLabel), &size);
  189.                 toolCtrl[cntToolCtrls].iWidth = size.cx;
  190. #else
  191.                 toolCtrl[cntToolCtrls].iWidth = LOWORD(GetTextExtent (hdc, szLabel, lstrlen(szLabel)));
  192. #endif
  193.         } else {
  194.                 toolCtrl[cntToolCtrls].iWidth = iWidth;
  195.         }
  196.         toolCtrl[cntToolCtrls].iHeight = tmToolFont.tmHeight;
  197.         if ((toolCtrl[cntToolCtrls].iHeight + (6*cyToolBorder)) > dyTools) {
  198.                 dyTools = (toolCtrl[cntToolCtrls].iHeight + (6*cyToolBorder));
  199.         }
  200.         ReleaseDC (hwndTools, hdc);
  201.         UpdatePositions();
  202.         return toolCtrl[cntToolCtrls++].hwnd;
  203. }
  204. HWND AddToolCombo (HANDLE hInst, int iId, int iWidth, DWORD dwStyle)
  205. {
  206.         if (cntToolCtrls >= MAXCTRLS) return (HWND)0; // No room left in our fixed array
  207.         if (dwStyle==0) dwStyle = CBS_DROPDOWNLIST;
  208.         toolCtrl[cntToolCtrls].hwnd = CreateWindow ("COMBOBOX", "",
  209.                 WS_CHILD | WS_VISIBLE | dwStyle,
  210.                 0, 0, 0, 0,
  211.                 hwndTools, (HMENU)iId, hInst, NULL);
  212.         if (!toolCtrl[cntToolCtrls].hwnd) return (HWND)0; // CreateWindow failed for some reason
  213.         SendMessage (toolCtrl[cntToolCtrls].hwnd, WM_SETFONT, (UINT)hfontTools, MAKELONG (TRUE, 0));
  214.         toolCtrl[cntToolCtrls].wType = TC_COMBO;
  215.         if (iWidth < 0) {
  216.                 toolCtrl[cntToolCtrls].iWidth = tmToolFont.tmAveCharWidth * abs(iWidth);
  217.         } else if (iWidth == 0) {
  218.                 toolCtrl[cntToolCtrls].iWidth = tmToolFont.tmAveCharWidth * 15; // just a default width
  219.         } else {
  220.                 toolCtrl[cntToolCtrls].iWidth = iWidth;
  221.         }
  222.         toolCtrl[cntToolCtrls].iHeight = dyCombo;
  223.         if ((toolCtrl[cntToolCtrls].iHeight + (6*cyToolBorder)) > dyTools) {
  224.                 dyTools = (toolCtrl[cntToolCtrls].iHeight + (6*cyToolBorder));
  225.         }
  226.         UpdatePositions();
  227.         return toolCtrl[cntToolCtrls++].hwnd;
  228. }
  229. HWND AddToolButton (HANDLE hInst, int iId, LPSTR szLabel, int iWidth, int iHeight, DWORD dwStyle)
  230. {
  231.         HDC hdc;
  232.         if (cntToolCtrls >= MAXCTRLS) return (HWND)0; // No room left in our fixed array
  233.         if (dwStyle == 0) dwStyle = BS_PUSHBUTTON;
  234.         toolCtrl[cntToolCtrls].hwnd = CreateWindow ("BUTTON", szLabel,
  235.                 WS_CHILD | WS_VISIBLE | dwStyle,
  236.                 0, 0, 0, 0,
  237.                 hwndTools, (HMENU)iId, hInst, NULL);
  238.         if (!toolCtrl[cntToolCtrls].hwnd) return (HWND)0; // CreateWindow failed for some reason
  239.         SendMessage (toolCtrl[cntToolCtrls].hwnd, WM_SETFONT, (UINT)hfontTools, MAKELONG (TRUE, 0));
  240.         toolCtrl[cntToolCtrls].wType = TC_BUTTON;
  241.         hdc = GetDC (hwndTools);
  242.         SelectObject (hdc, hfontTools);
  243.         if (iWidth < 0) {
  244.                 toolCtrl[cntToolCtrls].iWidth = tmToolFont.tmAveCharWidth * abs(iWidth);
  245.                 toolCtrl[cntToolCtrls].iWidth += (6*cxToolBorder);
  246.         } else if (iWidth == 0) {
  247. #if defined (WIN32)
  248.                 SIZE size;
  249.                 GetTextExtentPoint (hdc, szLabel, lstrlen(szLabel), &size);
  250.                 toolCtrl[cntToolCtrls].iWidth = size.cx;
  251. #else
  252.                 toolCtrl[cntToolCtrls].iWidth = LOWORD(GetTextExtent (hdc, szLabel, lstrlen(szLabel)));
  253. #endif
  254.                 toolCtrl[cntToolCtrls].iWidth += (6*cxToolBorder);
  255.         } else {
  256.                 toolCtrl[cntToolCtrls].iWidth = iWidth;
  257.         }
  258.         if (iHeight < 0) {
  259.                 toolCtrl[cntToolCtrls].iHeight = tmToolFont.tmHeight;
  260.                 toolCtrl[cntToolCtrls].iHeight += (6*cyToolBorder);
  261.         } else if (iHeight==0) {
  262.                 toolCtrl[cntToolCtrls].iHeight = dyTools - (6*cyToolBorder);
  263.         } else {
  264.                 toolCtrl[cntToolCtrls].iHeight = iHeight;
  265.         }
  266.         if ((toolCtrl[cntToolCtrls].iHeight + (6*cyToolBorder)) > dyTools) {
  267.                 dyTools = (toolCtrl[cntToolCtrls].iHeight + (6*cyToolBorder));
  268.         }
  269.         if (dwStyle & BS_OWNERDRAW) {
  270.                 toolCtrl[cntToolCtrls].hIcon = LoadIcon (hInst, szLabel);
  271.         } else {
  272.                 toolCtrl[cntToolCtrls].hIcon = NULL;
  273.         }
  274.         ReleaseDC (hwndTools, hdc);
  275.         UpdatePositions();
  276.         return toolCtrl[cntToolCtrls++].hwnd;
  277. }
  278. BOOL DestroyToolBar (void)
  279. {
  280.         return DeleteObject (hbrBtnFace);
  281. }
  282. void DrawButton (HDC hdc, RECT rect, BOOL bDown, HICON hIcon)
  283. {
  284.         HBRUSH  hBrush, hbrFrame, hbrFace, hbrHilite, hbrShadow;
  285.         RECT    border;
  286.         int     i;
  287.         hbrFrame = CreateSolidBrush(GetSysColor(COLOR_WINDOWFRAME));
  288.         hbrFace = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
  289.         hbrHilite = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
  290.         hbrShadow = CreateSolidBrush(GetSysColor(COLOR_BTNSHADOW));
  291.         FillRect (hdc, &rect, hbrFace);
  292.         if (hIcon) {
  293.                 if (bDown) {
  294.                         DrawIcon (hdc, rect.left + (4*cyToolBorder), rect.top + (4*cyToolBorder), hIcon);
  295.                 } else {
  296.                         DrawIcon (hdc, rect.left + (3*cyToolBorder), rect.top + (3*cyToolBorder), hIcon);
  297.                 }
  298.         }
  299.         hBrush = hbrFrame;
  300.         border = rect; border.bottom = border.top + cyToolBorder;
  301.         FillRect (hdc, &border, hBrush);
  302.         border = rect; border.right = border.left + cxToolBorder;
  303.         FillRect (hdc, &border, hBrush);
  304.         border = rect; border.top = border.bottom - cyToolBorder;
  305.         FillRect (hdc, &border, hBrush);
  306.         border = rect; border.left = border.right - cxToolBorder;
  307.         FillRect (hdc, &border, hBrush);
  308.         for (i= 0; i<2; i++) {
  309.                 InflateRect (&rect, -cxToolBorder, -cyToolBorder);
  310.                 hBrush = (bDown?hbrShadow:hbrHilite);
  311.                 border = rect; border.bottom = border.top + cyToolBorder;
  312.                 FillRect (hdc, &border, hBrush);
  313.                 border = rect; border.right = border.left + cxToolBorder;
  314.                 FillRect (hdc, &border, hBrush);
  315.                 if (!bDown) {
  316.                         hBrush = hbrShadow;
  317.                         border = rect; border.top = border.bottom - cyToolBorder;
  318.                         FillRect (hdc, &border, hBrush);
  319.                         border = rect; border.left = border.right - cxToolBorder;
  320.                         FillRect (hdc, &border, hBrush);
  321.                 }
  322.         }
  323.         DeleteObject (hbrFrame);
  324.         DeleteObject (hbrFace);
  325.         DeleteObject (hbrHilite);
  326.         DeleteObject (hbrShadow);
  327. }
  328. LONG APIENTRY ToolsProc (HWND hwnd, UINT msg, UINT wParam, LONG lParam)
  329. {
  330.         HDC          hdc;
  331.         PAINTSTRUCT      ps;
  332.         int          iType, idCtrl, msgCtrl, i;
  333.         RECT         rect, border;
  334.         COLORREF         clrColor;
  335.         HWND         hwndCtl;
  336.         LONG         lStyle;
  337.         HBRUSH       hBrush;
  338.         LPDRAWITEMSTRUCT lpdi;
  339.         HICON        hIcon;
  340.         LOGFONT     lfTmp ={0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  341.         switch (msg) {
  342.                 case WM_CREATE:
  343.                         lfTmp.lfHeight = 14;
  344.                         lfTmp.lfPitchAndFamily = VARIABLE_PITCH | FF_SWISS;
  345.                         hfontTools = CreateFontIndirect (&lfTmp);
  346.                         if (!hfontTools) {
  347.                                 MessageBox (GetFocus(),
  348.                                         "Unable to get an unnamed variable pitch swiss font", 
  349.                                         "Tool Bar CreateFont Error",
  350.                                          MB_OK);
  351.                                 hfontTools = CreateFont(14, 0, 0, 0, 0, 0, 0, 0,
  352.                                         0, 0, 0, 0,
  353.                                         VARIABLE_PITCH | FF_SWISS, "Arial");
  354.                         }
  355.                         if (!hfontTools) {
  356.                                 MessageBox (GetFocus(), "Failed To Create Font", "StatusProc", MB_OK);
  357.                         }
  358.                         hdc = GetDC (hwnd);
  359.                         SelectObject (hdc, hfontTools);
  360.                         GetTextMetrics (hdc, &tmToolFont);
  361.                         ReleaseDC (hwnd, hdc);
  362.                         return DefWindowProc (hwnd, msg, wParam, lParam);
  363.                 case WM_DESTROY:
  364.                         if (hfontTools) {
  365.                                 DeleteObject (hfontTools);
  366.                         }
  367.                         break;
  368.                 case WM_SIZE:
  369.                         UpdatePositions();
  370.                         break;
  371. #if defined (WIN32)
  372.                 case WM_CTLCOLORLISTBOX:
  373.                 case WM_CTLCOLOREDIT:
  374.                 case WM_CTLCOLORSTATIC:
  375.                 case WM_CTLCOLORBTN:
  376.                 case WM_CTLCOLORDLG:
  377.                 case WM_CTLCOLORMSGBOX:
  378.                 case WM_CTLCOLORSCROLLBAR:
  379.                         iType   = msg - WM_CTLCOLORMSGBOX;
  380.                         hdc     = (HDC)wParam;
  381.                         hwndCtl = (HWND)lParam;
  382. #else
  383.                 case WM_CTLCOLOR:
  384.                         hdc = wParam;
  385.                         hwndCtl = LOWORD(lParam);
  386.                         iType = HIWORD (lParam);
  387. #endif
  388.                         switch (iType) {
  389.                                 case CTLCOLOR_EDIT: //Edit control
  390.                                         clrColor = GetSysColor (COLOR_BTNFACE);
  391.                                         hBrush = hbrWindow;
  392.                                         break;
  393.                                 case CTLCOLOR_LISTBOX: //List-box control
  394.                                         lStyle = GetWindowLong (hwndCtl, GWL_STYLE);
  395.                                         if (lStyle & CBS_SIMPLE) {
  396.                                                 clrColor = GetSysColor (COLOR_WINDOW);
  397.                                                 hBrush = hbrWindow;
  398.                                         } else {
  399.                                                 clrColor = GetSysColor (COLOR_BTNFACE);
  400.                                                 hBrush = hbrBtnFace;
  401.                                         }
  402.                                         break;
  403.                                 case CTLCOLOR_STATIC:
  404.                                         clrColor = GetSysColor (COLOR_BTNFACE);
  405.                                         hBrush = hbrBtnFace;
  406.                                         break;
  407.                                 case CTLCOLOR_BTN:
  408.                                         clrColor = GetSysColor (COLOR_BTNFACE);
  409.                                         hBrush = hbrBtnFace;
  410.                                         break;
  411.                                 case CTLCOLOR_SCROLLBAR:
  412.                                 case CTLCOLOR_DLG:
  413.                                 case CTLCOLOR_MSGBOX:
  414.                                 default:
  415.                                         return DefWindowProc (hwnd, msg, wParam, lParam);
  416.                         }
  417.                         SetBkColor(hdc, clrColor);
  418.                 return (LONG)hBrush;
  419.                 case WM_PAINT:
  420.                         hdc = BeginPaint (hwnd, &ps);
  421.                         GetClientRect (hwnd, &rect);
  422.                         /* Shade the top of the bar white */
  423.                         hBrush = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
  424.                         border = rect;
  425.                         border.bottom = border.top + cyToolBorder;
  426.                         FillRect (hdc, &border, hBrush);
  427.                         DeleteObject (hBrush);
  428.                         /* Shade the bottom of the bar dark gray */
  429.                         hBrush = CreateSolidBrush(GetSysColor(COLOR_BTNSHADOW));
  430.                         border = rect;
  431.                         border.top = border.bottom - cyToolBorder;
  432.                         FillRect (hdc, &border, hBrush);
  433.                         DeleteObject (hBrush);
  434.                         EndPaint (hwnd, &ps);
  435.                         return DefWindowProc (hwnd, msg, wParam, lParam);
  436.                 case WM_DRAWITEM: // Indicates that an owner-draw control needs to be redrawn.
  437.                         lpdi = (LPDRAWITEMSTRUCT)lParam;
  438.                         switch (lpdi->itemAction) {
  439.                                 // handle normal drawing of button, but check if its selected or focus
  440.                                 case ODA_SELECT:
  441.                                 case ODA_DRAWENTIRE:
  442.                                         // handle button pressed down select state -- button down bitmap
  443.                                         //   text is right & down 2 pixels
  444.                                                                                 hIcon = NULL;
  445.                                         for (i=0; i< cntToolCtrls; i++) {
  446.                                                 if (toolCtrl[i].hwnd == lpdi->hwndItem) {
  447.                                                         hIcon = toolCtrl[i].hIcon;
  448.                                                 }
  449.                                         }
  450.                                         if (lpdi->itemState & ODS_SELECTED) {
  451.                                                 DrawButton (lpdi->hDC,lpdi->rcItem, TRUE, hIcon);
  452.                                         } else { // not selected -- button up; text is in normal position
  453.                                                 DrawButton (lpdi->hDC,lpdi->rcItem, FALSE, hIcon);
  454.                                         }
  455.                                         return TRUE;
  456.                         }
  457.                         break;
  458.                 case WM_COMMAND:
  459. #if defined (WIN32)
  460.                         idCtrl = LOWORD(wParam);
  461.                         msgCtrl = HIWORD(wParam);
  462.                         hwndCtl = (HWND)lParam;
  463. #else
  464.                         idCtrl = wParam;
  465.                         msgCtrl = HIWORD (lParam);
  466.                         hwndCtl = LOWORD (lParam);
  467. #endif
  468.                         if (GetWindowLong (hwndCtl, GWL_STYLE) & BS_OWNERDRAW) {
  469.                                 if (msgCtrl == BN_DOUBLECLICKED) {
  470.                                         PostMessage (hwndCtl, WM_LBUTTONDOWN, 0, 0);
  471.                                         return TRUE;
  472.                                 }
  473.                         }
  474.                         PostMessage (hwndMain, msg, wParam, lParam);
  475.                         return DefWindowProc (hwnd, msg, wParam, lParam);
  476.                 default:
  477.                         return DefWindowProc (hwnd, msg, wParam, lParam);
  478.         }
  479.         return 0L;
  480. }