home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 December / PCWKCD1296.iso / vjplusb / activex / inetsdk / samples / msconf / cnftest / msg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-03  |  5.4 KB  |  212 lines

  1. /* ----------------------------------------------------------------------
  2.  
  3.     CNFTEST sample for Microsoft ActiveX Conferencing
  4.  
  5.     Unpublished work.
  6.     Copyright (c) 1996, Microsoft Corporation
  7.     All rights reserved.
  8.  
  9.     msg.c
  10.  
  11.     Main message handlers.
  12. ---------------------------------------------------------------------- */
  13.  
  14. #include "main.h"
  15.  
  16. // Main window message table definition.
  17. static MSD _rgmsdMain[] =
  18. {
  19.     {WM_COMMAND,       MsgCmdMain},
  20.     {WM_NOTIFY,        MsgNotify},
  21.     {WM_CREATE,        MsgCreate},
  22.     {WM_DESTROY,       MsgDestroy},
  23.     {WM_CLOSE,         MsgClose},
  24.     {WM_SIZE,          MsgSize},
  25.     {WM_MENUSELECT,    MsgMenuSelect},
  26.     {WM_GETMINMAXINFO, MsgGetMinMax},
  27.     {WM_DRAWITEM,      MsgDrawItem},
  28.         
  29.     {0, (PFNMSG) DefWindowProc}
  30. };
  31.  
  32.  
  33. /*  W N D  P R O C */
  34. /*-------------------------------------------------------------------------
  35.     %%Function: WndProc
  36.  
  37.     Main Window proc
  38. -------------------------------------------------------------------------*/
  39. LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wparam, LPARAM lparam)
  40. {
  41.     return DispatchMsg(_rgmsdMain, hwnd, uMsg, wparam, lparam);
  42. }
  43.  
  44.  
  45. /*  M S G  D E S T R O Y */
  46. /*-------------------------------------------------------------------------
  47.     %%Function: MsgDestroy
  48.  
  49.     Handle a WM_DESTROY message
  50. -------------------------------------------------------------------------*/
  51. LRESULT MsgDestroy(HWND hwnd, UINT uMsg, WPARAM wparam, LPARAM lParam)
  52. {
  53.     PostQuitMessage(0);
  54.     return 0;
  55. }
  56.  
  57.  
  58. /* M S G  C R E A T E */
  59. /*----------------------------------------------------------------------------
  60.     %%Function: MsgCreate
  61.  
  62. ----------------------------------------------------------------------------*/
  63. LRESULT MsgCreate(HWND hwnd, UINT uMsg, WPARAM wparam, LPARAM lParam)
  64. {
  65.     return 0;
  66. }
  67.  
  68.  
  69.  
  70. /*  M S G  C L O S E */
  71. /*-------------------------------------------------------------------------
  72.     %%Function: MsgClose
  73.  
  74.     Handle a WM_CLOSE message
  75. -------------------------------------------------------------------------*/
  76. LRESULT MsgClose(HWND hwnd, UINT uMsg, WPARAM wparam, LPARAM lparam)
  77. {
  78.     WritePref();
  79.     DestroyWindow(hwnd);
  80.  
  81.     if (ghInstDll != NULL)
  82.         FreeLibrary(ghInstDll);
  83.  
  84.     return 0;
  85. }
  86.  
  87. /* _ S I Z E  S T A T U S */
  88. /*----------------------------------------------------------------------------
  89.     %%Function: _SizeStatus
  90.  
  91. ----------------------------------------------------------------------------*/
  92. VOID _SizeStatus(int dxClient, int dy)
  93. {
  94.     int rgdxp[3];
  95.  
  96.     rgdxp[2] = dxClient;
  97.     dxClient -= 100;
  98.     rgdxp[1] = dxClient;
  99.     dxClient -= 100;
  100.     rgdxp[0] = dxClient;
  101.     SendMessage(ghwndSbar, SB_SETPARTS, (WPARAM) 3, (LPARAM) rgdxp);
  102. }
  103.  
  104. /* _ S I Z E  M S G  W I N D O W */
  105. /*----------------------------------------------------------------------------
  106.     %%Function: _SizeMsgWindow
  107.  
  108. ----------------------------------------------------------------------------*/
  109. VOID _SizeMsgWindow(int dx, int dy)
  110. {
  111.     RECT rc;
  112.     int xLeft;
  113.     int yTop;
  114.     int d;
  115.  
  116.     xLeft = 0;
  117.     yTop = 3;
  118.     dy -= 3;
  119.  
  120.     if (gPref.fSbar)
  121.     {
  122.         // adjust for status bar
  123.         GetClientRect(ghwndSbar, &rc);
  124.         d = (rc.bottom - rc.top);
  125.         dy -= d;
  126.     }
  127.  
  128.     MoveWindow(ghwndMsg, xLeft, yTop, dx, dy, fTrue);
  129. }
  130.  
  131. /* R E C A L C  M S G  W I N D O W */
  132. /*----------------------------------------------------------------------------
  133.     %%Function: RecalcMsgWindow
  134.  
  135. ----------------------------------------------------------------------------*/
  136. VOID RecalcMsgWindow(void)
  137. {
  138.     RECT rc;
  139.  
  140.     GetClientRect(ghwndMain, &rc);
  141.     _SizeMsgWindow(rc.right, rc.bottom);
  142. }
  143.  
  144.  
  145. /*  M S G  S I Z E */
  146. /*-------------------------------------------------------------------------
  147.     %%Function: MsgSize
  148.  
  149.     Handle a WM_SIZE message
  150. -------------------------------------------------------------------------*/
  151. LRESULT MsgSize(HWND hwnd, UINT uMsg, WPARAM wparam, LPARAM lparam)
  152. {
  153.     int dxClient = LOWORD(lparam);  // width of client area
  154.     int dyClient = HIWORD(lparam);  // height of client area
  155.  
  156.     _SizeMsgWindow(dxClient, dyClient);
  157.     _SizeStatus(dxClient, 0);
  158.     SendMessage(ghwndSbar, uMsg, wparam, lparam);
  159.     
  160.     return 0;
  161. }
  162.  
  163.  
  164. /*  M S G  G E T  M I N  M A X */
  165. /*-------------------------------------------------------------------------
  166.     %%Function: MsgGetMinMax
  167.  
  168.     Handle a WM_GETMINMAXINFO message
  169. -------------------------------------------------------------------------*/
  170. LRESULT MsgGetMinMax(HWND hwnd, UINT uMsg, WPARAM wparam, LPARAM lparam)
  171. {
  172.     LPMINMAXINFO lpminmax = (LPMINMAXINFO) lparam;
  173.  
  174.     if (gdxWndMin == 0 || gdyWndMin == 0)
  175.         return 0;
  176.  
  177.     lpminmax->ptMinTrackSize.x = gdxWndMin;
  178.     lpminmax->ptMinTrackSize.y = gdyWndMin;
  179.  
  180.     return 0;
  181. }
  182.  
  183. /*  M S G  D R A W  I T E M */
  184. /*----------------------------------------------------------------------------
  185.     %%Function: MsgDrawItem
  186.  
  187. ----------------------------------------------------------------------------*/
  188. LRESULT MsgDrawItem(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  189. {
  190.     switch (wParam)
  191.     {
  192.     case IDW_MSG:
  193.         {
  194.         COLORREF cv;
  195.  
  196.         LPDRAWITEMSTRUCT lpdi = (LPDRAWITEMSTRUCT)lParam;
  197.         char sz[MAX_PATH];
  198.             
  199.         cv = SendMessage(ghwndMsg, LB_GETITEMDATA, (WPARAM)lpdi->itemID, (LPARAM)0);
  200.         SetTextColor(lpdi->hDC, cv);
  201.             
  202.         SendMessage(ghwndMsg, LB_GETTEXT, (WPARAM)lpdi->itemID, (LPARAM)sz);
  203.         DrawText( lpdi->hDC, sz, -1, &lpdi->rcItem, DT_LEFT | DT_SINGLELINE);
  204.         }
  205.         break;
  206.     default:
  207.         break;
  208.     } /* switch */                                                          
  209.  
  210.     return 0;
  211. }                                                                             
  212.