Annotation of mstools/samples/deb/toolbar.c, revision 1.1.1.2

1.1       root        1: // ************************************************************************
1.1.1.2 ! root        2: //
        !             3: //                      Microsoft Developer Support
        !             4: //               Copyright (c) 1992 Microsoft Corporation
        !             5: //
        !             6: // ************************************************************************
        !             7: // MODULE    : ToolBar.C
1.1       root        8: // PURPOSE   : A Win32 DLL containing various ToolBar controls
                      9: // FUNCTIONS :
                     10: //   LibMain()         - Dll entry point
                     11: //   TextButtonBar()   - generate a text button ToolBar
                     12: //   TextButtonBarProc - processes messages for the TextButtonBarWClass
                     13: // COMMENTS  :
1.1.1.2 ! root       14: //
1.1       root       15: // ************************************************************************
                     16: #define   NOMINMAX           // eliminate the duplicate min, max defs
                     17: #include <Windows.H>         // required for all Windows applications
                     18: #include <StdLib.H>          // ltoa()
                     19: 
                     20: #include "ToolBar.H"         // specific to this program
                     21: 
                     22: //-- internal data
                     23: HWND hWndToolBarOwner;       // window handle of Toolbar owner
                     24:                              // where all WM_COMMAND messages are sent
                     25: 
1.1.1.2 ! root       26: //-- internal prototypes
        !            27: LRESULT CALLBACK TextButtonBarProc( HWND, UINT, WPARAM, LPARAM );
        !            28: 
        !            29: 
1.1       root       30: // ************************************************************************
1.1.1.2 ! root       31: // FUNCTION : DllEntryPoint( HINSTANCE, DWORD, LPVOID )
        !            32: // PURPOSE  : DllEntryPoint is called by Windows when
1.1       root       33: //            the DLL is initialized, Thread Attached, and other times.
1.1.1.2 ! root       34: // COMMENTS : No initialization is needed here.
1.1       root       35: // ************************************************************************
1.1.1.2 ! root       36: BOOL WINAPI
        !            37: DllEntryPoint( HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved )
1.1       root       38: {
1.1.1.2 ! root       39:   UNREFERENCED_PARAMETER( hInstDLL );
        !            40:   UNREFERENCED_PARAMETER( fdwReason );
        !            41:   UNREFERENCED_PARAMETER( lpvReserved );
1.1       root       42: 
                     43:   return( TRUE );
                     44: }
                     45: 
                     46: 
                     47: // ************************************************************************
