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

unix.superglobalmegacorp.com

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