home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / inole2 / classlib / cstatlin.cpp < prev    next >
C/C++ Source or Header  |  1995-05-03  |  7KB  |  346 lines

  1. /*
  2.  * CSTATLIN.C
  3.  * Sample Code Class Libraries
  4.  *
  5.  * C++ wrapper class for a status line control
  6.  *
  7.  * Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  8.  *
  9.  * Kraig Brockschmidt, Microsoft
  10.  * Internet  :  kraigb@microsoft.com
  11.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  12.  */
  13.  
  14.  
  15. #include <windows.h>
  16. #include "classlib.h"
  17.  
  18.  
  19. /*
  20.  * CStatusLine::CStatusLine
  21.  * CStatusLine::~CStatusLine
  22.  *
  23.  * Constructor Parameters:
  24.  *  hInst           HINSTANCE of the module we're loaded in.
  25.  */
  26.  
  27. CStatusLine::CStatusLine(HINSTANCE hInst)
  28.     : CWindow(hInst)
  29.     {
  30.     return;
  31.     }
  32.  
  33.  
  34. CStatusLine::~CStatusLine(void)
  35.     {
  36.     return;
  37.     }
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44. /*
  45.  * CStatusLine::Init
  46.  *
  47.  * Purpose:
  48.  *  Initializes a status line object by creating the control that it
  49.  *  owns.
  50.  *
  51.  * Parameters:
  52.  *  hWndParent      HWND of the parent window.  The status line is
  53.  *                  created up from the bottom of this window,
  54.  *                  spanning the entire width of the window.
  55.  *  uID             UINT id of the control.
  56.  *  cy              UINT height to create the control
  57.  *
  58.  * Return Value:
  59.  *  BOOL            TRUE if the function succeeded, FALSE otherwise.
  60.  */
  61.  
  62. BOOL CStatusLine::Init(HWND hWndParent, UINT uID, UINT cy)
  63.     {
  64.     RECT        rc;
  65.  
  66.     GetClientRect(hWndParent, &rc);
  67.  
  68.     m_cy=cy;
  69.     m_hWnd=CreateWindow(CLASS_STATSTRIP, TEXT("Ready")
  70.         , WS_CHILD | WS_VISIBLE, rc.left, rc.top, rc.right-rc.left
  71.         , cy , hWndParent, (HMENU)uID, m_hInst, 0L);
  72.  
  73.     return (NULL!=m_hWnd);
  74.     }
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81. /*
  82.  * CStatusLine::OnSize
  83.  *
  84.  * Purpose:
  85.  *  Handles parent resizing.  The owner of this window is responsible
  86.  *  to call this function when it wants the status line to resize.  The
  87.  *  status line will automatically occupy a lower strip of CYSTATSTRIP
  88.  *  high on the bottom of the window.
  89.  *
  90.  * Parameters:
  91.  *  hWndParent      HWND of the parent window to which we're resizing
  92.  *
  93.  * Return Value:
  94.  *  None
  95.  */
  96.  
  97. void CStatusLine::OnSize(HWND hWndParent)
  98.     {
  99.     RECT        rc;
  100.  
  101.     GetClientRect(hWndParent, &rc);
  102.  
  103.     SetWindowPos(m_hWnd, NULL, rc.left, rc.bottom-rc.top-CYSTATSTRIP
  104.         , rc.right-rc.left, m_cy, SWP_NOZORDER);
  105.  
  106.     return;
  107.     }
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115. /*
  116.  * CStatusLine::MessageSet
  117.  *
  118.  * Purpose:
  119.  *  Sets a message in the status line explicitly with a string.
  120.  *
  121.  * Parameters:
  122.  *  pszMsg          LPTSTR to the string to display.
  123.  *
  124.  * Return Value:
  125.  *  None
  126.  */
  127.  
  128. void CStatusLine::MessageSet(LPTSTR psz)
  129.     {
  130.     SetWindowText(m_hWnd, psz);
  131.     return;
  132.     }
  133.  
  134.  
  135.  
  136.  
  137.  
  138. /*
  139.  * CStatusLine::MessageGet
  140.  *
  141.  * Purpose:
  142.  *  Retrieves the current message from the status line
  143.  *
  144.  * Parameters:
  145.  *  psz             LPTSTR in which to return the message.
  146.  *  cchMax          UINT maximum number of characters to copy.
  147.  *
  148.  * Return Value:
  149.  *  UINT            Number of characters copied.
  150.  */
  151.  
  152. UINT CStatusLine::MessageGet(LPTSTR psz, UINT cchMax)
  153.     {
  154.     return GetWindowText(m_hWnd, psz, cchMax);
  155.     }
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162. /*
  163.  * CStatusLine::MessageGetLength
  164.  *
  165.  * Purpose:
  166.  *  Returns the length of the current message in the status line.
  167.  *
  168.  * Parameters:
  169.  *  None
  170.  *
  171.  * Return Value:
  172.  *  UINT            Number of characters in the current message
  173.  */
  174.  
  175. UINT CStatusLine::MessageGetLength(void)
  176.     {
  177.     return GetWindowTextLength(m_hWnd);
  178.     }
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185. /*
  186.  * CStatusLine::FontSet
  187.  *
  188.  * Purpose:
  189.  *  Changes the font in the status line.
  190.  *
  191.  * Parameters:
  192.  *  hFont           HFONT of the font to use in the control.
  193.  *  fRedraw         BOOL indicating if the control is to repaint or
  194.  *                  not.
  195.  *
  196.  * Return Value:
  197.  *  None
  198.  */
  199.  
  200. void CStatusLine::FontSet(HFONT hFont, BOOL fRedraw)
  201.     {
  202.     SendMessage(m_hWnd, WM_SETFONT, (WPARAM)hFont, fRedraw);
  203.     return;
  204.     }
  205.  
  206.  
  207.  
  208.  
  209.  
  210. /*
  211.  * CStatusLine::FontGet
  212.  *
  213.  * Purpose:
  214.  *  Retrieves the handle of the current font used in the control.
  215.  *
  216.  * Parameters:
  217.  *  None
  218.  *
  219.  * Return Value:
  220.  *  HFONT           Handle to the current font.
  221.  */
  222.  
  223. HFONT CStatusLine::FontGet(void)
  224.     {
  225.     return (HFONT)(UINT)SendMessage(m_hWnd, WM_GETFONT, 0, 0L);
  226.     }
  227.  
  228.  
  229.  
  230.  
  231.  
  232. /*
  233.  * CStatusLine::Enable
  234.  *
  235.  * Purpose:
  236.  *  Enables or disables the status line window, graying the text if
  237.  *  the control is disabled.
  238.  *
  239.  * Parameters:
  240.  *  fEnable         BOOL specifying to enable (TRUE) or disable
  241.  *
  242.  * Return Value:
  243.  *  None
  244.  */
  245.  
  246. void CStatusLine::Enable(BOOL fEnable)
  247.     {
  248.     EnableWindow(m_hWnd, fEnable);
  249.     return;
  250.     }
  251.  
  252.  
  253.  
  254.  
  255.  
  256. /*
  257.  * CStatusLine::MessageMap
  258.  *
  259.  * Purpose:
  260.  *  Initializes a CStatusLine for automated processing of
  261.  *  WM_MENUSELECT messages as well as setting up a list of messages
  262.  *  that we can display using identifiers instead of string
  263.  *  pointers.  See MenuSelect and MessageDisplay members.
  264.  *
  265.  * Parameters:
  266.  *  hWnd            HWND of the window owning menus.
  267.  *  hInst           HINSTANCE of the app from which to load resources
  268.  *  uIDRMap         UINT identifying a resource mapping ID values to
  269.  *                  string ID values.
  270.  *  idsMin          UINT specifying the lowest string ID to load.
  271.  *  idsMax          UINT specifying the hightest string ID to load.
  272.  *  cchMax          UINT maximum string length.
  273.  *  uIDPopupMin     UINT lowest ID to assign to popup menus.
  274.  *  uIDPopupMax     UINT highest ID to assign to popup menus.
  275.  *  uIDStatic       UINT ID for the quiescent message.
  276.  *  uIDBlank        UINT ID for a blank message.
  277.  *  uIDSysMenu      UINT ID for the system menu.
  278.  *
  279.  * Return Value:
  280.  *  BOOL            TRUE if the function was successful, FALSE
  281.  *                  otherwise.
  282.  */
  283.  
  284. BOOL CStatusLine::MessageMap(HWND hWnd, HINSTANCE hInst, UINT uIDRMap
  285.     , UINT idsMin, UINT idsMax, UINT cchMax, UINT uIDPopupMin
  286.     , UINT uIDPopupMax, UINT uIDStatic, UINT uIDBlank
  287.     , UINT uIDSysMenu)
  288.     {
  289.     //Initialize all the messages in the status line
  290.     return StatStripMessageMap(m_hWnd, hWnd, hInst, uIDRMap, idsMin
  291.         , idsMax, cchMax, uIDPopupMin, uIDPopupMax, uIDStatic
  292.         , uIDBlank, uIDSysMenu);
  293.     }
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300. /*
  301.  * CStatusLine::MenuSelect
  302.  *
  303.  * Purpose:
  304.  *  Displays the appropriate message for whatever is in the
  305.  *  parameters of a WM_MENUSELECT message.  This can only be called
  306.  *  if StatStripMessageMap has already been called and must be used
  307.  *  with the same menu the owner window had at the time of that call.
  308.  *
  309.  * Parameters:
  310.  *  wParam          WPARAM of the WM_MENUSELECT message.
  311.  *  lParam          LPARAM of the WM_MENUSELECT message.
  312.  *
  313.  * Return Value:
  314.  *  None
  315.  */
  316.  
  317. void CStatusLine::MenuSelect(WPARAM wParam, LPARAM lParam)
  318.     {
  319.     StatStripMenuSelect(m_hWnd, wParam, lParam);
  320.     return;
  321.     }
  322.  
  323.  
  324.  
  325.  
  326.  
  327. /*
  328.  * CStatusLine::MessageDisplay
  329.  *
  330.  * Purpose:
  331.  *  Displays the appropriate message for a given ID value.   This can
  332.  *  only be called if StatStripMessageMap has already been called.
  333.  *
  334.  * Parameters:
  335.  *  uID             UINT of the message to display.
  336.  *
  337.  * Return Value:
  338.  *  None
  339.  */
  340.  
  341. void CStatusLine::MessageDisplay(UINT uID)
  342.     {
  343.     StatStripMessageDisplay(m_hWnd, uID);
  344.     return;
  345.     }
  346.