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

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

unix.superglobalmegacorp.com

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