Annotation of mstools/samples/fontview/tools.c, revision 1.1.1.3

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.