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

金融证券系统

开发平台:

Visual C++

  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include "resource.h"
  5. #include "global.h"
  6. #include "hq.h"
  7. #include "hq_cl.h"
  8. #include "maxmin.h"
  9. #include "toolbar.h"
  10. #include "appmain.h"
  11. #define MAXMIN_CLASS "CMAXMIN"
  12. extern HINSTANCE ghInstance;
  13. extern HWND ghWndMain, ghWndMaxMin;
  14. extern BOOL ErrMsg(HWND, LPSTR);
  15. extern BOOL IsZsRec(int jys, int rec_num);
  16. BOOL RegisterMaxMin(void)
  17. {
  18. WNDCLASS wc;
  19. memset(&wc, 0, sizeof(wc));
  20. wc.lpfnWndProc =MaxMinWndProc;
  21. wc.lpszClassName =MAXMIN_CLASS;
  22. wc.hbrBackground =GetStockObject(BLACK_BRUSH);
  23. wc.hInstance = ghInstance;
  24. wc.hCursor = LoadCursor(NULL, IDC_ARROW);        
  25. if(!RegisterClass(&wc)) return FALSE;
  26. return TRUE;
  27. }
  28. BOOL CreateWndMaxMin(HWND hWnd)
  29. {                          
  30. int x, y;
  31. HWND hwnd;
  32. int x0,y0,x1,y1;
  33. HDC hDC;
  34. TEXTMETRIC tm;
  35. RECT rc,rc1;
  36. x =GetSystemMetrics(SM_CXSCREEN);
  37. GetClientRect(ghWndMain,&rc);
  38. y =rc.bottom -rc.top;
  39. hDC =GetDC(hWnd);
  40. GetTextMetrics(hDC, &tm);
  41. ReleaseDC(hWnd, hDC);
  42. GetWindowRect(ghWndXlt,&rc1);
  43.     x0 =rc1.right;
  44.     y0 =tm.tmHeight*14+STATUS_HEIGHT +TOOLBAR_HEIGHT+2;
  45.     x1 =x*1/3-30-1;
  46.     
  47.     y1 =rc.bottom -STATUS_HEIGHT-y0-MSG_HEIGHT;
  48.     
  49.     if(y1 <tm.tmHeight*2) y1 =tm.tmHeight*2;
  50.     
  51. if(ghWndMaxMin==NULL)
  52. {
  53. hwnd =CreateWindow(MAXMIN_CLASS, NULL, WS_CHILD|WS_CLIPSIBLINGS,
  54. x0, y0, x1, y1,
  55. hWnd, NULL, ghInstance, NULL);
  56. if(hwnd ==NULL)
  57. {
  58. ErrMsg(hWnd, "Error create maxmin window");
  59. return FALSE;
  60. }
  61. ghWndMaxMin =hwnd;
  62. }
  63. else
  64. {
  65. SetWindowPos(ghWndMaxMin, (HWND) NULL,x0, y0, x1, y1,NULL);
  66. }
  67. return TRUE;
  68. }
  69. LPSTR MaxMinCaptions[]=
  70. {
  71. "涨幅最高","涨跌最高","总手最高","金额最高",
  72. "涨幅最低","涨跌最低","总手最低","金额最低"
  73. };
  74. LPSTR MaxMinTitles[]=
  75. {
  76. "名称", "最近", "涨幅", "总手", NULL
  77. };
  78. extern HFONT ghFontSmall;
  79. LRESULT CALLBACK MaxMinWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  80. {
  81. char tmp[256];
  82. PAINTSTRUCT ps;
  83. DWORD dw;
  84. int i, x, y;
  85. RECT rc;
  86. HPEN hPen;
  87. static int maxmin =0;
  88. static int maxmin_num =0;
  89. TEXTMETRIC tm;
  90. switch(message)
  91. {
  92. case WM_SETFOCUS:
  93. SetFocus(ghWndMain);
  94. break;
  95. case WM_CREATE:
  96. break;
  97. case WM_READ_OK:
  98. InvalidateRect(hWnd, NULL, TRUE);
  99. break;
  100. case WM_SIZE:
  101. if(IsWindowVisible(hWnd))
  102. InvalidateRect(hWnd, NULL, TRUE);
  103. break;
  104. case WM_KEYDOWN:
  105. switch(wParam)
  106. {
  107. case VK_UP:
  108. maxmin_num--;
  109. if(maxmin_num <0)
  110. {
  111. maxmin =(maxmin+1)%2;
  112. maxmin_num =3;
  113. }
  114. break;
  115. case VK_DOWN:
  116. maxmin_num++;
  117. if(maxmin_num >3)
  118. {
  119. maxmin =(maxmin+1)%2;
  120. maxmin_num =0;
  121. }
  122. break;
  123. default:
  124. return 0L;
  125. }
  126. InvalidateRect(hWnd, NULL, TRUE);
  127. break;
  128. case WM_PAINT:
  129. BeginPaint(hWnd, &ps);
  130. GetClientRect(hWnd, &rc);
  131. GetTextMetrics(ps.hdc, &tm);
  132. hPen =CreatePen(PS_SOLID, 2, RGB(180, 180, 180));
  133. SelectObject(ps.hdc, hPen);
  134. SelectObject(ps.hdc, GetStockObject(NULL_BRUSH));
  135. Rectangle(ps.hdc, 2, 2, rc.right-2, rc.bottom-1);
  136. SelectObject(ps.hdc, GetStockObject(WHITE_PEN));
  137. DeleteObject(hPen);
  138. MoveTo(ps.hdc, rc.right, 0);
  139. LineTo(ps.hdc, 0, 0);
  140. LineTo(ps.hdc, 0, rc.bottom);
  141. hPen =CreatePen(PS_SOLID, 2, RGB(80, 80, 80));
  142. SelectObject(ps.hdc, hPen);
  143. LineTo(ps.hdc, rc.right-1, rc.bottom-1);
  144. LineTo(ps.hdc, rc.right-1, 0);
  145. SelectObject(ps.hdc, GetStockObject(WHITE_PEN));
  146. DeleteObject(hPen);
  147. strcpy(tmp, MaxMinCaptions[maxmin*4+maxmin_num]);
  148. dw =GetTextExtent(ps.hdc, tmp, strlen(tmp));
  149. x =LOWORD(dw)/strlen(tmp); y =HIWORD(dw);
  150. SetTextColor(ps.hdc, RGB(0, 255, 255));
  151. SetBkMode(ps.hdc, TRANSPARENT);
  152. SetTextAlign(ps.hdc, TA_CENTER|TA_TOP);
  153. TextOut(ps.hdc, rc.right/2, 3, tmp, strlen(tmp));
  154. SetTextColor(ps.hdc, RGB(255, 255, 255));
  155. SetTextAlign(ps.hdc, TA_LEFT|TA_TOP);
  156. TextOut(ps.hdc, 5+x, y+2, MaxMinTitles[0], strlen(MaxMinTitles[0]));
  157. TextOut(ps.hdc, 5+x*6+5, y+2,
  158. MaxMinTitles[1], strlen(MaxMinTitles[1]));
  159. TextOut(ps.hdc, 5+x*12, y+2,
  160. MaxMinTitles[2], strlen(MaxMinTitles[2]));
  161. SetTextAlign(ps.hdc, TA_RIGHT|TA_TOP);
  162. TextOut(ps.hdc, rc.right-5, y+2,
  163. MaxMinTitles[3], strlen(MaxMinTitles[3]));
  164. if(maxmin >=0)
  165. {
  166. SelectObject(ps.hdc, ghFontSmall);
  167. for(i =0; i<10; i++)
  168. {                 
  169.     if(MaxMinData[GraphData.jys][maxmin].MaxMin[maxmin_num][i].zjjg==0)
  170.      break;
  171. SetTextColor(ps.hdc, RGB(255, 0, 255));
  172. SetTextAlign(ps.hdc, TA_LEFT|TA_TOP);
  173. if(2+(y+1)*(i+2) +tm.tmHeight >rc.bottom)
  174. break;
  175. TextOut(ps.hdc, 5, 2+(y+1)*(i+2), HqData[GraphData.jys].lpPreData[
  176. MaxMinData[GraphData.jys][maxmin].recNum[maxmin_num][i]].zqmc,
  177. strlen(HqData[GraphData.jys].lpPreData[
  178. MaxMinData[GraphData.jys][maxmin].recNum[maxmin_num][i]].zqmc));
  179. SetTextColor(ps.hdc, RGB(255, 255, 0));
  180. sprintf(tmp, "%.2f", MaxMinData[GraphData.jys][maxmin].MaxMin[maxmin_num][i].zjjg);
  181. TextOut(ps.hdc, 5+x*6+5, 2+(y+1)*(i+2), tmp, strlen(tmp));
  182. SetTextColor(ps.hdc, RGB(0, 180, 0));
  183. sprintf(tmp, "%.2f", MaxMinData[GraphData.jys][maxmin].MaxMin[maxmin_num][i].zdf);
  184. TextOut(ps.hdc, 5+x*12, 2+(y+1)*(i+2), tmp, strlen(tmp));
  185. SetTextAlign(ps.hdc, TA_RIGHT|TA_TOP);
  186. SetTextColor(ps.hdc, RGB(0, 180, 180));
  187. sprintf(tmp, "%ld", MaxMinData[GraphData.jys][maxmin].MaxMin[maxmin_num][i].cjss);
  188. TextOut(ps.hdc, rc.right-5, 2+(y+1)*(i+2), tmp, strlen(tmp));
  189. }
  190. }
  191. EndPaint(hWnd, &ps);
  192. break;
  193. case WM_DESTROY:
  194. break;
  195. }
  196. return DefWindowProc(hWnd, message, wParam, lParam);
  197. }