STATUS.C
上传用户:carrie980
上传日期:2013-03-28
资源大小:1143k
文件大小:8k
源码类别:

视频捕捉/采集

开发平台:

Visual C++

  1. /**************************************************************************
  2.  *
  3.  *  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  4.  *  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  5.  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  6.  *  PURPOSE.
  7.  *
  8.  *  Copyright (C) 1992 - 1996 Microsoft Corporation.  All Rights Reserved.
  9.  *
  10.  **************************************************************************/
  11. /****************************************************************************
  12.  *
  13.  *   status.c: Status bar window
  14.  *
  15.  *   Vidcap32 Source code
  16.  *
  17.  ***************************************************************************/
  18. #include <windows.h>
  19. #include <windowsx.h>
  20. //#include <win32.h>
  21. #include <mmsystem.h>
  22. #include "status.h"
  23. /* for compiling under win3.0 - we don't have this attribute */
  24. #ifndef COLOR_BTNHIGHLIGHT
  25. #define COLOR_BTNHIGHLIGHT 20
  26. #endif
  27. #ifdef _WIN32
  28. typedef WNDPROC LPWNDPROC;
  29. #else
  30. typedef long (FAR PASCAL *LPWNDPROC)();
  31. #endif
  32. // class names for status bar and static text windows
  33. char szStatusClass[] = "StatusClass";
  34. char szText[]   = "SText";
  35. int gStatusStdHeight;   // based on font metrics
  36. static HANDLE ghFont;
  37. static HBRUSH ghbrHL, ghbrShadow;
  38. /* Function Prototypes */
  39. LONG FAR PASCAL statusWndProc(HWND hwnd, unsigned msg,
  40. UINT wParam, LONG lParam);
  41. LONG FAR PASCAL fnText(HWND, unsigned, UINT, LONG);
  42. static VOID NEAR PASCAL PaintText(HWND hwnd, HDC hdc);
  43. /*
  44.  * create the brushes we need
  45.  */
  46. void
  47. statusCreateTools(void)
  48. {
  49.     HDC hdc;
  50.     TEXTMETRIC tm;
  51.     HFONT hfont;
  52.     ghbrHL = CreateSolidBrush(GetSysColor(COLOR_BTNHIGHLIGHT));
  53.     ghbrShadow = CreateSolidBrush(GetSysColor(COLOR_BTNSHADOW));
  54.     /* Create the font we'll use for the status bar - use system as default */
  55.     ghFont = CreateFont(12, 0, // height, width
  56.                 0, 0, // escapement, orientation
  57.                 FW_NORMAL, // weight,
  58.                 FALSE, FALSE, FALSE, // attributes
  59.                 ANSI_CHARSET, // charset
  60.                 OUT_DEFAULT_PRECIS, // output precision
  61.                 CLIP_DEFAULT_PRECIS, // clip precision
  62.                 DEFAULT_QUALITY, // quality
  63.                 VARIABLE_PITCH | FF_MODERN,
  64.                 "Helv");
  65.     if (ghFont == NULL) {
  66.         ghFont = GetStockObject(SYSTEM_FONT);
  67.     }
  68.     // find the char size to calc standard status bar height
  69.     hdc = GetDC(NULL);
  70.     hfont = SelectObject(hdc, ghFont);
  71.     GetTextMetrics(hdc, &tm);
  72.     SelectObject(hdc, hfont);
  73.     ReleaseDC(NULL, hdc);
  74.     gStatusStdHeight = tm.tmHeight * 3 / 2;
  75. }
  76. void
  77. statusDeleteTools(void)
  78. {
  79.     DeleteObject(ghbrHL);
  80.     DeleteObject(ghbrShadow);
  81.     DeleteObject(ghFont);
  82. }
  83. /*--------------------------------------------------------------+
  84. | statusInit - initialize for status window, register the |
  85. |        Window's class. |
  86. | |
  87. +--------------------------------------------------------------*/
  88. #pragma alloc_text(INIT_TEXT, statusInit)
  89. BOOL statusInit(HANDLE hInst, HANDLE hPrev)
  90. {
  91.   WNDCLASS  cls;
  92.   statusCreateTools();
  93.   if (!hPrev){
  94.   cls.hCursor = LoadCursor(NULL, IDC_ARROW);
  95.   cls.hIcon = NULL;
  96.   cls.lpszMenuName = NULL;
  97.   cls.lpszClassName = szStatusClass;
  98.   cls.hbrBackground     = (HBRUSH) (COLOR_BTNFACE + 1);
  99.   cls.hInstance = hInst;
  100.   cls.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
  101.   cls.lpfnWndProc = statusWndProc;
  102.   cls.cbClsExtra = 0;
  103.   cls.cbWndExtra = 0;
  104.   if (!RegisterClass(&cls))
  105.   return FALSE;
  106.   cls.hCursor        = LoadCursor(NULL,IDC_ARROW);
  107.   cls.hIcon          = NULL;
  108.   cls.lpszMenuName   = NULL;
  109.   cls.lpszClassName  = (LPSTR)szText;
  110.   cls.hbrBackground  = (HBRUSH) (COLOR_BTNFACE + 1);
  111.   cls.hInstance      = hInst;
  112.   cls.style          = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
  113.   cls.lpfnWndProc    = (LPWNDPROC)fnText;
  114.   cls.cbClsExtra     = 0;
  115.   cls.cbWndExtra     = 0;
  116.   if (!RegisterClass(&cls))
  117. return FALSE;
  118.   }
  119.   return TRUE;
  120. }
  121. /*
  122.  * returns the recommended height for a status bar based on the
  123.  * character dimensions of the font used
  124.  */
  125. int
  126. statusGetHeight(void)
  127. {
  128.     return(gStatusStdHeight);
  129. }
  130. /*--------------------------------------------------------------+
  131. | statusUpdateStatus - update the status line |
  132. | |
  133. | The argument can either be NULL, a string, or a resource ID |
  134. | cast to a LPCSTR with MAKEINTRESOURCE. |
  135. +--------------------------------------------------------------*/
  136. void statusUpdateStatus(HWND hwnd, LPCSTR lpsz)
  137. {
  138.     char ach[80];
  139.     HWND hwndtext;
  140.     if ((lpsz != NULL) && (HIWORD((DWORD) lpsz) == 0)) {
  141. LoadString(GetWindowInstance(hwnd), LOWORD((DWORD) lpsz), ach, sizeof(ach));
  142. lpsz = ach;
  143.     }
  144.     hwndtext = GetDlgItem(hwnd, 1);
  145.     if (!lpsz || *lpsz == '') {
  146. SetWindowText(hwndtext,"");
  147.     } else {
  148. SetWindowText(hwndtext, lpsz);
  149.     }
  150. }
  151. /*--------------------------------------------------------------+
  152. | statusWndProc - window proc for status window |
  153. | |
  154. +--------------------------------------------------------------*/
  155. LONG FAR PASCAL 
  156. statusWndProc(HWND hwnd, unsigned msg, UINT wParam, LONG lParam)
  157. {
  158.   PAINTSTRUCT ps;
  159.   HDC hdc;
  160.   HWND          hwndSText;
  161.   switch(msg){
  162.     case WM_CREATE:
  163.     /* we need to create the static text control for the status bar */
  164.     hwndSText = CreateWindow(
  165.                             szText,
  166.                             "",
  167.                             WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS,
  168.             0, 0, 0, 0,
  169.                             hwnd,
  170.                             (HMENU) 1,  // child id
  171.                             GetWindowInstance(hwnd),
  172.                             NULL);
  173.     if (!hwndSText) {
  174.     return -1;
  175.             }
  176.     break;
  177.     case WM_DESTROY:
  178.             statusDeleteTools();
  179.     break;
  180.     case WM_SIZE:
  181.         {
  182.             RECT rc;
  183.             GetClientRect(hwnd, &rc);
  184.             MoveWindow(
  185.                 GetDlgItem(hwnd, 1),    // get child window handle
  186.                 2, 1,                   // xy just inside
  187.                 rc.right - 4,
  188.                 rc.bottom - 2,
  189.                 TRUE);
  190.     break;
  191.         }
  192.     case WM_PAINT:
  193.     hdc = BeginPaint(hwnd, &ps);
  194.             // only the background and the child window need painting
  195.     EndPaint(hwnd, &ps);
  196.     break;
  197.     case WM_SYSCOLORCHANGE:
  198.         statusDeleteTools();
  199.         statusCreateTools();
  200.         break;
  201.     case WM_ERASEBKGND:
  202.         break;
  203.   }
  204.   return DefWindowProc(hwnd, msg, wParam, lParam);
  205. }
  206. /*
  207.  * window proc for static text window
  208.  */
  209. LONG FAR PASCAL 
  210. fnText(HWND hwnd, UINT msg, UINT wParam, LONG lParam )
  211. {
  212. PAINTSTRUCT ps;
  213. switch (msg) {
  214. case WM_SETTEXT:
  215. DefWindowProc(hwnd, msg, wParam, lParam);
  216. InvalidateRect(hwnd,NULL,FALSE);
  217. UpdateWindow(hwnd);
  218. return 0L;
  219. case WM_ERASEBKGND:
  220. return 0L;
  221. case WM_PAINT:
  222. BeginPaint(hwnd, &ps);
  223. PaintText(hwnd, ps.hdc);
  224. EndPaint(hwnd, &ps);
  225. return 0L;
  226.         }
  227. return DefWindowProc(hwnd, msg, wParam, lParam);
  228. }
  229. /*--------------------------------------------------------------+
  230. | PaintText - paint the shadowed static text field. |
  231. | |
  232. +--------------------------------------------------------------*/
  233. VOID NEAR PASCAL
  234. PaintText(HWND hwnd, HDC hdc)
  235. {
  236.   RECT rc;
  237.   char        ach[128];
  238.   int  len;
  239.   int dx, dy;
  240.   RECT rcFill;
  241.   HFONT hfontOld;
  242.   HBRUSH hbrSave;
  243.   GetClientRect(hwnd, &rc);
  244.   len = GetWindowText(hwnd,ach,sizeof(ach));
  245.   SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
  246.   SetTextColor(hdc, GetSysColor(COLOR_BTNTEXT));
  247.   hfontOld = SelectObject(hdc, ghFont);
  248.   rcFill.left = rc.left + 1;
  249.   rcFill.right = rc.right - 1;
  250.   rcFill.top = rc.top + 1;
  251.   rcFill.bottom = rc.bottom - 1;
  252.   /* move in some and do background and text in one swoosh */
  253.   ExtTextOut(hdc,4,1,ETO_OPAQUE,&rcFill,ach,len,NULL);
  254.   dx = rc.right - rc.left;
  255.   dy = rc.bottom - rc.top;
  256.   hbrSave = SelectObject(hdc, ghbrShadow);
  257.   PatBlt(hdc, rc.left, rc.top, 1, dy, PATCOPY);
  258.   PatBlt(hdc, rc.left, rc.top, dx, 1, PATCOPY);
  259.   SelectObject(hdc, ghbrHL);
  260.   PatBlt(hdc, rc.right-1, rc.top+1, 1, dy-1, PATCOPY);
  261.   PatBlt(hdc, rc.left+1, rc.bottom -1, dx-1, 1,  PATCOPY);
  262.   if (hfontOld)
  263.   SelectObject(hdc, hfontOld);
  264.   if (hbrSave)
  265.   SelectObject(hdc, hbrSave);
  266.   return ;
  267. }