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

金融证券系统

开发平台:

Visual C++

  1. #include <windows.h>
  2. #include <string.h>
  3. #include <time.h>
  4. #include "resource.h"
  5. #include "appmain.h"
  6. #include "global.h"
  7. #include "hq.h"
  8. #include "hq_cl.h"
  9. #include "caption.h"
  10. #include "jy_cl.h"
  11. #include "rsa.h"
  12. #define  CAPTION_CLASS "商标"
  13. #define SCROLL_X_COOR 200
  14. #define TIMER_X_COOR 100
  15. extern JyQs;
  16. extern HFILE hfZx;
  17. extern int UDP_Send_Zx(void);
  18. extern char szDataPath[128];
  19. extern void PASCAL ShowBmp(HDC hDC,HBITMAP hBmp,int left,int top,int width,int height);
  20. BOOL RegisterCaption(void)
  21. {
  22. WNDCLASS wc;
  23. memset(&wc, 0, sizeof(wc));
  24. wc.style =CS_HREDRAW | CS_VREDRAW;
  25. wc.lpfnWndProc =CaptionWndProc;
  26. wc.lpszClassName =CAPTION_CLASS;
  27. wc.hbrBackground =GetStockObject(LTGRAY_BRUSH);
  28. wc.hInstance = ghInstance;
  29. wc.lpszMenuName = NULL;
  30. wc.hCursor = LoadCursor(NULL, IDC_ARROW);        
  31. wc.hIcon = LoadIcon(ghInstance, MAKEINTRESOURCE(IDR_MAINFRAME));
  32. if(!RegisterClass(&wc)) return FALSE;
  33. return TRUE;
  34. }
  35. BOOL CreateWndCaption(HWND hWnd)
  36. {                          
  37. int x;
  38. HWND hwnd;
  39. if(ghWndCaption!=NULL) return TRUE;
  40. x =GetSystemMetrics(SM_CXSCREEN);
  41. hwnd =CreateWindow(CAPTION_CLASS, NULL, WS_CHILD|WS_CLIPSIBLINGS,
  42. 0, 0, x, STATUS_HEIGHT-2,
  43. hWnd, NULL, ghInstance, NULL);
  44. if(hwnd ==NULL)
  45. {
  46. ErrMsg(hWnd, "不能建立标题区窗口");
  47. return FALSE;
  48. }
  49. ghWndCaption =hwnd;
  50. ShowWindow(hwnd, SW_SHOW);
  51. return TRUE;
  52. }
  53. LRESULT CALLBACK CaptionWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  54. {
  55. PAINTSTRUCT ps;
  56. RECT rc;
  57. HDC hDC;
  58. DWORD dw;
  59.     static int s_left=0;
  60.     static int s_width =0;
  61.     static char szText[2000];
  62. static HBITMAP hBmpCaption =NULL;
  63. static BITMAP bmp;
  64. static RECT rcRoll;
  65. static int times_num =58;
  66. static long file_len =0, total_len =0;
  67. int read_len =0;
  68. unsigned int t_left;
  69. HPEN hPen;
  70. TEXTMETRIC tm;
  71. OFSTRUCT os;
  72. char temp[80];
  73. switch(message)
  74. {
  75. case WM_SETFOCUS:
  76. SetFocus(ghWndMain);
  77. break;
  78. case WM_CREATE:
  79. GetClientRect(hWnd, &rc);
  80. memcpy(&rcRoll, &rc, sizeof(rc));
  81. rcRoll.right -=4;
  82. rcRoll.left =SCROLL_X_COOR;
  83. s_width =0;
  84. s_left =rcRoll.right;
  85. szText[0] =0;
  86. SetTimer(hWnd, 1, 1000, NULL);
  87. hBmpCaption =LoadBitmap(ghInstance, MAKEINTRESOURCE(IDB_CAPTION));
  88. //hBmpCaption =LoadBitmap(ghInstance, MAKEINTRESOURCE(IDB_CX));
  89. GetObject(hBmpCaption, sizeof(BITMAP), &bmp);
  90. break;
  91. case WM_USER+1:
  92. if((long)lParam !=0L) break;
  93. strcpy(temp, szDataPath);
  94. strcat(temp, "\zx.txt");
  95.      hfZx =OpenFile(temp, &os, OF_SHARE_DENY_NONE|OF_READWRITE);
  96. if(hfZx ==HFILE_ERROR) break;
  97. _llseek(hfZx, 0, SEEK_SET);
  98. file_len =_llseek(hfZx, 0, SEEK_END);
  99. if(file_len <=0)
  100. {   
  101. _lclose(hfZx);
  102.   break;
  103. }
  104. if(file_len <=total_len)
  105. {
  106. _llseek(hfZx, 0, SEEK_SET);
  107. total_len =0;
  108. }
  109. else _llseek(hfZx, total_len, SEEK_SET);
  110. read_len =1000;
  111. if(read_len > file_len-total_len)
  112. read_len =(int)(file_len-total_len);
  113. szText[0] =0;
  114. _lread(hfZx, szText, read_len);
  115. total_len +=read_len;
  116. szText[read_len] =0;
  117. hDC =GetDC(hWnd);
  118. dw =GetTextExtent(hDC, szText, strlen(szText));
  119. ReleaseDC(hWnd, hDC);
  120. s_width =LOWORD(dw);
  121. _lclose(hfZx);
  122. SendMessage(hWnd, WM_TIMER, 0, 0L);
  123. //_lclose(hfZx);
  124. break;
  125. case WM_USER+2:
  126. GetClientRect(hWnd, &rc);
  127. hDC =GetDC(hWnd);
  128. GetTextMetrics(hDC, &tm);
  129. SetTextColor(hDC, RGB(255, 0, 65));
  130. SetBkColor(hDC,RGB(200, 200, 200));
  131. ExtTextOut(hDC,s_left,(rc.bottom-tm.tmHeight)/2,ETO_CLIPPED,&rcRoll,
  132. szText,strlen(szText),(LPINT) NULL);
  133. ReleaseDC(hWnd,hDC);
  134. break;
  135. case WM_TIMER:
  136.     KillTimer(hWnd, 1);
  137. if(szText[0]==0)
  138. {   
  139. if(IsSzRead&&IsShRead)
  140. {
  141. UDP_Send_Zx();
  142. SendMessage(hWnd, WM_USER+1, 0, 0L);
  143. }
  144. SetTimer(hWnd, 1, 1000*30, NULL);
  145. break;
  146. }
  147. if(times_num ++>5000) //10 minutes  //60
  148. {
  149. if(HqTime[0].fRunning)
  150. UDP_Send_Zx();
  151. times_num =0;
  152. }
  153. s_left -=1;
  154. SendMessage(hWnd, WM_USER+2, 0, 0L);
  155. if(s_width + s_left ==rcRoll.left)
  156. {
  157.   s_left =rcRoll.right;
  158.   SetTimer(hWnd, 1, 8000,NULL);
  159. }
  160. else
  161. SetTimer(hWnd, 1, 100,NULL);
  162. break;
  163. case WM_RBUTTONDOWN:
  164.     if(IsWindowVisible(ghWndHq))
  165.     {
  166. SendMessage(ghWndHq, WM_KEYDOWN, VK_PRIOR, 0L);
  167. }       
  168. break;
  169. case WM_LBUTTONDOWN:       
  170. t_left =(unsigned int)DrawTime(-1);
  171. if(LOWORD(lParam)>(t_left-bmp.bmWidth)/2&&LOWORD(lParam)<t_left)
  172.     {
  173.      hDC =GetDC(hWnd);
  174.      GetClientRect(hWnd, &rc);
  175.      hPen=CreatePen(PS_SOLID,1,RGB(65,65,65));     
  176.      SelectObject(hDC,hPen);
  177.      MoveTo(hDC,(t_left-bmp.bmWidth)/2,(rc.bottom -bmp.bmHeight)/2);
  178.      LineTo(hDC,(t_left-bmp.bmWidth)/2,(rc.bottom +bmp.bmHeight)/2);
  179.      MoveTo(hDC,(t_left-bmp.bmWidth)/2,(rc.bottom -bmp.bmHeight)/2);
  180.      LineTo(hDC,(t_left+bmp.bmWidth)/2,(rc.bottom -bmp.bmHeight)/2);     
  181.      SelectObject(hDC,GetStockObject(WHITE_PEN));
  182.      MoveTo(hDC,(t_left+bmp.bmWidth)/2-1,(rc.bottom +bmp.bmHeight)/2-1);
  183.      LineTo(hDC,(t_left-bmp.bmWidth)/2-1,(rc.bottom +bmp.bmHeight)/2-1);
  184.      MoveTo(hDC,(t_left+bmp.bmWidth)/2-1,(rc.bottom +bmp.bmHeight)/2-1);
  185.      LineTo(hDC,(t_left+bmp.bmWidth)/2-1,(rc.bottom -bmp.bmHeight)/2-1);
  186.      DeleteObject(hPen);
  187.      ReleaseDC(hWnd, hDC);
  188.      SendMessage(ghWndHq,WM_KEYDOWN,VK_ESCAPE,0L);
  189.     }  
  190. //break;
  191. case WM_LBUTTONUP:
  192. t_left =(unsigned int)DrawTime(-1);
  193. if(LOWORD(lParam)>(t_left-bmp.bmWidth)/2&&LOWORD(lParam)<t_left)
  194.     {
  195.      hDC =GetDC(hWnd);
  196.      GetClientRect(hWnd, &rc);
  197.      SelectObject(hDC,GetStockObject(WHITE_PEN));
  198.      MoveTo(hDC,(t_left-bmp.bmWidth)/2,(rc.bottom -bmp.bmHeight)/2);
  199.      LineTo(hDC,(t_left-bmp.bmWidth)/2,(rc.bottom +bmp.bmHeight)/2);
  200.      MoveTo(hDC,(t_left-bmp.bmWidth)/2,(rc.bottom -bmp.bmHeight)/2);
  201.      LineTo(hDC,(t_left+bmp.bmWidth)/2,(rc.bottom -bmp.bmHeight)/2);     
  202.      hPen=CreatePen(PS_SOLID,1,RGB(65,65,65));     
  203.      SelectObject(hDC,hPen);
  204.      MoveTo(hDC,(t_left+bmp.bmWidth)/2-1,(rc.bottom +bmp.bmHeight)/2-1);
  205.      LineTo(hDC,(t_left-bmp.bmWidth)/2-1,(rc.bottom +bmp.bmHeight)/2-1);
  206.      MoveTo(hDC,(t_left+bmp.bmWidth)/2-1,(rc.bottom +bmp.bmHeight)/2-1);
  207.      LineTo(hDC,(t_left+bmp.bmWidth)/2-1,(rc.bottom -bmp.bmHeight)/2-1);
  208.      SelectObject(hDC,GetStockObject(WHITE_PEN));
  209.      DeleteObject(hPen);
  210.      ReleaseDC(hWnd, hDC);
  211.     }  
  212. break;
  213. case WM_PAINT:
  214. GetClientRect(hWnd, &rc);
  215. BeginPaint(hWnd, &ps);
  216. GetTextMetrics(ps.hdc, &tm);
  217.             
  218. hPen=CreatePen(PS_SOLID,1,RGB(65,65,65));
  219. SelectObject(ps.hdc,hPen);
  220. MoveTo(ps.hdc,SCROLL_X_COOR-1,(rc.bottom-tm.tmHeight)/2-2); //竖线
  221. LineTo(ps.hdc,SCROLL_X_COOR-1,rc.bottom-(rc.bottom-tm.tmHeight)/2+2);
  222. MoveTo(ps.hdc,SCROLL_X_COOR-1,(rc.bottom-tm.tmHeight)/2-2);
  223. LineTo(ps.hdc,rc.right-4,(rc.bottom-tm.tmHeight)/2-2);
  224. SelectObject(ps.hdc,GetStockObject(WHITE_PEN));
  225. MoveTo(ps.hdc,rc.right-4,(rc.bottom-tm.tmHeight)/2-2);
  226. LineTo(ps.hdc,rc.right-4,rc.bottom-(rc.bottom-tm.tmHeight)/2+2);
  227. MoveTo(ps.hdc,SCROLL_X_COOR-1,rc.bottom-(rc.bottom-tm.tmHeight)/2+2);
  228. LineTo(ps.hdc,rc.right-4,rc.bottom-(rc.bottom-tm.tmHeight)/2+2);
  229.             
  230. //SetTextColor(ps.hdc, RGB(255, 0, 65));
  231. //SetBkColor(ps.hdc,RGB(200, 200, 200));
  232. //SetBkMode(ps.hdc, TRANSPARENT);
  233. //ExtTextOut(ps.hdc,s_left,(rc.bottom-tm.tmHeight)/2,ETO_CLIPPED,&rcRoll,
  234. // szText,strlen(szText),(LPINT) NULL);
  235. SelectObject(ps.hdc,GetStockObject(WHITE_PEN));
  236. t_left = DrawTime(-1);
  237. ShowBmp(ps.hdc,hBmpCaption,(t_left-bmp.bmWidth)/2,
  238. (rc.bottom -bmp.bmHeight)/2,bmp.bmWidth,rc.bottom);
  239. DispQsName(JyQs,RsaOk);
  240. DeleteObject(hPen);
  241. EndPaint(hWnd, &ps);
  242. break;
  243. case WM_DESTROY:
  244. if(hBmpCaption) DeleteObject(hBmpCaption);
  245. KillTimer(hWnd, 1);
  246. break;
  247. default:
  248. break;
  249. }
  250. return DefWindowProc(hWnd, message, wParam, lParam);
  251. }
  252. int DrawTime(int ret)
  253. {
  254. HDC hDC;
  255. RECT rc;
  256.     HPEN hPen;
  257.     int x0,y0,x1,y1;
  258.     char temp[20];
  259.     DWORD dw;
  260.     
  261. if(ret>=0) return(0);
  262. hDC =GetDC(ghWndCaption);
  263. GetClientRect(ghWndCaption, &rc);
  264. SetTextColor(hDC,RGB(0,0,255));
  265. SetBkColor(hDC,RGB(200,200,200));
  266. _strtime(temp);
  267. dw=GetTextExtent(hDC,temp,strlen(temp));
  268. y0=(rc.bottom-HIWORD(dw))/2;
  269. y1=rc.bottom-y0;
  270. x1=TIMER_X_COOR-4;
  271. x0=x1-LOWORD(dw);
  272. hPen=CreatePen(PS_SOLID,1,RGB(65,65,65));
  273. SelectObject(hDC,hPen);
  274. MoveTo(hDC,x0-1,y0-2); //竖线
  275. LineTo(hDC,x0-1,y1+2);      
  276. MoveTo(hDC,x0-1,y0-2);
  277. LineTo(hDC,x1+1,y0-2);
  278. SelectObject(hDC,GetStockObject(WHITE_PEN));
  279. MoveTo(hDC,x1+1,y0-2);
  280. LineTo(hDC,x1+1,y1+2);
  281. MoveTo(hDC,x0-1,y1+2);
  282. LineTo(hDC,x1+1,y1+2);
  283. SelectObject(hDC,GetStockObject(GRAY_BRUSH));
  284. TextOut(hDC,x0,y0,temp,strlen(temp));
  285. SelectObject(hDC,GetStockObject(WHITE_PEN));
  286. DeleteObject(hPen);
  287. ReleaseDC(ghWndCaption, hDC);
  288. return (x0);
  289. }
  290. extern ZQSXX Qsxx;
  291. void DispQsName(int JyQs,int color)
  292. {
  293. char temp[20];
  294. HDC hdc;
  295. HPEN hpen;
  296.     DWORD dw;
  297. RECT rc;
  298. int x0,x1,y0,y1;
  299. memset(temp,' ',18);
  300. if(JyQs!=0&&Qsxx.zqsjc[JyQs-1][0]!=0) 
  301. strcpy(temp,Qsxx.zqsjc[JyQs-1]);
  302. hdc =GetDC(ghWndCaption);
  303. GetClientRect(ghWndCaption, &rc);
  304. dw =GetTextExtent(hdc,temp,strlen(temp));
  305. y0=(rc.bottom-HIWORD(dw))/2;
  306. y1=rc.bottom-y0;
  307. x0=TIMER_X_COOR;
  308. x1=SCROLL_X_COOR-4;
  309. hpen=CreatePen(PS_SOLID,1,RGB(65,65,65));
  310. SelectObject(hdc,hpen);
  311. MoveTo(hdc,x0-1,y0-2); //竖线
  312. LineTo(hdc,x0-1,y1+2);      
  313. MoveTo(hdc,x0-1,y0-2);
  314. LineTo(hdc,x1+1,y0-2);
  315. SelectObject(hdc,GetStockObject(WHITE_PEN));
  316. MoveTo(hdc,x1+1,y0-2);
  317. LineTo(hdc,x1+1,y1+2);
  318. MoveTo(hdc,x0-1,y1+2);
  319. LineTo(hdc,x1+1,y1+2);
  320.                                              
  321.     if(color ==0)
  322. SetTextColor(hdc,RGB(0,255,0));
  323. if(color ==1)
  324. SetTextColor(hdc,RGB(255,255,0));
  325. SetRect(&rc,x0, y0, x1,y1);
  326. if(JyQs !=0)
  327. {
  328. SetBkColor(hdc,RGB(200,200,200));
  329. ExtTextOut(hdc,x0+1,y0,ETO_CLIPPED,&rc,temp,strlen(temp),(LPINT) NULL);
  330. }
  331. else
  332. FillRect(hdc,&rc,GetStockObject(LTGRAY_BRUSH));
  333. DeleteObject(hpen);
  334. ReleaseDC(ghWndCaption, hdc);
  335.  
  336. }