1.1.1.2 ! root       48: // FUNCTION : TextButtonBar( HWND, LPTEXTBUTTON, LPINT )
1.1       root       49: // PURPOSE  : Generate a text button ToolBar
                     50: // COMMENTS : lpTextButton points to an array of TEXTBUTTON
                     51: //            structures.  The last structure must set the
                     52: //            member lpButtonText to NULL.  lpHeight contains the
                     53: //            height of the ToolBar window.
                     54: // ************************************************************************
                     55: HWND
                     56: TextButtonBar( HWND hWndParent, LPTEXTBUTTON lpTextButton, LPINT lpHeight )
                     57: {
                     58:   #define BUTTON_BORDER    4
                     59:   #define BUTTONBAR_BORDER 4
                     60: 
                     61:   static HWND         hWndTextButtonBar;
                     62: 
                     63:   HDC          hDC;
                     64:   WNDCLASS     wndclass;
                     65:   LONG         ButtonWidth;
                     66:   LONG         ButtonHeight;
                     67:   INT          xPosButton;
                     68:   INT          ButtonSpacing;
                     69:   INT          ButtonSpace;
                     70:   LPTSTR       lpButtonString;
                     71:   LPTEXTBUTTON lpTempTextButton;
                     72:   TEXTMETRIC   tm;
                     73:   SIZE         ButtonTextSize;
                     74:   RECT         rect;
                     75: 
                     76: 
                     77:   //-- store owner of Toolbar
                     78:   hWndToolBarOwner = hWndParent;
                     79: 
                     80:   //-- register the TestButtonBar window class
                     81:   wndclass.style         = NULL;
                     82:   wndclass.lpfnWndProc   = (WNDPROC) TextButtonBarProc;
                     83:   wndclass.cbClsExtra    = 0;
                     84:   wndclass.cbWndExtra    = 0;
                     85:   wndclass.hInstance     = NULL;
                     86:   wndclass.hIcon         = NULL;
                     87:   wndclass.hCursor       = NULL;
                     88:   wndclass.hbrBackground = GetStockObject(LTGRAY_BRUSH);
                     89:   wndclass.lpszMenuName  = NULL;
                     90:   wndclass.lpszClassName = "TextButtonBarWClass";
                     91: 
                     92:   if( !RegisterClass( &wndclass ) )
1.1.1.2 ! root       93:     return( FALSE );
1.1       root       94: 
                     95:   hDC = GetDC( hWndParent );
                     96:   GetTextMetrics( hDC, &tm );
                     97:   ButtonHeight = 2 * BUTTON_BORDER + tm.tmHeight;
                     98:   *lpHeight = 2 * BUTTONBAR_BORDER + ButtonHeight;
                     99: 
                    100:   GetWindowRect( GetDesktopWindow(), &rect );
                    101:   hWndTextButtonBar = CreateWindow(
                    102:                         "TextButtonBarWClass", "Toolbar",
                    103:                         WS_CHILD | WS_CLIPSIBLINGS,
                    104:                         0, 0, rect.right - rect.left, *lpHeight,
                    105:                         hWndToolBarOwner,
                    106:                         (HMENU) NULL, (HANDLE) NULL, NULL );
                    107: 
                    108:   SetWindowPos( hWndTextButtonBar, (HWND) 1, 0, 0, 0, 0,
                    109:     SWP_NOMOVE | SWP_NOSIZE );
                    110: 
                    111:   //-- button spacing information
                    112:   ButtonSpacing = BUTTON_BORDER / 2;
                    113:   ButtonSpace   = BUTTON_BORDER * 4;
                    114:   xPosButton    = BUTTON_BORDER * 2;
                    115: 
                    116:   //-- Create all the button windows
                    117:   for( lpTempTextButton = lpTextButton;
                    118:          !(lpTempTextButton->lpButtonText == '\0' && lpTempTextButton->idButton == NULL);
                    119:          lpTempTextButton++ ) {
                    120: 
                    121:     //-- if TB_SPACE the adjust new xPos and continue
                    122:     if( lpTempTextButton->idButton == TB_SPACE ) {
                    123:       xPosButton += ButtonSpace;
                    124:       continue;
                    125:     }
                    126: 
                    127:     lpButtonString = lpTempTextButton->lpButtonText;
1.1.1.2 ! root      128:     GetTextExtentPoint( hDC, lpButtonString, lstrlen(lpButtonString), &ButtonTextSize );
1.1       root      129:     ButtonWidth = (4 * BUTTON_BORDER) + (LONG) ButtonTextSize.cx;
                    130: 
                    131:     (lpTempTextButton->hWndButton) = CreateWindow(
                    132:          "BUTTON", lpButtonString,
                    133:          WS_VISIBLE | BS_PUSHBUTTON /* | WS_CLIPSIBLINGS */ | WS_CHILD,
                    134:          xPosButton, BUTTONBAR_BORDER, ButtonWidth, ButtonHeight,
                    135:          hWndTextButtonBar,
                    136:          (HMENU) lpTempTextButton->idButton,
                    137:          (HANDLE) NULL, NULL );
                    138: 
                    139:     xPosButton += ButtonWidth + ButtonSpacing;
                    140:   }
                    141:   ReleaseDC( hWndParent, hDC );
                    142: 
                    143:   return( hWndTextButtonBar );
                    144: }
                    145: 
                    146: 
                    147: // ************************************************************************
                    148: // FUNCTION : TextButtonBarProc( HWND, UINT, WPARAM, LPARAM )
                    149: // PURPOSE  : Processes messages for the TextButtonBarWClass
                    150: // MESSAGES :
                    151: //  WM_COMMAND - forwarded onto the owner
                    152: //  WM_PAINT   - draw a 3D background
                    153: // COMMENTS :
                    154: // ************************************************************************
                    155: LRESULT CALLBACK
                    156: TextButtonBarProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
                    157: {
                    158:   static HDC         hDC;
                    159:   static RECT        rect;
                    160:   static PAINTSTRUCT ps;
                    161: 
                    162:   switch( uMsg ) {
                    163: 
                    164:     case WM_COMMAND:
                    165:       SendMessage( hWndToolBarOwner, uMsg, wParam, lParam );
1.1.1.2 ! root      166:       return( FALSE );
1.1       root      167: 
                    168:     case WM_PAINT:
                    169:       hDC = BeginPaint( hWnd, &ps );
                    170:       GetClientRect( hWnd, &rect );
                    171: 
                    172:       SelectObject( hDC, GetStockObject(WHITE_PEN) );
                    173:       MoveToEx( hDC, rect.left, rect.top, NULL );
                    174:       LineTo( hDC, rect.right+1, rect.top );
                    175: 
                    176:       #define DKGRAY_PEN RGB(128, 128, 128)
                    177:       SelectObject( hDC, (HANDLE) CreatePen( PS_SOLID, 1, DKGRAY_PEN ) );
                    178:       MoveToEx( hDC, rect.left, rect.bottom-2, NULL );
                    179:       LineTo( hDC, rect.right+1, rect.bottom-2 );
                    180: 
                    181:       SelectObject( hDC, (HANDLE) CreatePen( PS_SOLID, 1, BLACK_PEN ) );
                    182:       MoveToEx( hDC, rect.left, rect.bottom-1, NULL );
                    183:       LineTo( hDC, rect.right+1, rect.bottom-1 );
                    184: 
                    185:       DeleteObject( SelectObject( hDC, GetStockObject(BLACK_PEN) ) );
                    186:       EndPaint( hWnd, &ps );
1.1.1.2 ! root      187:       return( FALSE );
1.1       root      188: 
                    189:     default:
                    190:       return( DefWindowProc(hWnd, uMsg, wParam, lParam) );
                    191:   }
                    192: }

unix.superglobalmegacorp.com

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