File:  [WindowsNT SDKs] / mstools / samples / ntfonts / toolbar.c
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs
Thu Aug 9 18:22:13 2018 UTC (7 years, 9 months ago) by root
Branches: msft, MAIN
CVS tags: ntsdk-oct-1992, HEAD
Microsoft Windows NT Build 328 10-12-1992

/**************************************************************************\
*  toolbar.c -- module for the "toolbar" on top of the main window.
*   Includes the window procedure and an initialization routine.
*
*         Steve Firebaugh
*         Microsoft Developer Support
*         Copyright (c) 1992 Microsoft Corporation
*
\**************************************************************************/
#define UNICODE

#include <windows.h>
#include "ntfonts.h"


/* for the initial positioning of the buttons within the toolbar. */
#define SPACEBUTTON 8
#define CXBUTTON ((GetSystemMetrics (SM_CXFULLSCREEN)) /5 -2*SPACEBUTTON)
#define BUTTONTOP    TOOLBARHEIGHT/8
#define BUTTONHEIGHT TOOLBARHEIGHT*3/4
#define BUTTONLEFT(x) ((2*x+1)*SPACEBUTTON + x*CXBUTTON)

#define BORDER     2



int initTB (HWND hwndParent)
{
WNDCLASS  wc;

  wc.style = NULL;
  wc.lpfnWndProc = (WNDPROC)ToolBarWndProc;
  wc.cbClsExtra = 0;
  wc.cbWndExtra = 0;
  wc.hInstance = hInst;
  wc.hIcon = NULL;
  wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
  wc.lpszMenuName = NULL;
  wc.lpszClassName = TEXT("ToolBar");

  if (!RegisterClass(&wc)) return (FALSE);

  hwndTB = CreateWindow(
      TEXT("ToolBar"),
      NULL,
      WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE,
      0,0,
      GetSystemMetrics (SM_CXFULLSCREEN),
      TOOLBARHEIGHT,
      hwndParent, NULL, hInst, NULL);

  if (!hwndTB) return (FALSE);

  return TRUE;
}


/**************************************************************************\
*
*  function:  ToolBarWndProc
*
*  input parameters:  normal window procedure parameters.
*
*  global variables:
*   hwndMain - parent of the toolbar.
*
* When the window is created, create the various buttons.  When those
*  buttons send WM_COMMAND messages later, send the messages back to hwndMain.
*
\**************************************************************************/
LRESULT CALLBACK ToolBarWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HWND  hwndButton;
  switch (message) {

    /**********************************************************************\
    *  WM_CREATE
    *
    * Create the various buttons which are on the toolbar.  Once the buttons
    *  are created, set the window ID so that the WM_COMMANDS may be
    *  distinguished.
    \**********************************************************************/
    case WM_CREATE: {
      hwndButton = CreateWindow(
        TEXT("BUTTON"),TEXT("EnumFonts"),
        WS_CHILD | WS_VISIBLE,
        BUTTONLEFT(0),BUTTONTOP, CXBUTTON, BUTTONHEIGHT,
        hwnd, NULL, hInst, NULL);
      SetWindowLong (hwndButton, GWL_ID, TBID_ENUM);

      hwndButton = CreateWindow(
        TEXT("BUTTON"),TEXT("CreateFont"),
        WS_CHILD | WS_VISIBLE,
        BUTTONLEFT(1),BUTTONTOP, CXBUTTON, BUTTONHEIGHT,
        hwnd, NULL, hInst, NULL);
      SetWindowLong (hwndButton, GWL_ID, TBID_CREATE);

      hwndButton = CreateWindow(
        TEXT("BUTTON"),TEXT("GetMetrics"),
        WS_CHILD | WS_VISIBLE ,
        BUTTONLEFT(2),BUTTONTOP, CXBUTTON, BUTTONHEIGHT,
        hwnd, NULL, hInst, NULL);
      SetWindowLong (hwndButton, GWL_ID, TBID_GETTM);

      hwndButton = CreateWindow(
        TEXT("BUTTON"),TEXT("GetFontData"),
        WS_CHILD | WS_VISIBLE ,
        BUTTONLEFT(3),BUTTONTOP, CXBUTTON, BUTTONHEIGHT,
        hwnd, NULL, hInst, NULL);
      SetWindowLong (hwndButton, GWL_ID, TBID_GETFONTDATA);

      hwndButton = CreateWindow(
        TEXT("BUTTON"),TEXT("Enum(Printer)"),
        WS_CHILD | WS_VISIBLE,
        BUTTONLEFT(4),BUTTONTOP, CXBUTTON, BUTTONHEIGHT,
        hwnd, NULL, hInst, NULL);
      SetWindowLong (hwndButton, GWL_ID, TBID_PRINT);

    } break;


    /**********************************************************************\
    *  WM_COMMAND
    *
    * Send the command messages back to hwndMain.
    \**********************************************************************/
    case WM_COMMAND:
      PostMessage (hwndMain,message, wParam, lParam);
    break;


    /**********************************************************************\
    *  WM_PAINT
    *
    * Paint two rectangular strips, one on top, one on bottom.
    \**********************************************************************/
    case WM_PAINT : {
      PAINTSTRUCT ps;
      RECT rect;
      HDC hdc;

      hdc = BeginPaint(hwnd, &ps);
      GetClientRect (hwnd, &rect);
      rect.right --;
      rect.bottom --;

      SelectObject (hdc, GetStockObject (BLACK_PEN));
      MoveToEx (hdc, rect.right, rect.top, NULL);
      LineTo (hdc, rect.right, rect.bottom);
      LineTo (hdc, rect.left, rect.bottom);
      SelectObject (hdc, GetStockObject (WHITE_PEN));
      LineTo (hdc, rect.left, rect.top);
      LineTo (hdc, rect.right, rect.top);

      EndPaint (hwnd, &ps);
    } break;


    default:
      return (DefWindowProc(hwnd, message, wParam, lParam));
    }
    return (NULL);
}

unix.superglobalmegacorp.com

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