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

金融证券系统

开发平台:

Visual C++

  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <time.h>
  5. #include "resource.h"
  6. #include "global.h"           
  7. #include "hq.h"
  8. #include "hq_cl.h"
  9. #include "xlt.h"
  10. #include "fx.h"
  11. #include "jy_cl.h"
  12. #include "appmain.h"
  13. #include "toolbar.h"
  14. #define XLT_CLASS "CXLT"
  15. extern int LoadFile(char *filename,int sline,char *title);
  16. extern HINSTANCE ghInstance;
  17. extern HWND ghWndMain, ghWndXlt, ghWndCj, ghWndMaxMin, ghWndLitHq, ghWndZs, ghWndHelp,ghWndToolBar;
  18. extern HMENU ghMenuGraph;
  19. extern char szDataPath[128];
  20. extern BOOL ErrMsg(HWND, LPSTR);
  21. extern int DrawXlt(HDC, LPRECT);
  22. extern LPFX Fx;
  23. extern int FxInit(LPFX Fx);
  24. extern int UDP_Send_DataDay(int jys,int rec_num);
  25. extern int UDP_Send_Stock_Info(STOCK_INFO_FRAME *StockInfoFrame);
  26. extern int DlgJy(void);
  27. extern JY_ANS_CHKUSR curChkUsrRes;
  28. extern int gfOnLine ,gfConnecting ,gfDelete;
  29. BOOL RegisterXlt(void)
  30. {
  31. WNDCLASS wc;
  32. memset(&wc, 0, sizeof(wc));
  33. wc.lpfnWndProc =XltWndProc;
  34. wc.lpszClassName =XLT_CLASS;
  35. wc.hbrBackground =GetStockObject(BLACK_BRUSH);
  36. wc.hInstance = ghInstance;
  37. wc.hCursor = LoadCursor(NULL, IDC_ARROW);        
  38. if(!RegisterClass(&wc)) return FALSE;
  39. return TRUE;
  40. }
  41. extern  int CapHig;
  42. BOOL CreateWndXlt(HWND hWnd)
  43. {                          
  44. int x, y;
  45. HWND hwnd;
  46. RECT rc;
  47.            
  48.     GetClientRect(ghWndMain, &rc);
  49. x =rc.right -rc.left;
  50. y =rc.bottom -rc.top;
  51. if(ghWndXlt ==NULL)
  52. {
  53. hwnd =CreateWindow(XLT_CLASS, NULL, WS_CHILD|WS_CLIPSIBLINGS,
  54. 0, 
  55. STATUS_HEIGHT+TOOLBAR_HEIGHT, 
  56. x*2/3+30, 
  57. (y-STATUS_HEIGHT*2- TOOLBAR_HEIGHT -20)*3/5,
  58. hWnd, NULL, ghInstance, NULL);
  59. if(hwnd ==NULL)
  60. {
  61. ErrMsg(hWnd, "不能建立分时价图");
  62. return FALSE;
  63. }
  64. ghWndXlt =hwnd;
  65. }
  66. else
  67. {   
  68. SetWindowPos(ghWndXlt, (HWND) NULL, 
  69. 0, 
  70. STATUS_HEIGHT+TOOLBAR_HEIGHT, 
  71. x*2/3+30, 
  72. (y-STATUS_HEIGHT*2-TOOLBAR_HEIGHT -20)*3/5 ,
  73. NULL);
  74. }
  75. return TRUE;
  76. }
  77. extern int DrawTimeLines(HWND hWnd,HDC hDC, LPRECT rc, BOOL);
  78. extern int DrawVLine(int);
  79. extern BOOL fVLineDrawed;                         
  80. extern HMENU ghMenuHq;
  81. extern HWND hWndInput;
  82. extern BOOL IsZsRec(int, int);
  83. extern int UDP_Send_Gra00(int jys, int rec_num);
  84. int graphTop =0;
  85. LRESULT CALLBACK XltWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  86. {
  87. char tmp[256],temp[256];
  88. PAINTSTRUCT ps;
  89. DWORD dw;
  90. int i, j, x, y;
  91. RECT rc;
  92. static int total_times =0,reload=0;
  93. static clock_t MouDownClk;
  94. STOCK_INFO_FRAME StockInfo;
  95. switch(message)
  96. {
  97. case WM_CREATE:
  98. MouDownClk=clock();
  99. break;
  100. case WM_SETFOCUS:
  101. if(fVLineDrawed)
  102. {
  103. DrawVLine(0);
  104. fVLineDrawed =FALSE;
  105. }
  106. SetFocus(ghWndMain);
  107. break;
  108. case WM_KILLFOCUS:
  109. if(fVLineDrawed)
  110. {
  111. DrawVLine(0);
  112. fVLineDrawed =FALSE;
  113. }
  114. break;
  115. case WM_LBUTTONDOWN:
  116. if(clock()-MouDownClk<240)
  117. PostMessage(hWnd,WM_KEYDOWN,VK_RETURN,0L);
  118. MouDownClk=clock();
  119. break;
  120. case WM_RBUTTONDOWN:
  121. SendMessage(hWnd, WM_KEYDOWN, VK_ESCAPE, 0L);
  122. break;         
  123. case WM_SIZE:
  124. if(IsWindowVisible(hWnd))
  125. InvalidateRect(hWnd, NULL, TRUE);
  126. break;
  127. case WM_COMMAND:
  128. SendMessage(ghWndMain, WM_COMMAND, wParam, lParam);
  129. break;
  130. case WM_TIMER:
  131. if(wParam==1)
  132. {
  133. KillTimer(hWnd,1);
  134. if(IsWindowVisible(hWnd))
  135.      sprintf(StockInfo.name,"%s",HqData[GraphData.jys].lpPreData[GraphData.recNum].zqdm);
  136.     else if(IsWindowVisible(ghWndFx))
  137.      sprintf(StockInfo.name,"%s",Fx->gpdm);     
  138.     else
  139.     {
  140. i =HqPaintData.sortData.key[HqPaintData.curSelRec+HqPaintData.curRecNum];
  141. sprintf(StockInfo.name,"%s",HqData[HqPaintData.jys].lpPreData[i].zqdm);
  142.     }
  143.     sprintf(tmp,"%s\%s.txt",szDataPath,StockInfo.name);
  144. if((i=LoadFile(tmp,0,""))==0)
  145. {
  146. reload++;
  147. if(reload>20)
  148. {
  149. // ErrMsg(NULL,"该股无信息");
  150. reload=0;
  151. }
  152. //else
  153. // SetTimer(hWnd,1,1000,NULL);
  154. }
  155. }
  156. break;
  157. case WM_PAINT:
  158. BeginPaint(hWnd, &ps);
  159. GetClientRect(hWnd, &rc);
  160. SetTextColor(ps.hdc, RGB(255, 0, 255));
  161. SetBkColor(ps.hdc, RGB(0, 0, 0));
  162. strcpy(tmp, HqData[GraphData.jys].lpPreData[GraphData.recNum].zqmc);
  163. TextOut(ps.hdc, 2, 2, tmp, strlen(tmp));
  164. //SelectObject(ps.hdc,GetStockObject(ANSI_FIXED_FONT));
  165. dw =GetTextExtent(ps.hdc, tmp, strlen(tmp));
  166. x =LOWORD(dw); y =HIWORD(dw);
  167. SetTextColor(ps.hdc, RGB(255, 255, 0));
  168. if((int)(GraphData.GraHead.dateNum/100)!=0)
  169. {
  170. wsprintf(tmp, "%2d月%2d日", GraphData.GraHead.dateNum/100,
  171. GraphData.GraHead.dateNum%100);
  172. TextOut(ps.hdc, x+1, 2, tmp, strlen(tmp));
  173. }
  174. SelectObject(ps.hdc, GetStockObject(WHITE_PEN));
  175. rc.left =50; 
  176. rc.right -=30;
  177. rc.top =y+10;
  178. graphTop =rc.top;
  179. DrawTimeLines(hWnd,ps.hdc, &rc, FALSE);
  180. rc.bottom --;
  181. DrawXlt(ps.hdc, &rc);
  182. EndPaint(hWnd, &ps);
  183. break;
  184. case WM_READ_OK:
  185. if(fVLineDrawed)
  186. {
  187. DrawVLine(0);
  188. fVLineDrawed =FALSE;
  189. }
  190. if(wParam)
  191. InvalidateRect(hWnd, NULL, TRUE);
  192. else InvalidateRect(hWnd, NULL, FALSE);
  193. break;
  194.         
  195. case WM_KEYDOWN:
  196. switch(wParam)
  197. {   
  198.     case VK_F1:
  199.      ShowWindow(ghWndHelp,SW_SHOW);
  200. sprintf(tmp,"%s\help.txt",szDataPath);     
  201.      LoadFile(tmp,0,"帮助/[ESC]退出");
  202.     break;
  203.     case VK_F2:
  204.             SendMessage(ghWndMain,WM_COMMAND,IDM_JY,NULL);     
  205. break;
  206.     case VK_F3:
  207.      StockInfo.type=FILE_STOCK_INFO;     
  208. if(IsWindowVisible(hWnd))
  209.      sprintf(StockInfo.name,"%s",HqData[GraphData.jys].lpPreData[GraphData.recNum].zqdm);
  210.      else if(IsWindowVisible(ghWndFx))
  211.      sprintf(StockInfo.name,"%s",Fx->gpdm);
  212.      else
  213.      {
  214. i =HqPaintData.sortData.key[HqPaintData.curSelRec+HqPaintData.curRecNum];
  215. sprintf(StockInfo.name,"%s",HqData[HqPaintData.jys].lpPreData[i].zqdm);
  216.      }
  217.     
  218.      sprintf(tmp,"%s\%s.txt",szDataPath,StockInfo.name);
  219.      if(gfOnLine) unlink(tmp);
  220.     
  221.      UDP_Send_Stock_Info(&StockInfo);
  222.     
  223. ShowWindow(ghWndHelp,SW_SHOW);
  224. sprintf(temp,"个股信息%s/[ESC]退出",StockInfo.name);
  225. if((i=LoadFile(tmp,0,temp))==0)
  226. {       
  227. reload=0;
  228. SetTimer(hWnd,1,1000,NULL);
  229. }
  230.     break;
  231. case VK_F12:
  232.     StockInfo.type=FILE_LIST_DIR;
  233.     strcpy(StockInfo.name,"");
  234.      sprintf(tmp,"%s\%s",szDataPath,"news.idx");
  235.      if(gfOnLine) unlink(tmp);
  236.      UDP_Send_Stock_Info(&StockInfo);
  237.     
  238.      if(!IsWindowVisible(ghWndHelp))
  239. ShowWindow(ghWndHelp,SW_SHOW);
  240. else
  241.     SetFocus(ghWndHelp);
  242. LoadFile(tmp,0,"新闻公告/[ESC]退出");
  243. break;     
  244. case VK_PRIOR:
  245.         i =GraphData.recNum;
  246.         j =GraphData.jys;
  247.         if(i>0)
  248.         {   
  249.             i--;
  250. SetWindowText(hWndInput, HqData[j].lpPreData[i].zqdm);
  251. SendMessage(hWnd, WM_KEYDOWN, VK_RETURN, 0L);
  252. }
  253. break;
  254. case VK_NEXT:
  255.         i =GraphData.recNum;
  256.         j =GraphData.jys;
  257.         if(i <HqData[j].recCount-1)
  258.         {
  259.          i++;
  260. SetWindowText(hWndInput, HqData[j].lpPreData[i].zqdm);
  261. SendMessage(hWnd, WM_KEYDOWN, VK_RETURN, 0L);
  262. }
  263. break;
  264. case VK_RETURN:
  265. if(HqData[GraphData.jys].recCount <=0) break;
  266. if(fVLineDrawed)
  267. SendMessage(hWnd, WM_KILLFOCUS, 0, 0L);
  268. strcpy(tmp,"");
  269. GetWindowText(hWndInput, &tmp[0], sizeof(tmp));
  270. /*
  271. 分时图回车进入历史分析图
  272. */
  273. if(tmp[0] ==0)
  274. {
  275. ShowWindow(hWnd, SW_HIDE);
  276. ShowWindow(ghWndJlt, SW_HIDE);
  277. ShowWindow(ghWndZs, SW_HIDE);
  278. ShowWindow(ghWndMmp, SW_HIDE);
  279. ShowWindow(ghWndCj, SW_HIDE);
  280. ShowWindow(ghWndMaxMin, SW_HIDE);
  281. ShowWindow(ghWndLitHq, SW_HIDE);
  282.                         strcpy(Fx->gpdm, HqData[GraphData.jys].lpPreData[GraphData.recNum].zqdm);
  283.                         strcpy(Fx->gpmc, HqData[GraphData.jys].lpPreData[GraphData.recNum].zqmc);
  284.                         for(i=IDM_FX_MACD;i<=IDM_FX_KDJ;i++)
  285.                         {
  286.                              if(GetMenuState(ghMenuMain, i, MF_BYCOMMAND)&MF_CHECKED)
  287.                               break;
  288.                         }
  289.                         if(i<=IDM_FX_KDJ)
  290.                          Fx->type = i;
  291.                         else
  292.                         {
  293.                          if(Fx->type==0)
  294.                              Fx->type=IDM_FX_MACD;
  295.                         }
  296.                         UDP_Send_DataDay(GraphData.jys,GraphData.recNum);
  297.                         ShowWindow(ghWndFx,SW_SHOW);
  298.                         InvalidateRect(ghWndFx, NULL, TRUE);
  299.                         SetFocus(ghWndFx);
  300.                     }
  301. else
  302. {
  303. for(j =0; j<2; j++)
  304. {
  305. for(i =0; i<HqData[j].recCount; i++)
  306. {
  307. if(!strcmp(HqData[j].lpPreData[i].zqdm, tmp))
  308. break;
  309. }
  310. if(i <HqData[j].recCount) break;
  311. }
  312. if(j<2 && i <HqData[j].recCount)
  313. {
  314. GraphData.minEnd =0;
  315. GraphData.jys =j;
  316. GraphData.recNum =i;
  317. MmpData.jys =j;
  318. MmpData.recNum =i;
  319. if(fVLineDrawed)
  320. {
  321. DrawVLine(0);
  322. fVLineDrawed =FALSE;
  323. }
  324. UDP_Send_Gra00(j, i);
  325. InvalidateRect(hWnd, NULL, TRUE);
  326. InvalidateRect(ghWndJlt, NULL, TRUE);
  327. InvalidateRect(ghWndLitHq, NULL, TRUE);
  328. InvalidateRect(ghWndMmp, NULL, TRUE);
  329. if(IsZsRec(j, i))
  330. {
  331. if(!IsWindowVisible(ghWndZs))
  332. {
  333. ShowWindow(ghWndZs, SW_SHOW);
  334. ShowWindow(ghWndMmp, SW_HIDE);
  335. ShowWindow(ghWndCj, SW_HIDE);
  336. ShowWindow(ghWndMaxMin, SW_SHOW);
  337. }
  338. }
  339. else
  340. {
  341. if(IsWindowVisible(ghWndZs))
  342. {
  343. ShowWindow(ghWndZs, SW_HIDE);
  344. ShowWindow(ghWndMmp, SW_SHOW);
  345. ShowWindow(ghWndCj, SW_SHOW);
  346. ShowWindow(ghWndMaxMin, SW_HIDE);
  347. }
  348. SendMessage(ghWndCj, WM_READ_OK, 0, 0L);
  349. }
  350. }
  351. SetWindowText(hWndInput, "");
  352. }
  353. break;
  354. case VK_F6:
  355. case VK_ESCAPE:
  356. if(fVLineDrawed)
  357. {
  358. SendMessage(hWnd, WM_KILLFOCUS, 0, 0L);
  359. break;
  360. }
  361. ShowWindow(hWnd, SW_HIDE);
  362. ShowWindow(ghWndJlt, SW_HIDE);
  363. ShowWindow(ghWndCj, SW_HIDE);
  364. ShowWindow(ghWndMaxMin, SW_HIDE);
  365. ShowWindow(ghWndLitHq, SW_HIDE);
  366. ShowWindow(ghWndZs, SW_HIDE);
  367. ShowWindow(ghWndMmp, SW_HIDE);
  368. ShowWindow(ghWndHq, SW_SHOW);
  369. KillTimer(ghWndHq, 5);
  370. SetTimer(ghWndHq, 5, 1000, NULL);
  371. break;
  372. case VK_LEFT:
  373. DrawVLine(-1);
  374. break;
  375. case VK_RIGHT:
  376. DrawVLine(1);
  377. break;
  378. case VK_UP:
  379. case VK_DOWN:
  380. if(IsZsRec(GraphData.jys, GraphData.recNum))
  381. {
  382. SendMessage(ghWndZs, WM_KEYDOWN, wParam, lParam);
  383. SendMessage(ghWndMaxMin, WM_KEYDOWN, wParam, lParam);
  384. }
  385. else
  386. if(IsWindowVisible(ghWndCj))
  387. {
  388. SendMessage(ghWndCj, WM_KEYDOWN, wParam, lParam);
  389. }
  390. }
  391. break;
  392. case WM_DESTROY:
  393. break;
  394. default:
  395. break;
  396. }
  397. return DefWindowProc(hWnd, message, wParam, lParam);
  398. }