MSG.C
上传用户:bjghjy
上传日期:2007-01-07
资源大小:379k
文件大小:4k
源码类别:

金融证券系统

开发平台:

Visual C++

  1. #include <windows.h>
  2. #include <windowsx.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include "appmain.h"
  6. #include "resource.h"
  7. #include "msg.h"
  8. HWND ghWndMsg=NULL;
  9. char MsgInfo[100];
  10. LRESULT CALLBACK _export MsgWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
  11. BOOL RegisterMsg(void)
  12. {
  13. WNDCLASS wc;
  14. memset(&wc, 0, sizeof(wc));
  15. wc.style =CS_SAVEBITS;
  16. wc.lpfnWndProc =MsgWndProc;
  17. wc.lpszClassName ="MSG";
  18. wc.hbrBackground =GetStockObject(LTGRAY_BRUSH);
  19. wc.hInstance = ghInstance;
  20. wc.lpszMenuName = NULL;
  21. wc.hCursor = LoadCursor(NULL, IDC_ARROW);        
  22. wc.hIcon = LoadIcon(ghInstance, MAKEINTRESOURCE(IDR_MAINFRAME));
  23. if(!RegisterClass(&wc)) return FALSE;
  24. return TRUE;
  25. }
  26. int Msg(char *msg,int type)
  27. {
  28.     if(type&MSG_VERT|type&MSG_HORT&&strlen(msg)!=0)
  29.     {    
  30.      strcpy(MsgInfo,msg);         
  31.      InvalidateRect(ghWndMsg,NULL, TRUE);
  32.     }    
  33.     if(type&MSG_HIDE)
  34.     {
  35.      strcpy(MsgInfo,"");         
  36.      InvalidateRect(ghWndMsg,NULL, TRUE);    
  37.     }
  38.     if(type&MSG_FOCU)
  39.     {
  40.      EnableWindow(ghWndMsg,TRUE);
  41.      SetFocus(ghWndMsg);
  42.     }
  43. return TRUE;
  44. }
  45. LRESULT CALLBACK  MsgWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  46. {
  47. HDC hdc;
  48. PAINTSTRUCT ps;
  49. static LastWin =NULL;
  50. RECT rc,rc1;
  51. HPEN hPen;
  52. switch(message)
  53. {
  54. case WM_TIMER:
  55. KillTimer(hWnd,1);
  56. ShowWindow(hWnd,SW_HIDE);
  57. if(IsWindowEnabled(hWnd)&&LastWin!=NULL)
  58. {    
  59. SetFocus(LastWin);
  60. EnableWindow(hWnd,FALSE);
  61. SendMessage(LastWin,WM_KEYDOWN,VK_RETURN,0L);
  62. }
  63. break;
  64. case WM_CHAR:
  65. SendMessage(hWndInput, WM_CHAR, wParam, lParam);
  66. break;
  67. case WM_SIZE:
  68. if(IsWindowVisible(hWnd))
  69. InvalidateRect(hWnd, NULL, TRUE);
  70. break;
  71. case WM_CTLCOLOR:
  72.         switch(HIWORD(lParam))
  73.         {
  74.              case CTLCOLOR_EDIT:
  75.              case CTLCOLOR_LISTBOX:
  76.                 SetTextColor((HDC) wParam, RGB(255, 0, 255));
  77.                  SetBkMode((HDC) wParam, TRANSPARENT);
  78.                  return (LRESULT) GetStockObject(LTGRAY_BRUSH);
  79.          }
  80.          return (LRESULT) NULL;
  81. break;
  82. case WM_PAINT:
  83. GetClientRect(hWnd, &rc);
  84. hdc =BeginPaint(hWnd,&ps);
  85. SelectObject(hdc,GetStockObject(WHITE_PEN));
  86.     MoveTo(hdc,1,rc.bottom-1);
  87.     LineTo(hdc,rc.right-8-INPUT_WIDTH,rc.bottom-1);
  88. LineTo(hdc,rc.right-8-INPUT_WIDTH,1);
  89.     hPen=CreatePen(PS_SOLID,1,RGB(65,65,65));     
  90.     SelectObject(hdc,hPen);
  91.     LineTo(hdc,1,1);
  92. LineTo(hdc,1,rc.bottom-1);
  93. SelectObject(hdc,GetStockObject(WHITE_PEN));
  94. MoveTo(hdc,rc.right-3-INPUT_WIDTH,rc.bottom-1);
  95. LineTo(hdc,rc.right-3+1,rc.bottom-1);
  96. LineTo(hdc,rc.right-3+1,1);
  97. SelectObject(hdc,hPen);
  98. LineTo(hdc,rc.right-3-INPUT_WIDTH,1);
  99. LineTo(hdc,rc.right-3-INPUT_WIDTH,rc.bottom-1);
  100. SelectObject(hdc,GetStockObject(WHITE_PEN));
  101. DeleteObject(hPen);
  102. SelectObject(hdc,GetStockObject(SYSTEM_FIXED_FONT));
  103. SetBkMode(hdc,TRANSPARENT);
  104. SetTextColor(hdc,RGB(0,0,255));
  105. SetRect(&rc1,1,1,rc.right-8-INPUT_WIDTH-1,rc.bottom-1);
  106. ExtTextOut(hdc,2,2,ETO_CLIPPED,&rc1,MsgInfo,strlen(MsgInfo),
  107. (LPINT) NULL);
  108. EndPaint(hWnd, &ps);
  109. break;
  110. }
  111. return DefWindowProc(hWnd, message, wParam, lParam);
  112. }
  113. BOOL CreateWndMsg(HWND hWnd)
  114. {                          
  115. int x, y;
  116. HWND hwnd;                    
  117. RECT rc;
  118. GetClientRect(ghWndMain, &rc);
  119. x =rc.right -rc.left;
  120. y =rc.bottom -rc.top;
  121. if(ghWndMsg==NULL)
  122. {
  123. hwnd =CreateWindow("MSG", NULL, WS_CHILD,
  124. 0, 
  125. rc.bottom -MSG_HEIGHT, 
  126. x,
  127. MSG_HEIGHT,
  128. ghWndMain, NULL, ghInstance, NULL);
  129. if(hwnd ==NULL)
  130. {
  131. ErrMsg(hWnd, "Error create msg window");
  132. return FALSE;
  133. }
  134.     ShowWindow(hwnd, SW_SHOW);
  135. ghWndMsg =hwnd;
  136. hWndInput =CreateWindow("EDIT", "", WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL,
  137. x-INPUT_WIDTH-2,
  138. 2,
  139. INPUT_WIDTH,
  140. MSG_HEIGHT-4,
  141. hwnd, NULL, ghInstance, NULL);
  142. SendMessage(hWndInput, EM_LIMITTEXT, 16, 0L);
  143. }
  144. else
  145. {
  146. SetWindowPos(ghWndMsg, (HWND)NULL,
  147.     0,
  148. rc.bottom -MSG_HEIGHT, 
  149. x,
  150. MSG_HEIGHT,
  151. NULL);
  152. SetWindowPos(hWndInput, (HWND)NULL,
  153. x-INPUT_WIDTH-2,
  154. 2,
  155. INPUT_WIDTH,
  156. MSG_HEIGHT-4,
  157. NULL);
  158. }
  159. return TRUE;
  160. }