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

1.1       root        1: #include "FirstAid.H"
                      2: 
                      3: #define NOMINMAX
                      4: #include <windows.h>
                      5: 
                      6: #include <stdlib.h> // For 'abs'
                      7: 
                      8: //typedef LONG (APIENTRY *WNDPROC)(HWND, UINT, DWORD, LONG);
                      9: 
                     10: HWND    hwndTools, hwndToolText, hwndToolCombo, hwndToolButton, hwndMain;
                     11: HFONT   hfontTools=0;
                     12: TEXTMETRIC tmToolFont;
                     13: INT     dyTools = 0, cxToolBorder, cyToolBorder, cntToolCtrls = 0, dyCombo;
                     14: INT     xCurrent = 10; 
                     15: INT     dxTools= 0;
                     16: HBRUSH  hbrBtnFace=0, hbrWindow=0;
                     17: HANDLE  hInst=0;
                     18: 
                     19: #define MAXCTRLS 25
                     20: #define TC_SPACE 0
                     21: #define TC_LABEL 1
                     22: #define TC_COMBO 2
                     23: #define TC_BUTTON 3
                     24: typedef struct _tagTools {
                     25:                        HWND    hwnd;
                     26:                        WORD    wType;
                     27:                        INT     iWidth, iHeight;
                     28:                        HICON   hIcon;
                     29:                } Tools;
                     30: Tools  toolCtrl[MAXCTRLS];
                     31: 
                     32: LONG APIENTRY ToolsProc       (HWND, UINT, UINT, LONG);
                     33: LONG APIENTRY MyComboProc     (HWND, UINT, UINT, LONG);
                     34: VOID APIENTRY UpdatePositions (HWND hwnd);
                     35: 
                     36: BOOL InitToolBar (HANDLE hInstance)
                     37: {
                     38:        WNDCLASS    wndclass;
                     39: 
                     40:        hbrBtnFace = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
                     41:        hbrWindow = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
                     42: 
                     43:        wndclass.style         = CS_HREDRAW | CS_VREDRAW;
                     44:        wndclass.lpfnWndProc   = (WNDPROC)ToolsProc;
                     45:        wndclass.cbClsExtra    = 0;
                     46:        wndclass.cbWndExtra    = 0;
                     47:        wndclass.hInstance      = hInstance;
                     48:        wndclass.hIcon     = NULL;
                     49:        wndclass.hbrBackground = hbrBtnFace;
                     50:        wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW);
                     51:        wndclass.lpszMenuName  = NULL;
                     52:        wndclass.lpszClassName = "SamplerTools";
                     53: 
                     54:        if (!RegisterClass (&wndclass))
                     55:                return FALSE;
                     56: }
                     57: 
                     58: BOOL CreateToolBar (HWND hwnd, HANDLE hInstance, INT iId)
                     59: {
                     60:        HWND hwndTmp;
                     61:        RECT rect;
                     62: 
                     63: //OutputDebugString (__FILE__": [CreateToolBar]\n");
                     64: 
                     65: #if defined (NT)
                     66:        hInst = (HANDLE)GetWindowLong (hwnd, GWL_HINSTANCE);
                     67: #elif defined (WIN16)
                     68:        hInst = GetWindowWord (hwnd, GWW_HINSTANCE);
                     69: #endif
                     70: 
                     71:        if (hbrBtnFace==0) {
                     72:                hbrBtnFace = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
                     73:        }
                     74:        if (hbrWindow==0) {
                     75:                hbrWindow = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
                     76:        }
                     77: 
                     78: 
                     79:        cxToolBorder = GetSystemMetrics (SM_CXBORDER);
                     80:        cyToolBorder = GetSystemMetrics (SM_CYBORDER);
                     81: 
                     82: //OutputDebugString (__FILE__": Calling CreateWindow\n");
                     83: 
                     84:        hwndTools = CreateWindow ("SamplerTools", "SamplerTools",
                     85:                WS_CHILD | WS_CLIPSIBLINGS | WS_BORDER | WS_VISIBLE,
                     86:                0, 0, 0, 0,
                     87:        hwnd, (HMENU)iId, hInst, NULL);
                     88:        if (!hwndTools) {
                     89:                OutputDebugString (__FILE__": CreateWindow Failed\n");
                     90:                return FALSE;
                     91:        }
                     92: //OutputDebugString (__FILE__": CreateWindow suceeded\n");
                     93: 
                     94:        /* Lets find out how big a combo box is... */
                     95:        hwndTmp = CreateWindow ("COMBOBOX", "Combo",
                     96:                WS_CHILD //| WS_CLIPSIBLINGS
                     97:                | WS_VISIBLE | CBS_DROPDOWNLIST,
                     98:                        0, 0, 0, 0,
                     99:                hwndTools, NULL, hInst, NULL);
                    100:        if (hwndTmp) {
                    101:                SendMessage (hwndTmp, WM_SETFONT, (UINT)hfontTools, MAKELONG (TRUE, 0));
                    102:                GetClientRect (hwndTmp, &rect);
                    103:                dyCombo = rect.bottom - rect.top;
                    104:                DestroyWindow (hwndTmp);
                    105:        } else {
                    106:                dyCombo = 30; // Just for a default value
                    107:        }
                    108: 
                    109:        hwndMain = hwnd; // So we can pass WM_CONTROL messages back to the master parent
                    110: 
                    111:        hInstance; // unreferenced
                    112: 
                    113:        return TRUE;
                    114: }
                    115: 
                    116: int ToolBarHeight (HWND hwnd)
                    117: {
                    118:        RECT rect;
                    119:        
                    120:        GetClientRect (hwndTools, &rect);
                    121:        return rect.bottom-rect.top;
                    122: 
                    123:        hwnd; //unreferenced
                    124: }
                    125: 
                    126: BOOL AdjustToolBar (HWND hwnd)
                    127: {
                    128:        RECT rect;
                    129: 
                    130:        GetClientRect (hwnd, &rect);
                    131: 
                    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;
                    139: }
                    140: 
                    141: void UpdatePositions (HWND hwnd)
                    142: {
                    143:        INT i, x, y, dx, dy, cnt;
                    144: 
                    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: 
                    181: 
                    182:    if(hwnd == NULL ){                          /* JAP mod, can be called from WM_SIZE */
                    183:                UpdateWindow(hwndTools);        /* and hwndTools, isnt initialized yet*/
                    184:        }
                    185:        else{   
                    186:                UpdateWindow (hwnd);
                    187:        }
                    188: }
                    189: 
                    190: BOOL AddToolSpace (INT iWidth, INT iHeight)
                    191: {
                    192:        if (cntToolCtrls >= MAXCTRLS) return FALSE;
                    193:        toolCtrl[cntToolCtrls].hwnd = 0;
                    194:        toolCtrl[cntToolCtrls].wType = TC_SPACE;
                    195:        toolCtrl[cntToolCtrls].iWidth = iWidth;
                    196:        toolCtrl[cntToolCtrls].iHeight = iHeight;
                    197:        if ((toolCtrl[cntToolCtrls].iHeight + (6*cyToolBorder)) > dyTools) {
                    198:                dyTools = (toolCtrl[cntToolCtrls].iHeight + (6*cyToolBorder));
                    199:        }
                    200:        UpdatePositions(NULL);    /* JAP HACK */
                    201:        cntToolCtrls++;
                    202:        return TRUE;
                    203: }
                    204: 
                    205: HWND AddToolLabel (HANDLE hInst, INT iId, LPSTR szLabel, INT iWidth, DWORD dwStyle)
                    206: {
                    207:        HDC hdc;
                    208: 
                    209:        if (cntToolCtrls >= MAXCTRLS) return (HWND)0; // No room left in our fixed array
                    210: 
                    211:        toolCtrl[cntToolCtrls].hwnd = CreateWindow ("STATIC", szLabel,
                    212:        WS_CHILD //| WS_CLIPSIBLINGS
                    213:        | WS_VISIBLE | dwStyle,
                    214:                0, 0, 0, 0,
                    215:        hwndTools, (HMENU)iId, hInst, NULL);
                    216: 
                    217:        if (!toolCtrl[cntToolCtrls].hwnd) return (HWND)0; // CreateWindow failed for some reason
                    218: 
                    219:        SendMessage (toolCtrl[cntToolCtrls].hwnd, WM_SETFONT, (UINT)hfontTools, MAKELONG (TRUE, 0));
                    220:        toolCtrl[cntToolCtrls].wType = TC_LABEL;
                    221: 
                    222:        hdc = GetDC (hwndTools);
                    223:        if (iWidth < 0) {
                    224:                toolCtrl[cntToolCtrls].iWidth = tmToolFont.tmAveCharWidth * abs(iWidth);
                    225:        } else if (iWidth == 0) {
                    226: #ifdef NT
                    227:                SIZE size;
                    228:                GetTextExtentPoint (hdc, szLabel, lstrlen(szLabel), &size);
                    229:                toolCtrl[cntToolCtrls].iWidth = size.cx;
                    230: #else
                    231:                toolCtrl[cntToolCtrls].iWidth = LOWORD(GetTextExtent (hdc, szLabel, lstrlen(szLabel)));
                    232: #endif
                    233:        } else {
                    234:                toolCtrl[cntToolCtrls].iWidth = iWidth;
                    235:        }
                    236:        toolCtrl[cntToolCtrls].iHeight = tmToolFont.tmHeight;
                    237: 
                    238:        if ((toolCtrl[cntToolCtrls].iHeight + (6*cyToolBorder)) > dyTools) {
                    239:                dyTools = (toolCtrl[cntToolCtrls].iHeight + (6*cyToolBorder));
                    240:        }
                    241: 
                    242:        ReleaseDC (hwndTools, hdc);
                    243:        UpdatePositions(NULL);   /* JAP HACK*/
                    244:        return toolCtrl[cntToolCtrls++].hwnd;
                    245: }
                    246: 
                    247: HWND AddToolCombo (HANDLE hInst, INT iId, INT iWidth, DWORD dwStyle)
                    248: {
                    249: 
                    250:        if (cntToolCtrls >= MAXCTRLS) return (HWND)0; // No room left in our fixed array
                    251: 
                    252:        if (dwStyle==0) dwStyle = CBS_DROPDOWNLIST;
                    253:        toolCtrl[cntToolCtrls].hwnd = CreateWindow ("COMBOBOX", "",
                    254:        WS_CHILD //| WS_CLIPSIBLINGS
                    255:                | WS_VISIBLE | dwStyle,
                    256:                0, 0, 0, 0,
                    257:                hwndTools, (HMENU)iId, hInst, NULL);
                    258: 
                    259:        if (!toolCtrl[cntToolCtrls].hwnd) return (HWND)0; // CreateWindow failed for some reason
                    260: 
                    261:        SendMessage (toolCtrl[cntToolCtrls].hwnd, WM_SETFONT, (UINT)hfontTools, MAKELONG (TRUE, 0));
                    262:        toolCtrl[cntToolCtrls].wType = TC_COMBO;
                    263: 
                    264:        if (iWidth < 0) {
                    265:                toolCtrl[cntToolCtrls].iWidth = tmToolFont.tmAveCharWidth * abs(iWidth);
                    266:        } else if (iWidth == 0) {
                    267:                toolCtrl[cntToolCtrls].iWidth = tmToolFont.tmAveCharWidth * 15; // just a default width
                    268:        } else {
                    269:                toolCtrl[cntToolCtrls].iWidth = iWidth;
                    270:        }
                    271:        toolCtrl[cntToolCtrls].iHeight = dyCombo;
                    272: 
                    273:        if ((toolCtrl[cntToolCtrls].iHeight + (6*cyToolBorder)) > dyTools) {
                    274:                dyTools = (toolCtrl[cntToolCtrls].iHeight + (6*cyToolBorder));
                    275:        }
                    276: 
                    277:        UpdatePositions(NULL);
                    278:        return toolCtrl[cntToolCtrls++].hwnd;
                    279: }
                    280: 
                    281: 
                    282: HWND AddToolButton (HANDLE hInst, INT iId, LPSTR szLabel, INT iWidth, INT iHeight, DWORD dwStyle)
                    283: {
                    284:        HDC hdc;
                    285: 
                    286:        if (cntToolCtrls >= MAXCTRLS) return (HWND)0; // No room left in our fixed array
                    287: 
                    288:        if (dwStyle == 0) dwStyle = BS_PUSHBUTTON;
                    289:        toolCtrl[cntToolCtrls].hwnd = CreateWindow ("BUTTON", szLabel,
                    290:        WS_CHILD //| WS_CLIPSIBLINGS
                    291:                | WS_VISIBLE | dwStyle,
                    292:                0, 0, 0, 0,
                    293:        hwndTools, (HMENU)iId, hInst, NULL);
                    294: 
                    295:        if (!toolCtrl[cntToolCtrls].hwnd) return (HWND)0; // CreateWindow failed for some reason
                    296: 
                    297:        SendMessage (toolCtrl[cntToolCtrls].hwnd, WM_SETFONT, (UINT)hfontTools, MAKELONG (TRUE, 0));
                    298:        toolCtrl[cntToolCtrls].wType = TC_BUTTON;
                    299: 
                    300:        hdc = GetDC (hwndTools);
                    301:        SelectObject (hdc, hfontTools);
                    302:        if (iWidth < 0) {
                    303:                toolCtrl[cntToolCtrls].iWidth = tmToolFont.tmAveCharWidth * abs(iWidth);
                    304:                toolCtrl[cntToolCtrls].iWidth += (6*cxToolBorder);
                    305:        } else if (iWidth == 0) {
                    306: #if defined (NT)
                    307:                SIZE size;
                    308:                GetTextExtentPoint (hdc, szLabel, lstrlen(szLabel), &size);
                    309:                toolCtrl[cntToolCtrls].iWidth = size.cx;
                    310: #elif defined (WIN16)
                    311:                toolCtrl[cntToolCtrls].iWidth = LOWORD(GetTextExtent (hdc, szLabel, lstrlen(szLabel)));
                    312: #endif
                    313:                toolCtrl[cntToolCtrls].iWidth += (6*cxToolBorder);
                    314:        } else {
                    315:                toolCtrl[cntToolCtrls].iWidth = iWidth;
                    316:        }
                    317:        if (iHeight < 0) {
                    318:                toolCtrl[cntToolCtrls].iHeight = tmToolFont.tmHeight;
                    319:                toolCtrl[cntToolCtrls].iHeight += (6*cyToolBorder);
                    320:        } else if (iHeight==0) {
                    321:                toolCtrl[cntToolCtrls].iHeight = dyTools - (6*cyToolBorder);
                    322:        } else {
                    323:                toolCtrl[cntToolCtrls].iHeight = iHeight;
                    324:        }
                    325: 
                    326:        if ((toolCtrl[cntToolCtrls].iHeight + (6*cyToolBorder)) > dyTools) {
                    327:                dyTools = (toolCtrl[cntToolCtrls].iHeight + (6*cyToolBorder));
                    328:        }
                    329: 
                    330:        if (dwStyle & BS_OWNERDRAW) {
                    331:                toolCtrl[cntToolCtrls].hIcon = LoadIcon (hInst, szLabel);
                    332:        } else {
                    333:                toolCtrl[cntToolCtrls].hIcon = NULL;
                    334:        }
                    335: 
                    336:        ReleaseDC (hwndTools, hdc);
                    337:        UpdatePositions(NULL);
                    338:        return toolCtrl[cntToolCtrls++].hwnd;
                    339: }
                    340: 
                    341: 
                    342: BOOL DestroyToolBar (void)
                    343: {
                    344:        return DeleteObject (hbrBtnFace);
                    345: }
                    346: 
                    347: void DrawButton (HDC hdc, RECT rect, BOOL bDown, HICON hIcon)
                    348: {
                    349:        HBRUSH  hBrush, hbrFrame, hbrFace, hbrHilite, hbrShadow;
                    350:        RECT    border;
                    351:        INT     i;
                    352: 
                    353:        hbrFrame = CreateSolidBrush(GetSysColor(COLOR_WINDOWFRAME));
                    354:        hbrFace = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
                    355:        hbrHilite = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
                    356:        hbrShadow = CreateSolidBrush(GetSysColor(COLOR_BTNSHADOW));
                    357: 
                    358:        FillRect (hdc, &rect, hbrFace);
                    359: 
                    360:        if (hIcon) {
                    361:                if (bDown) {
                    362:                        DrawIcon (hdc, rect.left + (4*cyToolBorder), rect.top + (4*cyToolBorder), hIcon);
                    363:                } else {
                    364:                        DrawIcon (hdc, rect.left + (3*cyToolBorder), rect.top + (3*cyToolBorder), hIcon);
                    365:                }
                    366:        }
                    367: 
                    368:        hBrush = hbrFrame;
                    369:        border = rect; border.bottom = border.top + cyToolBorder;
                    370:        FillRect (hdc, &border, hBrush);
                    371:        border = rect; border.right = border.left + cxToolBorder;
                    372:        FillRect (hdc, &border, hBrush);
                    373:        border = rect; border.top = border.bottom - cyToolBorder;
                    374:        FillRect (hdc, &border, hBrush);
                    375:        border = rect; border.left = border.right - cxToolBorder;
                    376:        FillRect (hdc, &border, hBrush);
                    377: 
                    378:        for (i= 0; i<2; i++) {
                    379:                InflateRect (&rect, -cxToolBorder, -cyToolBorder);
                    380:                hBrush = (bDown?hbrShadow:hbrHilite);
                    381:                border = rect; border.bottom = border.top + cyToolBorder;
                    382:                FillRect (hdc, &border, hBrush);
                    383:                border = rect; border.right = border.left + cxToolBorder;
                    384:                FillRect (hdc, &border, hBrush);
                    385:                if (!bDown) {
                    386:                        hBrush = hbrShadow;
                    387:                        border = rect; border.top = border.bottom - cyToolBorder;
                    388:                        FillRect (hdc, &border, hBrush);
                    389:                        border = rect; border.left = border.right - cxToolBorder;
                    390:                        FillRect (hdc, &border, hBrush);
                    391:                }
                    392:        }
                    393: 
                    394:        DeleteObject (hbrFrame);
                    395:        DeleteObject (hbrFace);
                    396:        DeleteObject (hbrHilite);
                    397:        DeleteObject (hbrShadow);
                    398: 
                    399: }
                    400: 
                    401: 
                    402: LONG APIENTRY ToolsProc (HWND hwnd, UINT msg, UINT wParam, LONG lParam)
                    403: {
                    404:        HDC          hdc;
                    405:        PAINTSTRUCT      ps;
                    406:        INT          iType, idCtrl, msgCtrl, i;
                    407:        RECT         rect, border;
                    408:        COLORREF         clrColor;
                    409:        HWND         hwndCtl;
                    410:        LONG         lStyle;
                    411:        HBRUSH       hBrush;
                    412:        LPDRAWITEMSTRUCT lpdi;
                    413:        HICON        hIcon;
                    414: 
                    415:        switch (msg) {
                    416:        case WM_CREATE:
                    417: //OutputDebugString (__FILE__": [ToolsProc] WM_CREATE\n");
                    418: 
                    419: #ifdef NOCREATEFONT // CreateFont is failing in NT
                    420:                hfontTools = (HFONT)NULL;
                    421: #else
                    422:                hfontTools = CreateFont(16, 0, 0, 0, 0, 0, 0, 0,
                    423:                                ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
                    424:                                DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS, NULL);
                    425:                if (!hfontTools) {
                    426:                                MessageBox (GetFocus(), "Failed To Create Font", "StatusProc", MB_OK);
                    427:                        }
                    428: #endif
                    429:                hdc = GetDC (hwnd);
                    430:                SelectObject (hdc, hfontTools);
                    431:                        GetTextMetrics (hdc, &tmToolFont);
                    432:                ReleaseDC (hwnd, hdc);
                    433: 
                    434: //OutputDebugString (__FILE__": [ToolsProc] WM_CREATE (exit)\n");
                    435: 
                    436:                        return DefWindowProc (hwnd, msg, wParam, lParam);
                    437: 
                    438:                case WM_SIZE:
                    439:                        UpdatePositions(hwnd);
                    440:                        break;
                    441: 
                    442: #if defined (NT)
                    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;
                    453: #elif defined (WIN16)
                    454:                case WM_CTLCOLOR:
                    455:                        hdc = wParam;
                    456:                        hwndCtl = LOWORD(lParam);
                    457:                        iType = HIWORD (lParam);
                    458: #endif
                    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 NULL;
                    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:                        switch (lpdi->itemAction) {
                    520:                                // handle normal drawing of button, but check if its selected or focus
                    521:                                case ODA_SELECT:
                    522:                                case ODA_DRAWENTIRE:
                    523:                                        // handle button pressed down select state -- button down bitmap
                    524:                                        //   text is right & down 2 pixels
                    525:                                        hIcon = NULL;
                    526:                                        for (i=0; i< cntToolCtrls; i++) {
                    527:                                                if (toolCtrl[i].hwnd == lpdi->hwndItem) {
                    528:                                                        hIcon = toolCtrl[i].hIcon;
                    529:                                                }
                    530:                                        }
                    531:                                        if (lpdi->itemState & ODS_SELECTED) {
                    532:                                                DrawButton (lpdi->hDC,lpdi->rcItem, TRUE, hIcon);
                    533:                                        } else { // not selected -- button up; text is in normal position
                    534:                                                DrawButton (lpdi->hDC,lpdi->rcItem, FALSE, hIcon);
                    535:                                        }
                    536:                                        return TRUE;
                    537:                        }
                    538:                        break;
                    539: 
                    540:                case WM_COMMAND:
                    541: #if defined (NT)
                    542:                        idCtrl = LOWORD(wParam);
                    543:                        msgCtrl = HIWORD(wParam);
                    544:                        hwndCtl = (HWND)lParam;
                    545: #elif defined (WIN16)
                    546:                        idCtrl = wParam;
                    547:                        msgCtrl = HIWORD (lParam);
                    548:                        hwndCtl = LOWORD (lParam);
                    549: #endif
                    550: 
                    551:                        if (GetWindowLong (hwndCtl, GWL_STYLE) & BS_OWNERDRAW) {
                    552:                                if (msgCtrl == BN_DOUBLECLICKED) {
                    553:                                        PostMessage (hwndCtl, WM_LBUTTONDOWN, 0, 0);
                    554:                                        return TRUE;
                    555:                                }
                    556:                        }
                    557:                        PostMessage (hwndMain, msg, wParam, lParam);
                    558:                        return DefWindowProc (hwnd, msg, wParam, lParam);
                    559: 
                    560: 
                    561:                default:
                    562:                        return DefWindowProc (hwnd, msg, wParam, lParam);
                    563:        }
                    564:        return 0L;
                    565: }
                    566: 

unix.superglobalmegacorp.com

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