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

金融证券系统

开发平台:

Visual C++

  1. #include <windows.h>
  2. #include <windowsx.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. #include <malloc.h>
  7. #include <direct.h>
  8. #include <io.h>
  9. #include <time.h>
  10. #include "resource.h"
  11. #include "global.h"
  12. #include "appmain.h"
  13. #include "hq.h"
  14. #include "hq_cl.h"
  15. #include "hq_tcp.h"
  16. #include "jy_cl.h"
  17. #include "msg.h"
  18. #include "pctcp.h"
  19. #include "caption.h"
  20. #include "rsa.h"
  21. #define HQ_CLASS                "CHQ"
  22. HQ_DATA HqData[2];
  23. HQ_PAINT_DATA HqPaintData;
  24. HQSEL_DATA HqSelData[MAX_HQSEL_COUNT];
  25. DP_DATA DpData[2];
  26. HQ_TIME  HqTime[2];
  27. GRAPH_DATA GraphData;
  28. MMP_DATA MmpData;
  29. MAXMIN_DATA     MaxMinData[2][2];
  30. ZX_DATA ZxData;
  31. int SeleQs=0;
  32. HFONT ghFontSmall =NULL;
  33. HFONT hHqFont =NULL;
  34. char szDataPath[128];
  35. extern int LoadFile(char *filename,int sline,char *title);
  36. extern BOOL ErrMsg(HWND, LPSTR);
  37. extern BOOL run_cancelled;
  38. extern JY_ANS_CHKUSR curChkUsrRes;
  39. extern BOOL jy_running;
  40. extern int TOOLBAR_HEIGHT;
  41. extern void SendJyQsxx(void);
  42. int DrawTitle(HWND hWnd, HDC hDC);
  43. void DrawSelRect(HWND hWnd, HDC hDC, int sel_num, int bClr);
  44. LPSTR GetHqFldPos(HDC, int jys, int rec_num, int fld_num);
  45. LPSTR GetHqFldPos1(int jys, int rec_num, int fld_num);
  46. LRESULT CALLBACK HqWndProc(HWND, UINT, WPARAM, LPARAM);
  47. int HqSort(void);
  48. int SortFloat(LPSORT_DATA lpSortData, int jys);
  49. int SortLong(LPSORT_DATA lpSortData, int jys);
  50. BOOL IsZsRec(int jys, int recNum);
  51. HFILE hfZx =HFILE_ERROR;
  52. extern HBITMAP hBmpUp, hBmpDown, hBmpEqual;
  53. extern int UDP_Send_Hq10(int, int, int, int);
  54. LPSTR HqTimeDefs[] ={"9:30", "11:30", "13:00", "15:00",
  55. "9:30", "11:30", "13:00", "15:00",
  56. };
  57. int *lpHqTimes[] ={&HqTime[0].am_min_start, &HqTime[0].am_min_count,
  58. &HqTime[0].pm_min_start, &HqTime[0].pm_min_count,
  59. &HqTime[1].am_min_start, &HqTime[1].am_min_count,
  60. &HqTime[1].pm_min_start, &HqTime[1].pm_min_count
  61. };
  62. float  HqZd;
  63. extern BOOL IsSzRead,IsShRead;
  64. BOOL RegisterHq(void)
  65. {
  66. WNDCLASS wc;
  67. BYTE bytes[20];
  68. float f =(float)0.1;
  69. memset(bytes, 0, sizeof(bytes));
  70. memcpy(bytes, &f, sizeof(float));
  71. memset(&wc, 0, sizeof(wc));
  72. wc.style =CS_HREDRAW | CS_VREDRAW;
  73. wc.cbWndExtra =sizeof(WORD);
  74. wc.lpfnWndProc =HqWndProc;
  75. wc.lpszClassName =HQ_CLASS;
  76. wc.hbrBackground =GetStockObject(BLACK_BRUSH);
  77. wc.hInstance = ghInstance;
  78. wc.lpszMenuName = NULL;
  79. wc.hCursor = LoadCursor(NULL, IDC_ARROW);        
  80. wc.hIcon = LoadIcon(ghInstance, MAKEINTRESOURCE(IDR_MAINFRAME));
  81. if(!RegisterClass(&wc)) return FALSE;
  82. return TRUE;
  83. }
  84. BOOL CreateWndHq(HWND hWnd)
  85. {                          
  86. HWND hwnd;
  87. RECT rc;
  88. GetClientRect(ghWndMain, &rc);
  89.     if(ghWndHq==NULL)
  90.     {
  91. hwnd =CreateWindow(HQ_CLASS, HQ_CLASS, WS_CHILD|WS_CLIPSIBLINGS,// |WS_VSCROLL|WS_HSCROLL,
  92. 0, 
  93. STATUS_HEIGHT +TOOLBAR_HEIGHT ,
  94. rc.right -rc.left, 
  95. rc.bottom -rc.top -TOOLBAR_HEIGHT-STATUS_HEIGHT*2-MSG_HEIGHT,
  96. hWnd, IDW_HQ, ghInstance, NULL);
  97. if(hwnd ==NULL)
  98. {
  99. ErrMsg(hWnd, "Error create hq window");
  100. return FALSE;
  101. }
  102. ghWndHq =hwnd;
  103. SendMessage(hwnd, WM_COMMAND, IDM_HQ_SZ, 0L);
  104. ShowWindow(hwnd, SW_SHOW);
  105. }
  106. else
  107. {
  108. SetWindowPos(ghWndHq, (HWND)NULL,
  109.     0,
  110.     0,
  111. rc.right -rc.left,
  112. rc.bottom -rc.top -TOOLBAR_HEIGHT-STATUS_HEIGHT*2-MSG_HEIGHT,
  113. SWP_NOMOVE);
  114. PostMessage(ghWndHq,WM_USER+1,NULL,NULL);
  115. }
  116. return TRUE;
  117. }
  118. BOOL HqInit(void)
  119. {
  120. int i, jys;
  121. LOGFONT SmallLf;
  122. char temp[128];
  123. OFSTRUCT os;
  124. HANDLE hf;
  125. memset(&HqData, 0, sizeof(HqData));
  126. memset(&HqSelData, 0, sizeof(HqSelData));
  127. memset(&HqTime, 0, sizeof(HqTime));
  128. HqTime[0].fRunning =HqTime[1].fRunning =TRUE;
  129. memset(&HqPaintData, 0, sizeof(HqPaintData));
  130. memset(&MmpData, 0, sizeof(MmpData));
  131. memset(&GraphData, 0, sizeof(GraphData));
  132. memset(&ZxData, 0, sizeof(ZxData));
  133. memset(&lf, 0, sizeof(lf));
  134. if(!GetInitString("HQ", "DATAPATH", szDataPath))
  135. {
  136. strcpy(szDataPath, ".\data");
  137. }
  138. else
  139. {
  140. i =strlen(szDataPath);
  141. if(szDataPath[i-1] =='\') szDataPath[i-1] =0;
  142. }
  143. if(_access(szDataPath, 0) !=0 && _mkdir(szDataPath) !=0)
  144. strcpy(szDataPath, ".");
  145. PutInitString("HQ", "DATAPATH", szDataPath);
  146. if(!GetInitString("HQ", "ITEM_SPACE_X", temp))
  147.     ITEM_SPACE_X =0;
  148. else
  149. ITEM_SPACE_X =atoi(temp);
  150. if(!GetInitString("HQ", "X0_TITLE", temp))
  151.     X0_TITLE =0;
  152. else
  153. X0_TITLE =atoi(temp);
  154. strcpy(temp, szDataPath);
  155. strcat(temp, "\zx.txt");
  156. if(access(temp,0)!=0)
  157. hfZx =OpenFile(temp, &os, OF_SHARE_DENY_NONE|OF_CREATE|OF_READWRITE);
  158. else
  159.     hfZx =OpenFile(temp, &os, OF_SHARE_DENY_NONE|OF_READWRITE);     
  160. if(hfZx ==HFILE_ERROR)
  161. {
  162. strcat(temp, ": Create failed!");
  163. ErrMsg(NULL, temp);
  164. }
  165. _lclose(hfZx);
  166. memset(&lf, 0, sizeof(LOGFONT));
  167. strcpy(temp, "font.dat");
  168. if(access(temp,0)==0)
  169. {
  170.     hf =OpenFile(temp, &os, OF_SHARE_DENY_NONE|OF_READ);     
  171. if(hfZx ==HFILE_ERROR)
  172. unlink(temp);
  173. else
  174. {
  175. if(_lread(hf,&lf,sizeof(LOGFONT))!=sizeof(LOGFONT))
  176. {
  177. _lclose(hfZx);
  178. memset(&lf, 0, sizeof(LOGFONT));
  179. unlink(temp);
  180. }
  181. else
  182. _lclose(hfZx);
  183. }
  184. }
  185. memset(&SmallLf, 0, sizeof(LOGFONT));
  186. SmallLf.lfHeight =-12;
  187. SmallLf.lfWeight =FW_NORMAL;               
  188. strcpy(SmallLf.lfFaceName, "宋体");
  189. ghFontSmall =CreateFontIndirect(&SmallLf);
  190. //由HqTimeDefs数据生成HqTimes数据
  191. for(jys =0; jys <2; jys++)
  192. {
  193. for(i =0; i<4; i++)
  194. {
  195. strcpy(temp, HqTimeDefs[i+4*jys]);
  196. *lpHqTimes[i+4*jys] =atoi(strtok(temp, ":"))*60;
  197. *lpHqTimes[i+4*jys] +=atoi(strtok(NULL, ":"));
  198. }
  199. HqTime[jys].am_min_count -=HqTime[jys].am_min_start;
  200. HqTime[jys].pm_min_count -=HqTime[jys].pm_min_start;
  201. }
  202. if(GetInitString("TIME", "SZ_AM_START",temp))
  203. HqTime[0].am_min_start =atoi(temp);
  204. if(GetInitString("TIME", "SZ_AM_COUNT",temp))
  205. HqTime[0].am_min_count =atoi(temp);
  206. if(GetInitString("TIME", "SZ_PM_START",temp))
  207. HqTime[0].pm_min_start =atoi(temp);
  208. if(GetInitString("TIME", "SZ_PM_COUNT",temp))
  209. HqTime[0].pm_min_count =atoi(temp);
  210. if(GetInitString("TIME", "SH_AM_START",temp))
  211. HqTime[1].am_min_start =atoi(temp);
  212. if(GetInitString("TIME", "SH_AM_COUNT",temp))
  213. HqTime[1].am_min_count =atoi(temp);
  214. if(GetInitString("TIME", "SH_PM_START",temp))
  215. HqTime[1].pm_min_start =atoi(temp);
  216. if(GetInitString("TIME", "SH_PM_COUNT",temp))
  217. HqTime[1].pm_min_count =atoi(temp);
  218. return TRUE;
  219. }
  220. void HqExit(void)
  221. {
  222. static BOOL fExit =FALSE;
  223. int jys;
  224. char temp[80];
  225. OFSTRUCT os;
  226. HANDLE hf;
  227. if(fExit ==TRUE) return;
  228. fExit =TRUE;
  229. for(jys =0; jys <2; jys++)
  230. {
  231. if(HqData[jys].lpPreData !=NULL)
  232. GlobalFreePtr(HqData[jys].lpPreData);
  233. if(HqData[jys].lpRefData !=NULL)
  234. GlobalFreePtr(HqData[jys].lpRefData);
  235. if(HqData[jys].isJgChanged !=NULL)
  236. GlobalFreePtr(HqData[jys].isJgChanged);
  237. if(HqData[jys].isLcChanged !=NULL)
  238. GlobalFreePtr(HqData[jys].isLcChanged);
  239. if(HqData[jys].isReadOK !=NULL)
  240. GlobalFreePtr(HqData[jys].isReadOK);
  241. }
  242. if(GraphData.lpGraData) GlobalFreePtr(GraphData.lpGraData);
  243. if(GraphData.lpMinPos) GlobalFreePtr(GraphData.lpMinPos);
  244. if(GraphData.lpMinLc) GlobalFreePtr(GraphData.lpMinLc);
  245. if(ZxData.lpText) GlobalFreePtr(ZxData.lpText);
  246. strcpy(temp,"font.dat");
  247. hf =OpenFile(temp, &os, OF_SHARE_DENY_NONE|OF_CREATE|OF_WRITE);
  248. _lwrite(hf,&lf,sizeof(LOGFONT));
  249. _lclose(hf);
  250. if(ghFontSmall) DeleteObject(ghFontSmall);
  251.     if(hHqFont!=NULL) DeleteObject(hHqFont);
  252. //if(hfZx !=HFILE_ERROR) _lclose(hfZx);
  253. sprintf(temp,"%d",HqTime[0].am_min_start);
  254. PutInitString("TIME", "SZ_AM_START",temp);
  255. sprintf(temp,"%d",HqTime[0].am_min_count);
  256. PutInitString("TIME", "SZ_AM_COUNT",temp);
  257. sprintf(temp,"%d",HqTime[0].pm_min_start);
  258. PutInitString("TIME", "SZ_PM_START",temp);
  259. sprintf(temp,"%d",HqTime[0].pm_min_count);
  260. PutInitString("TIME", "SZ_PM_COUNT",temp);
  261. sprintf(temp,"%d",HqTime[1].am_min_start);
  262. PutInitString("TIME", "SH_AM_START",temp);
  263. sprintf(temp,"%d",HqTime[1].am_min_count);
  264. PutInitString("TIME", "SH_AM_COUNT",temp);
  265. sprintf(temp,"%d",HqTime[1].pm_min_start);
  266. PutInitString("TIME", "SH_PM_START",temp);
  267. sprintf(temp,"%d",HqTime[1].pm_min_count);
  268. PutInitString("TIME", "SH_PM_COUNT",temp);
  269. }
  270. //zqdm,zrsp,jrkp,zgjg,zdjg,zgjm,zdjm,zjjg,zdf,cjss,lc,npzl, wpzl, wb, cjje ,zd
  271. int HqFldLens[HQ_FLDS_COUNT+1]=
  272. {
  273. MAX_ZQDM_SIZE+2, sizeof(float),sizeof(float), sizeof(float), sizeof(float),
  274. sizeof(float), sizeof(float),sizeof(float), sizeof(float), sizeof(long),
  275. sizeof(long), sizeof(long), sizeof(long), sizeof(float), sizeof(long),sizeof(float)
  276. };
  277. int HqPaintFldLens[HQ_FLDS_COUNT+1]=
  278. {
  279. MAX_ZQDM_SIZE+2, MAX_JG_SIZE, MAX_JG_SIZE, MAX_JG_SIZE, MAX_JG_SIZE,
  280. MAX_JG_SIZE, MAX_JG_SIZE, MAX_JG_SIZE, MAX_JG_SIZE -1, MAX_CJSS_SIZE+1,
  281. MAX_CJSS_SIZE -1, MAX_CJSS_SIZE+1, MAX_CJSS_SIZE+1, MAX_JG_SIZE-2, MAX_CJJE_SIZE,MAX_JG_SIZE+1
  282. };
  283. int HqFldTypes[HQ_FLDS_COUNT+1] =
  284. {
  285. FLD_TYPE_STRING, FLD_TYPE_FLOAT, FLD_TYPE_FLOAT, FLD_TYPE_FLOAT,
  286. FLD_TYPE_FLOAT, FLD_TYPE_FLOAT, FLD_TYPE_FLOAT, FLD_TYPE_FLOAT,
  287. FLD_TYPE_FLOAT, FLD_TYPE_LONG, FLD_TYPE_LONG, FLD_TYPE_LONG,
  288. FLD_TYPE_LONG, FLD_TYPE_FLOAT, FLD_TYPE_LONG ,FLD_TYPE_FLOAT
  289. };
  290. short *recList =NULL;
  291. int FontHight=-15;
  292. BOOL isRF=FALSE;
  293. #define R_VERT 4000
  294. #define R_HORZ 1000
  295. //unsigned short ITEM_SPACE_Y =7;
  296. //unsigned short X0_TITLE=84;
  297. //unsigned short ITEM_SPACE_X =12;
  298. unsigned short ITEM_SPACE_Y =0;
  299. unsigned short X0_TITLE=0;
  300. unsigned short ITEM_SPACE_X =0;
  301. LOGFONT lf;
  302. LRESULT CALLBACK HqWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  303. {
  304. PAINTSTRUCT ps;
  305. int i, j, m, l, n, k;
  306. RECT rc, rc1;
  307. HDC hDC;
  308. int x, y;
  309. static TEXTMETRIC tm;
  310. char tmp[100];
  311. LPSTR lpTmp;
  312. int recNum, recCount;
  313. BOOL fRefresh =FALSE, fSel =FALSE;
  314. static clock_t MouDownClk;
  315. switch(message)
  316. {
  317. case WM_CREATE:
  318. MouDownClk=clock();
  319. HqPaintData.sortData.fldID =SORT_ZQDM;
  320. HqPaintData.sortData.type =SORT_DOWN;
  321. HqPaintData.filter =HQ_ALL;
  322. HqPaintData.jys =0;
  323. SetScrollRange(hWnd,SB_VERT,0,R_VERT,TRUE);
  324. SetScrollRange(hWnd,SB_HORZ,0,R_HORZ,TRUE);
  325. if(lf.lfHeight ==0)
  326. {
  327. memset(&lf,0,sizeof(lf));
  328. lf.lfWeight =FW_NORMAL;
  329.      lf.lfHeight=FontHight;
  330. lf.lfItalic=0;
  331. lf.lfUnderline=0;    
  332. }
  333. // PostMessage(hWnd,WM_USER+1,NULL,NULL);
  334. // break;
  335. case WM_USER +1:
  336. hDC =GetDC(hWnd);
  337. if(hHqFont!=NULL)
  338. DeleteObject(hHqFont);
  339.      hHqFont =CreateFontIndirect(&lf);
  340.     
  341.      SelectObject(hDC,hHqFont);
  342. GetTextMetrics(hDC, &tm);
  343. ReleaseDC(hWnd, hDC);
  344. if(X0_TITLE ==0) X0_TITLE =tm.tmAveCharWidth *10;
  345. if(ITEM_SPACE_X ==0) ITEM_SPACE_X =10;
  346. ITEM_SPACE_Y =tm.tmHeight*15/100;
  347. // PostMessage(hWnd,WM_USER +5,0,0L);
  348. // break;
  349. case WM_USER +5:
  350. GetClientRect(hWnd, &rc);
  351. i =rc.bottom -rc.top;
  352. HqPaintData.curRecCount =i/(tm.tmHeight+ITEM_SPACE_Y);
  353. if(HqPaintData.curRecCount<=1) HqPaintData.curRecCount=2;
  354. ITEM_SPACE_Y +=(i-HqPaintData.curRecCount*(tm.tmHeight+ITEM_SPACE_Y))/HqPaintData.curRecCount;
  355. HqPaintData.itemHeight = tm.tmHeight+ITEM_SPACE_Y;
  356. if(HqPaintData.curRecCount>2)
  357. HqPaintData.curRecCount--;
  358. if(recList!=NULL)
  359. free(recList);
  360. recList =(short *)malloc(sizeof(short)*HqPaintData.curRecCount);
  361. if(recList ==NULL)
  362. {
  363. ErrMsg(hWnd, "alloc recList failed!");
  364. return -1;
  365. }
  366. x  =X0_TITLE;
  367. HqPaintData.x0 =0;
  368. HqPaintData.curFldNum=0;
  369. if(HqPaintData.fldCount <=0)
  370. {
  371. HqPaintData.fldCount =sizeof(HqFldLens)/sizeof(int);
  372. for(j =0; j<HqPaintData.fldCount; j++)
  373. HqPaintData.fldNum[j] =j;
  374. }
  375. for(j =0; j<HqPaintData.fldCount; j++)
  376. {
  377. HqPaintData.rcTitles[j].left =x;
  378. HqPaintData.rcTitles[j].right =
  379. x+(tm.tmAveCharWidth)*HqPaintFldLens[HqPaintData.fldNum[j]];
  380. x =HqPaintData.rcTitles[j].right+ITEM_SPACE_X;
  381. HqPaintData.rcTitles[j].top =0;  
  382. HqPaintData.rcTitles[j].bottom =tm.tmHeight;
  383. break;
  384. case WM_VSCROLL:
  385.     if(wParam==SB_LINEDOWN)
  386.      SendMessage(hWnd,WM_KEYDOWN,VK_DOWN,0L);
  387.     if(wParam==SB_LINEUP)
  388.      SendMessage(hWnd,WM_KEYDOWN,VK_UP,0L);
  389.     if(wParam==SB_PAGEDOWN)
  390.      SendMessage(hWnd,WM_KEYDOWN,VK_NEXT,0L);     
  391.     if(wParam==SB_PAGEUP)
  392.      SendMessage(hWnd,WM_KEYDOWN,VK_PRIOR,0L);
  393. break;
  394. case WM_HSCROLL:
  395. if(wParam ==SB_LINEDOWN||wParam ==SB_PAGEDOWN)
  396. SendMessage(hWnd,WM_KEYDOWN,VK_RIGHT,0L);
  397. if(wParam ==SB_LINEUP||wParam ==SB_PAGEUP)
  398. SendMessage(hWnd,WM_KEYDOWN,VK_LEFT,0L);
  399. break;
  400. case WM_USER +2:
  401. if((int)wParam !=HqPaintData.jys) break;
  402. HqSort();
  403. InvalidateRect(hWnd, NULL, FALSE);
  404. break;
  405. case WM_SETFOCUS:
  406. SetFocus(ghWndMain);
  407. break;
  408. case WM_TIMER:
  409. if(wParam==5)
  410. {         
  411. if(HqPaintData.type >=HQ_SEL_1 && HqPaintData.type <=HQ_SEL_5||HqPaintData.filter!=HQ_ALL)
  412. {
  413. fSel =TRUE;
  414. for(i =0; i<HqPaintData.curRecCount
  415. && i+HqPaintData.curRecNum<HqPaintData.recCount; i++)
  416. recList[i] =HqPaintData.sortData.key[i+HqPaintData.curRecNum];
  417. recCount =i;
  418. }
  419. else
  420. {
  421. fSel =FALSE;
  422. recList[0] =HqPaintData.sortData.key[HqPaintData.curRecNum];
  423. recCount =HqPaintData.curRecCount;
  424. }
  425. if(HqData[HqPaintData.jys].recCount ==0) fRefresh =FALSE;
  426. else fRefresh =TRUE;
  427. //to deal with the new stock code adding status,we must receive 
  428. //    stock code and other information 
  429. fRefresh=FALSE;
  430. for(i =0; i<HqPaintData.curRecCount
  431. && (i+HqPaintData.curRecNum <HqPaintData.recCount); i++)
  432. {
  433. recNum =HqPaintData.sortData.key[i+HqPaintData.curRecNum];
  434. if(HqData[HqPaintData.jys].isReadOK[recNum] ==FALSE)
  435. {
  436. fRefresh =FALSE;
  437. break;
  438. }
  439. }
  440. if(recCount&&!gfConnecting&&gfOnLine)
  441. UDP_Send_Hq00(HqPaintData.jys, FALSE, fRefresh, fSel, recCount, recList);
  442. KillTimer(hWnd,5);
  443. if(recCount)
  444. {   
  445.     recNum =HqPaintData.sortData.key[0];
  446. if((HqData[HqPaintData.jys].recCount==0||HqData[HqPaintData.jys].lpRefData[recNum].zdjm==0.00&&
  447. HqData[HqPaintData.jys].lpRefData[recNum].zgjm==0.00)&&gfOnLine)
  448. SetTimer(hWnd,5,10000,NULL);
  449. }
  450. }
  451. break;
  452. case WM_RBUTTONDOWN:
  453. SetFocus(hWnd);
  454. SendMessage(hWnd, WM_KEYDOWN, VK_ESCAPE, 0L);
  455. break;
  456. case WM_KEYDOWN:
  457. GetClientRect(hWnd, &rc);
  458. DrawSelRect(hWnd, NULL, HqPaintData.curSelRec, TRUE);
  459. switch(wParam)
  460. {
  461. case VK_ESCAPE:
  462. DrawSelRect(hWnd, NULL, HqPaintData.curSelRec, FALSE);
  463. TrackPopupMenu(ghMenuHq, TPM_LEFTALIGN, 0,STATUS_HEIGHT -2,
  464. 0, ghWndMain, NULL);
  465. return 0L;
  466. case VK_ADD:
  467. //if(FontHight<24)
  468. {
  469. FontHight-=2;
  470. lf.lfHeight=FontHight;
  471. PostMessage(hWnd,WM_USER+1,NULL,NULL);
  472. SetWindowText(hWndInput, "");
  473. InvalidateRect(hWnd, NULL, TRUE);
  474. }
  475. return 0L;
  476. case VK_SUBTRACT:
  477. //if(FontHight>14)
  478. {
  479. FontHight+=2;
  480. lf.lfHeight=FontHight;
  481. PostMessage(hWnd,WM_USER+1,NULL,NULL);
  482. SetWindowText(hWndInput, "");
  483. InvalidateRect(hWnd, NULL, TRUE);
  484. }
  485. return 0L;
  486. case VK_F1:
  487. if(!IsSzRead||!IsShRead)
  488. return 0L;
  489. if(!IsWindowVisible(ghWndHelp))
  490. ShowWindow(ghWndHelp,SW_SHOW);
  491. else
  492.     SetFocus(ghWndHelp);
  493. sprintf(tmp,"%s\help.txt",szDataPath);
  494. i=LoadFile(tmp,0,"帮助/[ESC]退出");
  495. if(i>0)
  496. SendMessage(ghWndHelp,WM_USER+1,NULL,i);
  497. break;                                
  498. case VK_F2:
  499. if(!IsSzRead||!IsShRead)
  500. return 0L;
  501.     SendMessage(ghWndMain,WM_COMMAND,IDM_JY,NULL);
  502. return 0L;
  503. break;
  504. case VK_F3:
  505. if(!IsSzRead||!IsShRead)
  506. return 0L;
  507.     SendMessage(ghWndXlt,WM_KEYDOWN,VK_F3,0L);
  508. return 0L;
  509. case VK_F4:
  510. if(!IsSzRead||!IsShRead)
  511. return 0L;
  512.                     if(HqPaintData.jys==0)
  513. SendMessage(hWnd, WM_COMMAND, IDM_HQ_SH, 0L); 
  514. else
  515. SendMessage(hWnd, WM_COMMAND, IDM_HQ_SZ, 0L);
  516. return 0L;
  517. case VK_F5:
  518. if(!IsSzRead||!IsShRead)
  519. return 0L;
  520. switch(HqPaintData.type) 
  521. {
  522. case HQ_SZALL:
  523. case HQ_SHALL:
  524. SendMessage(hWnd, WM_COMMAND, IDM_HQSEL_1, 0L);
  525.     break;
  526. case HQ_SEL_1:
  527. SendMessage(hWnd, WM_COMMAND, IDM_HQSEL_2, 0L);
  528.     break;
  529. case HQ_SEL_2:
  530. SendMessage(hWnd, WM_COMMAND, IDM_HQSEL_3, 0L);
  531.     break;
  532. case HQ_SEL_3:
  533. SendMessage(hWnd, WM_COMMAND, IDM_HQSEL_4, 0L);
  534.     break;
  535. case HQ_SEL_4:
  536. SendMessage(hWnd, WM_COMMAND, IDM_HQSEL_5, 0L);
  537.     break;
  538. case HQ_SEL_5:
  539. SendMessage(hWnd, WM_COMMAND, IDM_HQSEL_1, 0L);
  540. break;     
  541. }
  542. return 0L;
  543. case VK_F7:
  544. SendMessage(hWnd, WM_COMMAND, IDM_HQSEL_SET_1, 0L);
  545. return 0L;
  546. case VK_F8:
  547. SendMessage(hWnd, WM_COMMAND, IDM_HQ_FLD_SEL, 0L);
  548. return 0L;
  549. case VK_F9:
  550. if(!IsSzRead||!IsShRead)
  551. return 0L;
  552. i =HqPaintData.sortData.key[HqPaintData.curSelRec+HqPaintData.curRecNum];
  553. GraphData.jys =MmpData.jys =HqPaintData.jys;
  554. GraphData.recNum =MmpData.recNum =i;
  555. UDP_Send_Gra00(GraphData.jys, i);
  556. ShowWindow(ghWndLitHq, SW_SHOW);
  557. SendMessage(ghWndLitHq, WM_READ_OK, GraphData.jys, GraphData.recNum);
  558. if(IsZsRec(GraphData.jys, i))
  559. {
  560. ShowWindow(ghWndMmp, SW_HIDE);
  561. ShowWindow(ghWndCj, SW_HIDE);
  562. ShowWindow(ghWndZs, SW_SHOW);
  563. ShowWindow(ghWndMaxMin, SW_SHOW);
  564. }
  565. else
  566. {
  567. ShowWindow(ghWndZs, SW_HIDE);
  568. ShowWindow(ghWndMaxMin, SW_HIDE);
  569. ShowWindow(ghWndMmp, SW_SHOW);
  570. ShowWindow(ghWndCj, SW_SHOW);
  571. }
  572. SendMessage(ghWndXlt, WM_KEYDOWN, VK_RETURN, 0L);
  573. ShowWindow(hWnd, SW_HIDE);
  574. return 0L;
  575. case VK_F11:
  576. if(!IsSzRead||!IsShRead)
  577. break;
  578. if(gfConnecting)
  579. {
  580. ErrMsg(ghWndMain,"正在连接券商...!");
  581. break;
  582. }
  583. if(Addr[0][0]==0)
  584. InitQsInfo();
  585.     if(Addr[0][0]==0) break;
  586.     
  587.     if(Qsxx.zqsid[0]!=0&&Qsxx.zqsid[1]==0) //单券商
  588.     {
  589.      curChkUsrData.zqsid =Qsxx.zqsid[0];
  590.      i=1;
  591.     }
  592.     else
  593.     {                                      //多券商
  594. if((i=DlgSelectZqs())==0)
  595. {
  596. ErrMsg(ghWndMain,"选择证券商出错,不能交易!");
  597. break;
  598. }
  599. }
  600. if(JyQs!=i)
  601. {     
  602.      Msg("正在连接证券部,请您稍候...",MSG_VERT);
  603.      gfConnecting =TRUE;
  604.      JyQs =0;
  605.      SeleQs =i;
  606. if(ConnectToJyHost(Addr[i -1])!=0)
  607. {
  608. Msg("",MSG_HIDE);
  609. gfConnecting =FALSE;
  610. Msg("连接证券部出错,请您重试...",MSG_VERT);
  611. JyQs =0;
  612. DispQsName(JyQs,0);
  613. break;
  614. }
  615. gfConnecting =FALSE;
  616. }
  617. break;
  618. case VK_F12:
  619. if(!IsSzRead||!IsShRead)
  620. return 0L;
  621. SendMessage(ghWndXlt, WM_KEYDOWN, VK_F12, 0L);
  622. return 0L;
  623. case VK_F6:
  624. case VK_RETURN:
  625. if(!IsSzRead||!IsShRead)
  626. return 0L;
  627. if(HqPaintData.recCount <=0) break;
  628. tmp[0] =0;
  629. GetWindowText(hWndInput, &tmp[0], sizeof(tmp));
  630. if(tmp[0] ==0)
  631. SendMessage(hWnd, WM_COMMAND, IDM_GRAPH, 0L);
  632. else
  633. {                        
  634.                         if(!strcmp("01", tmp))
  635.                         {
  636.                          //if(HqPaintData.jys!=0)
  637.                          {
  638.                              HqPaintData.filter =HQ_ALL;
  639. SendMessage(hWnd, WM_COMMAND, IDM_HQ_SZ, 0L);
  640. HqSort();
  641. InvalidateRect(hWnd, NULL, TRUE);
  642. }
  643. SetWindowText(hWndInput, "");
  644. break;
  645.                         }
  646.                         if(!strcmp("02", tmp))
  647.                         {
  648.                          //if(HqPaintData.jys!=1)
  649.                          {
  650.                          HqPaintData.filter =HQ_ALL;
  651. SendMessage(hWnd, WM_COMMAND, IDM_HQ_SH, 0L);                        
  652. HqSort();
  653. InvalidateRect(hWnd, NULL, TRUE);
  654. }
  655. SetWindowText(hWndInput, "");
  656. break;
  657.                         }
  658.                         if(!strcmp("03",tmp))
  659.                         {
  660. SetWindowText(hWndInput, "");
  661. SendMessage(hWnd, WM_COMMAND, IDM_GRAPH, 3L);
  662. break;
  663.                         }
  664.                         if(!strcmp("04",tmp))
  665.                         {
  666. SetWindowText(hWndInput, "");
  667. SendMessage(hWnd, WM_COMMAND, IDM_GRAPH, 4L);
  668. break;                        
  669.                         }
  670.                         if(!strcmp("05",tmp))
  671.                         {
  672.                          HqPaintData.filter =HQ_A;
  673. HqSort();
  674. InvalidateRect(hWnd, NULL, TRUE);
  675. SetWindowText(hWndInput, "");
  676. break;
  677.                         }
  678.                         else if(!strcmp("06",tmp))
  679.                         {
  680.                          HqPaintData.filter =HQ_B;
  681.                          HqSort();
  682. InvalidateRect(hWnd, NULL, TRUE);
  683. SetWindowText(hWndInput, "");
  684. break;
  685.                         }
  686.                         else if(!strcmp("07",tmp))
  687.                         {
  688.                          HqPaintData.filter =HQ_BOND;
  689.                          HqSort();
  690. InvalidateRect(hWnd, NULL, TRUE);
  691. SetWindowText(hWndInput, "");
  692. break;
  693.                         }                        
  694.                         else if(HqPaintData.type==HQ_SZALL&&strlen(tmp)==6)
  695.                         {
  696. SendMessage(hWnd, WM_COMMAND, IDM_HQ_SH, 0L);
  697. InvalidateRect(hWnd, NULL, TRUE);                        
  698.                         }
  699.                         else if(HqPaintData.type==HQ_SHALL&&strlen(tmp)==4)
  700.                         {
  701. SendMessage(hWnd, WM_COMMAND, IDM_HQ_SZ, 0L);
  702. InvalidateRect(hWnd, NULL, TRUE);                        
  703.                         }
  704. for(i =0; i<HqPaintData.recCount; i++)
  705. {
  706. j =HqPaintData.sortData.key[i];
  707. if(!strcmp(HqData[HqPaintData.jys].lpPreData[j].zqdm, tmp))
  708. break;
  709. }
  710. if(i <HqPaintData.recCount)
  711. {   
  712. if(HqPaintData.type==HQ_SZALL||HqPaintData.type==HQ_SHALL)
  713. {
  714. HqPaintData.curRecNum =i-i%HqPaintData.curRecCount;
  715. HqPaintData.curSelRec =i%HqPaintData.curRecCount;
  716. if(HqPaintData.curRecNum+HqPaintData.curRecCount >=HqPaintData.recCount)
  717. {
  718. HqPaintData.curRecNum =
  719. HqPaintData.recCount-HqPaintData.curRecCount;
  720. for(i=0;i<HqPaintData.curRecCount;i++)
  721. if(!strcmp(HqData[HqPaintData.jys].lpPreData[i+HqPaintData.curRecNum].zqdm, tmp))
  722. break;
  723. HqPaintData.curSelRec=i;
  724. }
  725. }
  726. else
  727. HqPaintData.curSelRec=i;
  728. InvalidateRect(hWnd, NULL, TRUE);
  729. }
  730. KillTimer(hWnd, 5);
  731. SetTimer(hWnd,5,1000,NULL);
  732. SetWindowText(hWndInput, "");
  733. }
  734. break;
  735. case VK_LEFT:
  736. DrawSelRect(hWnd, NULL, HqPaintData.curSelRec, FALSE);
  737. if(HqPaintData.curFldNum ==0) break;
  738. HqPaintData.curFldNum --;
  739. rc.left =X0_TITLE;
  740. x =HqPaintData.x0;
  741. if(HqPaintData.curFldNum >0)
  742. {
  743. HqPaintData.x0 +=
  744. HqPaintData.rcTitles[HqPaintData.curFldNum].right
  745. -HqPaintData.rcTitles[HqPaintData.curFldNum-1].right;
  746. }
  747. else
  748. HqPaintData.x0 +=
  749. HqPaintData.rcTitles[HqPaintData.curFldNum].right
  750. -X0_TITLE;
  751. ScrollWindow(hWnd, HqPaintData.x0-x, 0, &rc, &rc);
  752. SetScrollPos(hWnd,SB_HORZ,(int)(HqPaintData.curFldNum*R_HORZ/HqPaintData.fldCount),TRUE);
  753. break;
  754. case VK_RIGHT:
  755. if(HqPaintData.rcTitles[HqPaintData.fldCount-1].right==0)
  756. {
  757. x  =X0_TITLE;
  758. for(j =0; j<HqPaintData.fldCount; j++)
  759. {
  760. HqPaintData.rcTitles[j].left =x;
  761. HqPaintData.rcTitles[j].right =
  762. x+tm.tmAveCharWidth*HqPaintFldLens[HqPaintData.fldNum[j]];
  763. HqPaintData.rcTitles[j].top =0;
  764. HqPaintData.rcTitles[j].bottom =tm.tmHeight;
  765. x =HqPaintData.rcTitles[j].right+ITEM_SPACE_X;
  766. }
  767. }
  768. DrawSelRect(hWnd, NULL, HqPaintData.curSelRec, FALSE);
  769. if(HqPaintData.rcTitles[HqPaintData.fldCount-1].right
  770. +HqPaintData.x0<rc.right) break;
  771. if(HqPaintData.curFldNum>=HqPaintData.fldCount-1) break;
  772. rc.left =X0_TITLE;
  773. x =HqPaintData.x0;
  774. if(HqPaintData.curFldNum >0)
  775. {
  776. HqPaintData.x0 -=
  777. HqPaintData.rcTitles[HqPaintData.curFldNum].right
  778. -HqPaintData.rcTitles[HqPaintData.curFldNum-1].right;
  779. }
  780. else    
  781. HqPaintData.x0 -=
  782. HqPaintData.rcTitles[HqPaintData.curFldNum].right
  783. -X0_TITLE;
  784. HqPaintData.curFldNum ++;
  785. ScrollWindow(hWnd, HqPaintData.x0-x, 0, &rc, &rc);
  786. SetScrollPos(hWnd,SB_HORZ,(int)(HqPaintData.curFldNum*R_HORZ/HqPaintData.fldCount),TRUE);
  787. break;
  788. case VK_UP:
  789. HqPaintData.curSelRec--;
  790. if(HqPaintData.curSelRec <0)
  791. {
  792. HqPaintData.curSelRec =HqPaintData.curRecCount-1; //0
  793. if(HqPaintData.curSelRec >=HqPaintData.recCount)
  794. HqPaintData.curSelRec =HqPaintData.recCount-1;
  795. }
  796. SetScrollPos(hWnd,SB_VERT,(int)((long)(HqPaintData.curRecNum+HqPaintData.curSelRec)*(long)R_VERT/(long)HqPaintData.recCount),TRUE);
  797. break;
  798. case VK_DOWN:
  799. if(HqPaintData.curSelRec+HqPaintData.curRecNum
  800. >=HqPaintData.recCount-1)
  801. {
  802. HqPaintData.curSelRec =0;
  803. break;
  804. }
  805. HqPaintData.curSelRec++;
  806. if(HqPaintData.curSelRec >=HqPaintData.curRecCount)
  807. HqPaintData.curSelRec =0;//HqPaintData.curRecCount-1;
  808. SetScrollPos(hWnd,SB_VERT,(int)((long)(HqPaintData.curRecNum+HqPaintData.curSelRec)*(long)R_VERT/(long)HqPaintData.recCount),TRUE);
  809. break;
  810. case VK_PRIOR:
  811. if(HqPaintData.rcTitles[HqPaintData.fldCount-1].right==0)
  812. {
  813. x  =X0_TITLE;
  814. for(j =0; j<HqPaintData.fldCount; j++)
  815. {
  816. HqPaintData.rcTitles[j].left =x;
  817. HqPaintData.rcTitles[j].right =
  818. x+tm.tmAveCharWidth*HqPaintFldLens[HqPaintData.fldNum[j]];
  819. HqPaintData.rcTitles[j].top =0;
  820. HqPaintData.rcTitles[j].bottom =tm.tmHeight;
  821. x =HqPaintData.rcTitles[j].right+ITEM_SPACE_X;
  822. }
  823. }
  824. if(HqPaintData.curRecNum ==0) break;
  825. i =HqPaintData.curRecNum;
  826. HqPaintData.curRecNum-=HqPaintData.curRecCount-1;
  827. if(HqPaintData.curRecNum <0)
  828. HqPaintData.curRecNum =0;
  829. HqPaintData.curSelRec =0;
  830. rc.top =HqPaintData.itemHeight;
  831. rc.bottom =HqPaintData.itemHeight*(HqPaintData.curRecCount+1);
  832. ScrollWindow(hWnd, 0,
  833. +(HqPaintData.curRecCount-1)*HqPaintData.itemHeight,
  834. &rc, &rc);
  835. SetScrollPos(hWnd,SB_VERT,(int)((long)(HqPaintData.curRecNum+HqPaintData.curSelRec)*(long)R_VERT/(long)HqPaintData.recCount),TRUE);
  836. if(HqPaintData.curRecCount <HqPaintData.recCount)
  837. {
  838. KillTimer(hWnd, 5);
  839. SetTimer(hWnd,5,500,NULL);
  840. }
  841. break;
  842. case VK_NEXT:
  843. if(IsSzRead&&IsShRead)
  844. {
  845. if(HqPaintData.rcTitles[HqPaintData.fldCount-1].right==0)
  846. {
  847. x  =X0_TITLE;
  848. for(j =0; j<HqPaintData.fldCount; j++)
  849. {
  850. HqPaintData.rcTitles[j].left =x;
  851. HqPaintData.rcTitles[j].right =
  852. x+tm.tmAveCharWidth*HqPaintFldLens[HqPaintData.fldNum[j]];
  853. HqPaintData.rcTitles[j].top =0;
  854. HqPaintData.rcTitles[j].bottom =tm.tmHeight;
  855. x =HqPaintData.rcTitles[j].right+ITEM_SPACE_X;
  856. }
  857. }
  858. if(HqPaintData.curRecNum+HqPaintData.curRecCount >=HqPaintData.recCount)
  859. break;
  860. i =HqPaintData.curRecNum;
  861. HqPaintData.curRecNum+=HqPaintData.curRecCount-1;
  862. if(HqPaintData.curRecNum+HqPaintData.curRecCount >=HqPaintData.recCount)
  863. HqPaintData.curRecNum =HqPaintData.recCount-HqPaintData.curRecCount;
  864. HqPaintData.curSelRec =0;
  865. rc.top =HqPaintData.itemHeight;
  866. rc.bottom =HqPaintData.itemHeight*(HqPaintData.curRecCount+1);
  867. ScrollWindow(hWnd, 0,
  868. -(HqPaintData.curRecCount-1)*HqPaintData.itemHeight,
  869. &rc, &rc);
  870. SetScrollPos(hWnd,SB_VERT,(int)((long)(HqPaintData.curRecNum+HqPaintData.curSelRec)*(long)R_VERT/(long)HqPaintData.recCount),TRUE);
  871. if(HqPaintData.curRecNum+HqPaintData.curRecCount >=HqPaintData.recCount)
  872. InvalidateRect(hWnd, NULL, TRUE);
  873. if(HqPaintData.curRecCount <HqPaintData.recCount)
  874. {
  875. KillTimer(hWnd, 5);
  876. SetTimer(hWnd,5,500,NULL);
  877. }
  878. }
  879. break;
  880. case VK_HOME:
  881. HqPaintData.curRecNum =HqPaintData.curSelRec =0;
  882. InvalidateRect(hWnd, NULL, TRUE);
  883. if(HqPaintData.recCount >HqPaintData.curRecCount)
  884. {
  885. KillTimer(hWnd, 5);
  886. SetTimer(hWnd,5,500,NULL);
  887. }
  888. SetScrollPos(hWnd,SB_VERT,(int)((long)(HqPaintData.curRecNum+HqPaintData.curSelRec)*(long)R_VERT/(long)HqPaintData.recCount),TRUE);
  889. return 0L;
  890. case VK_END:
  891. if(IsSzRead&&IsShRead)
  892. {
  893. if(HqPaintData.recCount <HqPaintData.curRecCount)
  894. {
  895. HqPaintData.curRecNum =0;
  896. HqPaintData.curSelRec =HqPaintData.recCount-1;
  897. }
  898. else
  899. {
  900. HqPaintData.curSelRec =HqPaintData.curRecCount-1;
  901. HqPaintData.curRecNum =HqPaintData.recCount
  902. -HqPaintData.curRecCount;
  903. KillTimer(hWnd, 5);
  904. SetTimer(hWnd,5,500,NULL);
  905. }
  906. InvalidateRect(hWnd, NULL, TRUE);
  907. }
  908. SetScrollPos(hWnd,SB_VERT,(int)((long)(HqPaintData.curRecNum+HqPaintData.curSelRec)*(long)R_VERT/(long)HqPaintData.recCount),TRUE);
  909. return 0L;
  910. default:
  911. break;  
  912. }
  913. UpdateWindow(hWnd);
  914. DrawSelRect(hWnd, NULL, HqPaintData.curSelRec, FALSE);
  915. break;
  916. case WM_LBUTTONDBLCLK:
  917. PostMessage(hWnd,WM_KEYDOWN,VK_RETURN,NULL);
  918. break;
  919. case WM_LBUTTONDOWN:
  920. SetFocus(hWnd);
  921. x=LOWORD(lParam);
  922. y=HIWORD(lParam);
  923. DrawSelRect(hWnd, NULL, HqPaintData.curSelRec, TRUE);
  924. i=(int)((y)/(HqPaintData.rcTitles[0].bottom+ITEM_SPACE_Y)) -1;
  925. if(i>=HqPaintData.recCount) i=HqPaintData.recCount -1;
  926. if(i<0) i=0;
  927. HqPaintData.curSelRec=i;
  928. DrawSelRect(hWnd, NULL, HqPaintData.curSelRec, FALSE);
  929. if(clock()-MouDownClk<240)
  930. PostMessage(hWnd,WM_KEYDOWN,VK_RETURN,NULL);
  931. MouDownClk=clock();
  932. break;
  933. case WM_PAINT:
  934. if(HqPaintData.type<2&&
  935. HqPaintData.curRecCount>0&&HqPaintData.recCount>0)
  936. {
  937. if(HqPaintData.curRecNum+HqPaintData.curRecCount >=HqPaintData.recCount)
  938. HqPaintData.curRecNum =HqPaintData.recCount-HqPaintData.curRecCount;
  939.     }
  940. if(HqData[HqPaintData.jys].recCount <=0) break;
  941. GetClientRect(hWnd, &rc);
  942. BeginPaint(hWnd, &ps);
  943.      SelectObject(ps.hdc,hHqFont);
  944. GetClientRect(hWnd, &rc);
  945. // draw title
  946. rc.left =DrawTitle(hWnd, ps.hdc);
  947. rc.top =HqPaintData.itemHeight;
  948. rc.bottom =HqPaintData.itemHeight*(HqPaintData.curRecCount+1);
  949. IntersectClipRect(ps.hdc, rc.left, rc.top, rc.right, rc.bottom);
  950. SetTextAlign(ps.hdc, TA_TOP|TA_RIGHT);
  951. SetBkMode(ps.hdc, OPAQUE);
  952. i =HqPaintData.curRecNum;
  953. SetBkColor(ps.hdc, RGB(0, 0, 0));
  954. m =0;
  955. //for(j =0; j<HqPaintData.curFldNum; j++)
  956. //      m +=HqFldLens[j];
  957. SetTextColor(ps.hdc, RGB(0, 255, 0));
  958. hDC =CreateCompatibleDC(ps.hdc);
  959. n =-1;
  960. while(i <=HqPaintData.curRecNum+HqPaintData.curRecCount
  961. && i<HqPaintData.recCount)
  962. {
  963. for(j =HqPaintData.curFldNum;
  964. j<HqPaintData.fldCount; j++)
  965. {
  966. x =HqPaintData.rcTitles[j].right+HqPaintData.x0;
  967. //if(x >rc.right) break;
  968. y =(HqPaintData.rcTitles[0].bottom+ITEM_SPACE_Y)
  969. *(i-HqPaintData.curRecNum+1);
  970. lpTmp =GetHqFldPos(ps.hdc, HqPaintData.jys,
  971. HqPaintData.sortData.key[i],
  972. HqPaintData.fldNum[j]);
  973. /*if(HqData[HqPaintData.jys].isChanged[HqPaintData.sortData.key[i]*HQ_REF_ITEM_COUNT+j] >0)
  974. SetTextColor(ps.hdc, RGB(255, 0, 0));   // red
  975. else if(HqData[HqPaintData.jys].isChanged[HqPaintData.sortData.key[i]*HQ_REF_ITEM_COUNT+j] <0)
  976. SetTextColor(ps.hdc, RGB(0, 255, 0));   // blue
  977. else SetTextColor(ps.hdc, RGB(255, 255, 255));  // black
  978. */
  979. l =HqPaintFldLens[HqPaintData.fldNum[j]]-strlen(tmp);
  980. for(k =0; k<l; k++)
  981. tmp[k] =0x20;
  982. switch(HqFldTypes[HqPaintData.fldNum[j]])
  983. {
  984. case FLD_TYPE_STRING:
  985. strcpy(&tmp[0], lpTmp);
  986. break;
  987. case FLD_TYPE_FLOAT:
  988. sprintf(&tmp[k], "%.2f", *(float *)lpTmp);
  989. if(strncmp(&tmp[k],"9999.99",7)==0) strcpy(&tmp[k],"-.--");
  990. if(HqPaintData.fldNum[j] ==7)
  991. {
  992. if(HqData[HqPaintData.jys].isJgChanged[i] >0)
  993. {
  994. SelectObject(hDC, hBmpUp);
  995. BitBlt(ps.hdc, x+2, y+2, 10, 10, hDC, 0, 0, SRCCOPY);
  996. }
  997. else if(HqData[HqPaintData.jys].isJgChanged[i] <0)
  998. {
  999. SelectObject(hDC, hBmpDown);
  1000. BitBlt(ps.hdc, x+2, y+2, 10, 10, hDC, 0, 0, SRCCOPY);
  1001. }
  1002. else
  1003. {
  1004. SelectObject(ps.hdc, GetStockObject(BLACK_BRUSH));
  1005. SelectObject(ps.hdc, GetStockObject(NULL_PEN));
  1006. Rectangle(ps.hdc, x+2, y+2, x+12, y+12);
  1007. }
  1008. n =j+1;
  1009. }
  1010. break;
  1011. case FLD_TYPE_LONG:
  1012. if(HqPaintData.fldNum[j] ==14)
  1013. sprintf(&tmp[k], "%.1f", (float)*(long *)lpTmp/10);
  1014. else
  1015. sprintf(&tmp[k], "%ld", *(long *)lpTmp);
  1016. break;
  1017. }
  1018. //strcpy(&tmp[k], lpTmp);
  1019. if(j ==0)
  1020. SetRect(&rc1, rc.left,
  1021. y, x, y+HqPaintData.rcTitles[0].bottom+1);
  1022. else if(j ==n)
  1023. SetRect(&rc1, HqPaintData.rcTitles[j-1].right+HqPaintData.x0+12,
  1024. y, x, y+HqPaintData.rcTitles[0].bottom+1);
  1025. else
  1026. SetRect(&rc1, HqPaintData.rcTitles[j-1].right+HqPaintData.x0,
  1027. y, x, y+HqPaintData.rcTitles[0].bottom+1);
  1028. if(HqPaintData.fldNum[j] ==10)
  1029. {
  1030. SelectObject(ps.hdc, GetStockObject(NULL_PEN));
  1031. SelectObject(ps.hdc, GetStockObject(BLACK_BRUSH));
  1032. Rectangle(ps.hdc, rc1.left, rc1.top,
  1033. rc1.right, rc1.bottom);
  1034. ExtTextOut(ps.hdc, x, y, ETO_CLIPPED,
  1035. &rc1, tmp, strlen(tmp), NULL);
  1036. }
  1037. else    
  1038. ExtTextOut(ps.hdc, x, y, ETO_CLIPPED|ETO_OPAQUE,
  1039. &rc1, tmp, strlen(tmp), NULL);
  1040. //lpTmp +=HqFldLens[j];
  1041. if(x >rc.right) break;
  1042. }
  1043. i++;
  1044. }
  1045. DeleteObject(hDC);
  1046. EndPaint(hWnd, &ps);
  1047. break;
  1048. case WM_COMMAND:
  1049. if(wParam >=IDM_SORT_ZQDM && wParam <=IDM_SORT_CJJE)
  1050. {
  1051. if(!IsWindowVisible(hWnd)) return 0L;
  1052. CheckMenuItem(ghMenuHq, HqPaintData.sortData.fldID+IDM_SORT_ZQDM,
  1053. MF_BYCOMMAND|MF_UNCHECKED);
  1054. HqPaintData.sortData.fldID =(int)wParam -IDM_SORT_ZQDM;
  1055. HqSort();
  1056. CheckMenuItem(ghMenuHq, wParam, MF_BYCOMMAND|MF_CHECKED);
  1057. InvalidateRect(hWnd, NULL, TRUE);
  1058. return 0L;
  1059. }
  1060. i =HqPaintData.type;
  1061. switch(wParam)
  1062. {
  1063. case IDM_HQSEL_SET_1:
  1064. case IDM_HQSEL_SET_2:
  1065. case IDM_HQSEL_SET_3:
  1066. case IDM_HQSEL_SET_4:
  1067. case IDM_HQSEL_SET_5:
  1068. case IDM_HQ_FLD_SEL:
  1069. case IDM_JY:
  1070. case IDM_MINIMIZE:
  1071. case IDM_EXIT:
  1072. SendMessage(ghWndMain, WM_COMMAND, wParam, lParam);
  1073. return 0L;
  1074. case IDM_GRAPH:
  1075. if(!HqPaintData.recCount) return 0L;
  1076. if(lParam==3)
  1077. {   
  1078.     for(i=HqData[0].recCount-1;i>=0;i--)
  1079.     {
  1080.      if(strncmp("9901",HqData[0].lpPreData[i].zqdm,4)==0)
  1081.      break;
  1082.     }
  1083.     if(i<0) return 0L;
  1084. GraphData.jys =MmpData.jys=0;
  1085. }
  1086. if(lParam==4)
  1087. {
  1088.     for(i=0;i<HqData[1].recCount;i++)
  1089.     {
  1090.      if(strncmp("000001",HqData[1].lpPreData[i].zqdm,6)==0)
  1091.      {
  1092.      break;
  1093.      }
  1094.     }
  1095.     if(i>=HqData[1].recCount) return 0L;
  1096. GraphData.jys =MmpData.jys=1;
  1097. }
  1098. if(lParam==0)
  1099. {
  1100. i =HqPaintData.sortData.key[HqPaintData.curSelRec+HqPaintData.curRecNum];
  1101. GraphData.jys =MmpData.jys =HqPaintData.jys;
  1102. }
  1103. GraphData.recNum =MmpData.recNum =i;
  1104. UDP_Send_Gra00(GraphData.jys, i);
  1105. if(!IsWindowVisible(ghWndXlt))
  1106. ShowWindow(ghWndXlt, SW_SHOW);
  1107. else
  1108. InvalidateRect(ghWndXlt, NULL, TRUE);
  1109. if(!IsWindowVisible(ghWndJlt))
  1110. ShowWindow(ghWndJlt, SW_SHOW);
  1111. else
  1112.     InvalidateRect(ghWndJlt, NULL, TRUE);
  1113. if(!IsWindowVisible(ghWndLitHq))    
  1114. ShowWindow(ghWndLitHq, SW_SHOW);
  1115. else
  1116.     InvalidateRect(ghWndLitHq, NULL, TRUE);
  1117. SendMessage(ghWndLitHq, WM_READ_OK, GraphData.jys, GraphData.recNum);
  1118. if(IsZsRec(GraphData.jys, i))
  1119. {
  1120. ShowWindow(ghWndMmp, SW_HIDE);
  1121. ShowWindow(ghWndCj, SW_HIDE);
  1122. if(!IsWindowVisible(ghWndZs))
  1123. ShowWindow(ghWndZs, SW_SHOW);
  1124. else
  1125.     InvalidateRect(ghWndZs, NULL, TRUE);
  1126. if(!IsWindowVisible(ghWndMaxMin))    
  1127. ShowWindow(ghWndMaxMin, SW_SHOW);
  1128. else
  1129.     InvalidateRect(ghWndMaxMin, NULL, TRUE);
  1130. }
  1131. else
  1132. {
  1133. ShowWindow(ghWndZs, SW_HIDE);
  1134. ShowWindow(ghWndMaxMin, SW_HIDE);    
  1135. if(!IsWindowVisible(ghWndMmp))    
  1136. ShowWindow(ghWndMmp, SW_SHOW);
  1137. else
  1138.     InvalidateRect(ghWndMmp, NULL, TRUE); 
  1139. if(!IsWindowVisible(ghWndCj))        
  1140. ShowWindow(ghWndCj, SW_SHOW);
  1141. else
  1142.     InvalidateRect(ghWndCj, NULL, TRUE); 
  1143. }
  1144.         if(IsWindowVisible(ghWndHq)) ShowWindow(hWnd, SW_HIDE);
  1145. return 0L;
  1146. case IDM_SORT_UP:
  1147. if(!IsWindowVisible(hWnd)) return 0L;
  1148. CheckMenuItem(ghMenuHq, IDM_SORT_DOWN, MF_BYCOMMAND|MF_UNCHECKED);
  1149. HqPaintData.sortData.type =SORT_UP;
  1150. HqSort();
  1151. CheckMenuItem(ghMenuHq, IDM_SORT_UP, MF_BYCOMMAND|MF_CHECKED);
  1152. InvalidateRect(hWnd, NULL, TRUE);
  1153. return 0L;
  1154. case IDM_SORT_DOWN:
  1155. if(!IsWindowVisible(hWnd)) return 0L;
  1156. CheckMenuItem(ghMenuHq, IDM_SORT_UP, MF_BYCOMMAND|MF_UNCHECKED);
  1157. HqPaintData.sortData.type =SORT_DOWN;
  1158. HqSort();
  1159. CheckMenuItem(ghMenuHq, IDM_SORT_DOWN, MF_BYCOMMAND|MF_CHECKED);
  1160. InvalidateRect(hWnd, NULL, TRUE);
  1161. return 0L;
  1162. case IDM_HQ_SZ:
  1163. HqPaintData.type =HQ_SZALL;
  1164. break;
  1165. case IDM_HQ_SH:
  1166. HqPaintData.type =HQ_SHALL;
  1167. break;
  1168. case IDM_HQSEL_1:
  1169. HqPaintData.type =HQ_SEL_1;
  1170. break;
  1171. case IDM_HQSEL_2:
  1172. HqPaintData.type =HQ_SEL_2;
  1173. break;
  1174. case IDM_HQSEL_3:
  1175. HqPaintData.type =HQ_SEL_3;
  1176. break;
  1177. case IDM_HQSEL_4:
  1178. HqPaintData.type =HQ_SEL_4;
  1179. break;
  1180. case IDM_HQSEL_5:
  1181. HqPaintData.type =HQ_SEL_5;
  1182. break;
  1183. default: return 0L;
  1184. }                                                 
  1185. ShowWindow(ghWndFx,SW_HIDE);
  1186. ShowWindow(ghWndJlt, SW_HIDE);
  1187. ShowWindow(ghWndXlt, SW_HIDE);
  1188. ShowWindow(ghWndCj, SW_HIDE);
  1189. ShowWindow(ghWndLitHq,SW_HIDE);
  1190. ShowWindow(ghWndMmp, SW_HIDE);
  1191. ShowWindow(ghWndZs, SW_HIDE);
  1192. ShowWindow(ghWndMaxMin, SW_HIDE);
  1193. CheckMenuItem(ghMenuHq, i+IDM_HQ_SZ, MF_BYCOMMAND|MF_UNCHECKED);
  1194. HqSort();
  1195. HqPaintData.curRecNum =0;
  1196. HqPaintData.curFldNum =0;
  1197. HqPaintData.curSelRec =0;
  1198. HqPaintData.x0 =0;
  1199. if(!IsWindowVisible(hWnd))
  1200. {
  1201. ShowWindow(hWnd, SW_SHOW);
  1202. }
  1203. CheckMenuItem(ghMenuHq, wParam, MF_BYCOMMAND|MF_CHECKED);
  1204. KillTimer(hWnd, 5);
  1205. SetTimer(hWnd, 5, 1000, NULL);
  1206. InvalidateRect(hWnd, NULL, TRUE);
  1207. break;
  1208. case WM_DESTROY:
  1209. if(recList) free(recList); 
  1210. }
  1211. return DefWindowProc(hWnd, message, wParam, lParam);
  1212. }
  1213. LPSTR HqTitles[HQ_FLDS_COUNT+2] =
  1214. {
  1215. "代码","昨收","今开","最高","最低","叫买","叫卖","成交","涨幅",
  1216. "总手","现手", "内盘", "外盘", "委比", "金额(万)","涨跌",NULL
  1217. };
  1218. int DrawTitle(HWND hWnd, HDC hDC)
  1219. {
  1220. int i, jys;
  1221. RECT rc;
  1222. char temp[20];
  1223. jys =HqPaintData.jys;
  1224. GetClientRect(hWnd, &rc);
  1225. //SetBkMode(hDC, TRANSPARENT);
  1226. SetBkMode(hDC, OPAQUE);
  1227. SetTextColor(hDC, RGB(255, 0, 255));
  1228. SetBkColor(hDC,RGB(0,0,0));
  1229. SetTextAlign(hDC, TA_LEFT|TA_TOP);
  1230. i =HqPaintData.curRecNum;
  1231. for(;i <HqPaintData.curRecNum+HqPaintData.curRecCount
  1232. && i<HqPaintData.recCount; i++)
  1233. {
  1234. if(IsZsRec(HqPaintData.jys, HqPaintData.sortData.key[i]))
  1235. SetTextColor(hDC, RGB(255, 0, 0));
  1236. else SetTextColor(hDC, RGB(255, 0, 255));
  1237. strcpy(temp,HqData[jys].lpPreData[HqPaintData.sortData.key[i]].zqmc);
  1238. TextOut(hDC, 0,(HqPaintData.rcTitles[0].bottom+ITEM_SPACE_Y)
  1239. *(i-HqPaintData.curRecNum+1),temp, 
  1240. strlen(HqData[jys].lpPreData[HqPaintData.sortData.key[i]].zqmc));
  1241. }
  1242. DrawSelRect(hWnd, hDC, HqPaintData.curSelRec, FALSE);
  1243. SetTextColor(hDC, RGB(0, 255, 255));
  1244. TextOut(hDC, 0, 0, "证券名称", strlen("证券名称"));
  1245. rc.left =LOWORD(GetTextExtent(hDC, "证券名称", 8))+2;//X0_TITLE-ITEM_SPACE_X;
  1246. IntersectClipRect(hDC, rc.left, rc.top, rc.right, rc.bottom);
  1247. SetTextAlign(hDC, TA_RIGHT|TA_TOP);
  1248. for(i =HqPaintData.curFldNum;
  1249. i<HqPaintData.fldCount; i++)
  1250. {
  1251. if(HqPaintData.rcTitles[i].left+HqPaintData.x0 >rc.right) break;
  1252. if(HqPaintData.sortData.fldID ==HqPaintData.fldNum[i])
  1253. {
  1254. if(HqPaintData.sortData.type ==SORT_UP)
  1255. SetTextColor(hDC, RGB(255, 0, 0));
  1256. else SetTextColor(hDC, RGB(0, 0, 255));
  1257. }
  1258. else SetTextColor(hDC, RGB(0, 255, 255));
  1259. TextOut(hDC, HqPaintData.rcTitles[i].right+HqPaintData.x0, 0,
  1260. HqTitles[HqPaintData.fldNum[i]],
  1261. strlen(HqTitles[HqPaintData.fldNum[i]]));
  1262. }
  1263. return rc.left;
  1264. }
  1265. extern int CompString(LPSTR, LPSTR);
  1266. void DrawSelRect(HWND hWnd, HDC hDC, int sel_num, int bClr)
  1267. {
  1268. RECT rc;
  1269. DWORD dw;
  1270. HPEN hPen;
  1271. HDC hdc;
  1272. int height, width,i;
  1273.     char temp[20];
  1274.     
  1275. if(HqPaintData.recCount <=0) return;
  1276. if(hDC ==NULL) hdc =GetDC(hWnd);
  1277. else hdc =hDC;
  1278. SelectObject(hdc,hHqFont);
  1279. dw =GetTextExtent(hdc, "证券代码", 8);
  1280. GetClientRect(hWnd, &rc);
  1281. height=HqPaintData.itemHeight-ITEM_SPACE_Y;
  1282. width =LOWORD(dw);
  1283. SelectObject(hdc, GetStockObject(NULL_BRUSH));
  1284. i=HqPaintData.curSelRec+HqPaintData.curRecNum;
  1285. if(bClr)       
  1286. {
  1287. hPen =CreatePen(PS_SOLID, 0, RGB(0, 0, 0));
  1288. SetBkColor(hdc,RGB(0,0,0));
  1289. if(IsZsRec(HqPaintData.jys, HqPaintData.sortData.key[i]))
  1290.     SetTextColor(hdc, RGB(255, 0, 0));
  1291. else
  1292. SetTextColor(hdc, RGB(255, 0, 255));
  1293. }
  1294. else
  1295. {
  1296. hPen =CreatePen(PS_SOLID, 0, RGB(180, 180, 180));
  1297. SetBkColor(hdc,RGB(255,255,255));
  1298. SetTextColor(hdc, RGB(0,0, 255));
  1299. }
  1300. SelectObject(hdc, hPen);
  1301. MoveTo(hdc, 0, (sel_num+1)*(height+ITEM_SPACE_Y)+height+1);
  1302. LineTo(hdc, rc.right-1, (sel_num+1)*(height+ITEM_SPACE_Y)+height+1);
  1303.     rc.right =width +rc.left;
  1304.     rc.top =(sel_num+1)*(height+ITEM_SPACE_Y);
  1305.     rc.bottom =rc.top+height+1;
  1306.     if(bClr)
  1307.      FillRect(hdc,&rc,GetStockObject(BLACK_BRUSH));
  1308.     else       
  1309.      FillRect(hdc,&rc,GetStockObject(WHITE_BRUSH));
  1310.     
  1311. strcpy(temp,HqData[HqPaintData.jys].lpPreData[HqPaintData.sortData.key[i]].zqmc);
  1312. for(i=strlen(temp);i<8;i++) temp[i]=' ';
  1313. TextOut(hdc, 0,(HqPaintData.rcTitles[0].bottom+ITEM_SPACE_Y)
  1314. *(HqPaintData.curSelRec+1),temp,8);
  1315. SelectObject(hdc, GetStockObject(WHITE_PEN));
  1316. DeleteObject(hPen);
  1317. if(hDC ==NULL) ReleaseDC(hWnd, hdc);
  1318. if(hDC !=NULL)
  1319. SelectObject(hDC, GetStockObject(WHITE_PEN));
  1320.   SetBkColor(hDC,RGB(0,0,0));
  1321. }
  1322. }
  1323. int HqSort(void)
  1324. {
  1325. int i,j;
  1326. int jys;
  1327. switch(HqPaintData.type)
  1328. {
  1329. case HQ_SZALL:
  1330. HqPaintData.recCount =HqData[0].recCount;
  1331. jys =HqPaintData.jys =0;
  1332. for(i =0,j=0; i<HqData[0].recCount; i++)
  1333. if(HqPaintData.filter ==HQ_ALL)
  1334. HqPaintData.sortData.key[j++] =i;
  1335. if(HqPaintData.filter ==HQ_A)
  1336. {
  1337. if(HqData[HqPaintData.jys].lpPreData[i].zqdm[0]=='1')
  1338. continue;
  1339. if(HqData[HqPaintData.jys].lpPreData[i].zqdm[0]=='2')
  1340. continue;
  1341. if(HqData[HqPaintData.jys].lpPreData[i].zqdm[0]=='3')
  1342. continue;
  1343. if(HqData[HqPaintData.jys].lpPreData[i].zqdm[0]=='8')
  1344. continue;
  1345. if(HqData[HqPaintData.jys].lpPreData[i].zqdm[0]=='9')
  1346. continue;
  1347. HqPaintData.sortData.key[j++] =i;
  1348. }
  1349. if(HqPaintData.filter ==HQ_B)
  1350. {
  1351. if(HqData[HqPaintData.jys].lpPreData[i].zqdm[0]=='2')
  1352. HqPaintData.sortData.key[j++] =i;
  1353. else
  1354. continue;
  1355. }
  1356. if(HqPaintData.filter ==HQ_BOND)
  1357. {
  1358. if(HqData[HqPaintData.jys].lpPreData[i].zqdm[0]=='1')
  1359. HqPaintData.sortData.key[j++] =i;
  1360. else
  1361. continue;
  1362. }
  1363. }
  1364. HqPaintData.recCount =j;
  1365. break;
  1366. case HQ_SHALL:
  1367. HqPaintData.recCount =HqData[1].recCount;
  1368. jys =HqPaintData.jys =1;
  1369. for(i =0,j=0; i<HqData[1].recCount; i++)
  1370. {
  1371.     if(HqPaintData.filter ==HQ_ALL)
  1372. HqPaintData.sortData.key[j++] =i;
  1373. if(HqPaintData.filter ==HQ_A)
  1374. {
  1375. if(HqData[HqPaintData.jys].lpPreData[i].zqdm[0]=='0')
  1376. continue;
  1377. if(HqData[HqPaintData.jys].lpPreData[i].zqdm[0]=='1')
  1378. continue;
  1379. if(HqData[HqPaintData.jys].lpPreData[i].zqdm[0]=='2')
  1380. continue;
  1381. if(HqData[HqPaintData.jys].lpPreData[i].zqdm[0]=='7')
  1382. continue;
  1383. if(HqData[HqPaintData.jys].lpPreData[i].zqdm[0]=='9')
  1384. continue;
  1385. HqPaintData.sortData.key[j++] =i;
  1386. }
  1387. if(HqPaintData.filter ==HQ_B)
  1388. {
  1389. if(HqData[HqPaintData.jys].lpPreData[i].zqdm[0]=='9')
  1390. HqPaintData.sortData.key[j++] =i;
  1391. else
  1392. continue;
  1393. }
  1394. if(HqPaintData.filter ==HQ_BOND)
  1395. {
  1396. if(atoi(HqData[HqPaintData.jys].lpPreData[i].zqdm)<=10)
  1397. continue;
  1398. if(HqData[HqPaintData.jys].lpPreData[i].zqdm[0]<='2')
  1399. HqPaintData.sortData.key[j++] =i;
  1400. else
  1401. continue;
  1402. }
  1403. }
  1404. HqPaintData.recCount =j;
  1405. break;
  1406. case HQ_SEL_1:
  1407. HqPaintData.recCount =HqSelData[0].recCount;
  1408. for(i =0; i<HqPaintData.recCount; i++)
  1409. HqPaintData.sortData.key[i] =HqSelData[0].recNum[i];
  1410. jys =HqPaintData.jys =HqSelData[0].jys;
  1411. break;
  1412. case HQ_SEL_2:
  1413. HqPaintData.recCount =HqSelData[1].recCount;
  1414. for(i =0; i<HqPaintData.recCount; i++)
  1415. HqPaintData.sortData.key[i] =HqSelData[1].recNum[i];
  1416. jys =HqPaintData.jys =HqSelData[1].jys;
  1417. break;
  1418. case HQ_SEL_3:
  1419. HqPaintData.recCount =HqSelData[2].recCount;
  1420. for(i =0; i<HqPaintData.recCount; i++)
  1421. HqPaintData.sortData.key[i] =HqSelData[2].recNum[i];
  1422. jys =HqPaintData.jys =HqSelData[2].jys;
  1423. break;
  1424. case HQ_SEL_4:
  1425. HqPaintData.recCount =HqSelData[3].recCount;
  1426. for(i =0; i<HqPaintData.recCount; i++)
  1427. HqPaintData.sortData.key[i] =HqSelData[3].recNum[i];
  1428. jys =HqPaintData.jys =HqSelData[3].jys;
  1429. break;
  1430. case HQ_SEL_5:
  1431. HqPaintData.recCount =HqSelData[4].recCount;
  1432. for(i =0; i<HqPaintData.recCount; i++)
  1433. HqPaintData.sortData.key[i] =HqSelData[4].recNum[i];
  1434. jys =HqPaintData.jys =HqSelData[4].jys;
  1435. break;
  1436. }
  1437. //if(HqPaintData.sortData.fldID >=HqPaintData.fldCount)
  1438. //      return 0;
  1439. if(HqFldTypes[HqPaintData.sortData.fldID] ==FLD_TYPE_FLOAT)
  1440. SortFloat(&HqPaintData.sortData, jys);
  1441. else
  1442. if(HqFldTypes[HqPaintData.sortData.fldID] ==FLD_TYPE_LONG)
  1443. SortLong(&HqPaintData.sortData, jys);
  1444. return 0;
  1445. }
  1446. int SortFloat(LPSORT_DATA lpSortData, int jys)
  1447. {
  1448. int key, i, j, k, n;
  1449. float fval, f1, f;
  1450. k =HqPaintData.sortData.fldID;
  1451. for(i=0; i<HqPaintData.recCount-1; i++)
  1452. {
  1453. key =i;
  1454. fval =*(float*)GetHqFldPos1(jys, lpSortData->key[key], k);
  1455. for(j =i+1; j<HqPaintData.recCount; j++)
  1456. {
  1457. f1 =*(float *)GetHqFldPos1(jys, lpSortData->key[j], k);
  1458. f =f1-fval;
  1459. if(lpSortData->type ==SORT_UP && f>.0)
  1460. {
  1461. key =j;
  1462. fval =f1;
  1463. }
  1464. else if(lpSortData->type ==SORT_DOWN && f<.0)           
  1465. {
  1466. key =j;
  1467. fval =f1;
  1468. }
  1469. }
  1470. if(key >i)
  1471. {
  1472. //fval =*(float *)GetHqFldPos1(jys, lpSortData->key[key], k);
  1473. n =lpSortData->key[i];
  1474. lpSortData->key[i] =lpSortData->key[key];
  1475. lpSortData->key[key] =n;
  1476. }
  1477. }
  1478. return 0;
  1479. }
  1480. int SortLong(LPSORT_DATA lpSortData, int jys)
  1481. {
  1482. int key, i, j, k, n;
  1483. long lval, l1, l;
  1484. k =HqPaintData.sortData.fldID;
  1485. for(i=0; i<HqPaintData.recCount-1; i++)
  1486. {
  1487. key =i;
  1488. lval =*(long*)GetHqFldPos1(jys, lpSortData->key[key], k);
  1489. for(j =i+1; j<HqPaintData.recCount; j++)
  1490. {
  1491. l1 =*(long *)GetHqFldPos1(jys, lpSortData->key[j], k);
  1492. l =l1-lval;
  1493. if(lpSortData->type ==SORT_UP && l>0)
  1494. {
  1495. key =j;
  1496. lval =l1;
  1497. }
  1498. else if(lpSortData->type ==SORT_DOWN && l<0)            
  1499. {
  1500. key =j;
  1501. lval =l1;
  1502. }
  1503. }
  1504. if(key >i)
  1505. {
  1506. //lval =*(long *)GetHqFldPos1(jys, lpSortData->key[key], k);
  1507. n =lpSortData->key[i];
  1508. lpSortData->key[i] =lpSortData->key[key];
  1509. lpSortData->key[key] =n;
  1510. }
  1511. }
  1512. return 0;
  1513. }
  1514. LPSTR GetHqFldPos(HDC hDC, int jys, int rec_num, int fld_num)
  1515. {
  1516. float f;
  1517. LPSTR lpFld;
  1518. static long l;
  1519. if(HqData[jys].lpPreData[rec_num].zrsp!=0)
  1520. {
  1521. HqData[jys].lpRefData[rec_num].zdf=
  1522. (HqData[jys].lpRefData[rec_num].zjjg-HqData[jys].lpPreData[rec_num].zrsp)*100/
  1523. HqData[jys].lpPreData[rec_num].zrsp;
  1524. }
  1525. SetBkColor(hDC, RGB(0, 0, 0));
  1526. switch(fld_num)
  1527. {
  1528. case 0:
  1529. SetTextColor(hDC, RGB(180, 180, 0));
  1530. return (LPSTR)&HqData[jys].lpPreData[rec_num].zqdm[0];
  1531. case 1:
  1532. SetTextColor(hDC, RGB(255, 255, 255));
  1533. return (LPSTR)&HqData[jys].lpPreData[rec_num].zrsp;
  1534. case 2:
  1535. f =((HqData[jys].lpPreData[rec_num].jrkp
  1536. -HqData[jys].lpPreData[rec_num].zrsp));
  1537. lpFld =(LPSTR)&HqData[jys].lpPreData[rec_num].jrkp;
  1538. break;
  1539. case 3:
  1540. f =((HqData[jys].lpRefData[rec_num].zgjg
  1541. -HqData[jys].lpPreData[rec_num].zrsp));
  1542. lpFld =(LPSTR)&HqData[jys].lpRefData[rec_num].zgjg;
  1543. break;
  1544. case 4:
  1545. f =((HqData[jys].lpRefData[rec_num].zdjg
  1546. -HqData[jys].lpPreData[rec_num].zrsp));
  1547. lpFld =(LPSTR)&HqData[jys].lpRefData[rec_num].zdjg;
  1548. break;
  1549. case 5:
  1550. f =((HqData[jys].lpRefData[rec_num].zgjm
  1551. -HqData[jys].lpPreData[rec_num].zrsp));
  1552. lpFld =(LPSTR)&HqData[jys].lpRefData[rec_num].zgjm;
  1553. break;
  1554. case 6:
  1555. f =((HqData[jys].lpRefData[rec_num].zdjm
  1556. -HqData[jys].lpPreData[rec_num].zrsp));
  1557. lpFld =(LPSTR)&HqData[jys].lpRefData[rec_num].zdjm;
  1558. break;
  1559. case 7:
  1560. f =((HqData[jys].lpRefData[rec_num].zjjg
  1561. -HqData[jys].lpPreData[rec_num].zrsp));
  1562. lpFld =(LPSTR)&HqData[jys].lpRefData[rec_num].zjjg;
  1563. break;
  1564. case 8:
  1565. f =(float)(HqData[jys].lpRefData[rec_num].zdf);
  1566. lpFld =(LPSTR)&HqData[jys].lpRefData[rec_num].zdf;
  1567. break;
  1568. case 9:
  1569. f =HqData[jys].lpRefData[rec_num].zdf;
  1570. lpFld =(LPSTR)&HqData[jys].lpRefData[rec_num].cjss;
  1571. break;
  1572. case 10:
  1573. f =HqData[jys].lpRefData[rec_num].zdf;
  1574. if(HqData[jys].isJgChanged[rec_num]>0)
  1575. SetBkColor(hDC, RGB(80, 0, 0));
  1576. else if(HqData[jys].isJgChanged[rec_num]<0)
  1577. SetBkColor(hDC, RGB(0, 80, 0));
  1578. else SetBkColor(hDC, RGB(0, 0, 0));
  1579. SetTextColor(hDC, RGB(255, 255, 0));
  1580. return (LPSTR)&HqData[jys].lpRefData[rec_num].lc;
  1581. //break;
  1582. case 11:
  1583. f =HqData[jys].lpRefData[rec_num].zdf;
  1584. lpFld = (LPSTR)&HqData[jys].lpRefData[rec_num].npzl;
  1585. break;
  1586. case 12:
  1587. l =HqData[jys].lpRefData[rec_num].cjss
  1588. -HqData[jys].lpRefData[rec_num].npzl;
  1589. f =HqData[jys].lpRefData[rec_num].zdf;
  1590. lpFld =(LPSTR)&l;
  1591. break;
  1592. case 13:
  1593. f =HqData[jys].lpRefData[rec_num].zdf;
  1594. lpFld =(LPSTR)&HqData[jys].lpRefData[rec_num].wb;
  1595. break;
  1596. case 14:
  1597. f =HqData[jys].lpRefData[rec_num].zdf;
  1598. lpFld =(LPSTR)&HqData[jys].lpRefData[rec_num].cjje;
  1599. break;
  1600. case 15:
  1601. f =HqData[jys].lpRefData[rec_num].zdf;
  1602. HqZd =HqData[jys].lpRefData[rec_num].zjjg -
  1603. HqData[jys].lpPreData[rec_num].zrsp;
  1604. lpFld =(LPSTR)&HqZd;
  1605. break;
  1606. }
  1607. if(f >0) SetTextColor(hDC, RGB(255, 0, 0));
  1608. else if(f <0) SetTextColor(hDC, RGB(0, 255, 0));
  1609. else SetTextColor(hDC, RGB(255, 255, 255));
  1610. return lpFld;
  1611. }
  1612. LPSTR GetHqFldPos1(int jys, int rec_num, int fld_num)
  1613. {
  1614. long l;
  1615. if(HqData[jys].lpPreData[rec_num].zrsp!=0)
  1616. {
  1617. HqData[jys].lpRefData[rec_num].zdf=
  1618. (HqData[jys].lpRefData[rec_num].zjjg-HqData[jys].lpPreData[rec_num].zrsp)*100/
  1619. HqData[jys].lpPreData[rec_num].zrsp;
  1620. }
  1621. switch(fld_num)
  1622. {
  1623. case 0:
  1624. return (LPSTR)&HqData[jys].lpPreData[rec_num].zqdm[0];
  1625. case 1:
  1626. return (LPSTR)&HqData[jys].lpPreData[rec_num].zrsp;
  1627. case 2:
  1628. return (LPSTR)&HqData[jys].lpPreData[rec_num].jrkp;
  1629. case 3:
  1630. return (LPSTR)&HqData[jys].lpRefData[rec_num].zgjg;
  1631. case 4:
  1632. return (LPSTR)&HqData[jys].lpRefData[rec_num].zdjg;
  1633. case 5:
  1634. return (LPSTR)&HqData[jys].lpRefData[rec_num].zgjm;
  1635. case 6:
  1636. return (LPSTR)&HqData[jys].lpRefData[rec_num].zdjm;
  1637. case 7:
  1638. return (LPSTR)&HqData[jys].lpRefData[rec_num].zjjg;
  1639. case 8:
  1640. return (LPSTR)&HqData[jys].lpRefData[rec_num].zdf;
  1641. case 9:
  1642. return (LPSTR)&HqData[jys].lpRefData[rec_num].cjss;
  1643. case 10:
  1644. return (LPSTR)&HqData[jys].lpRefData[rec_num].lc;
  1645. case 11:
  1646. return (LPSTR)&HqData[jys].lpRefData[rec_num].npzl;
  1647. case 12:
  1648. l =HqData[jys].lpRefData[rec_num].cjss
  1649. -HqData[jys].lpRefData[rec_num].npzl;
  1650. return (LPSTR)&l;
  1651. case 13:
  1652. return (LPSTR)&HqData[jys].lpRefData[rec_num].wb;
  1653. case 14:
  1654. return (LPSTR)&HqData[jys].lpRefData[rec_num].cjje;
  1655. case 15:
  1656. HqZd =HqData[jys].lpRefData[rec_num].zjjg -
  1657. HqData[jys].lpPreData[rec_num].zrsp;
  1658. return (LPSTR)&HqZd;
  1659. }
  1660. }
  1661. BOOL IsZsRec(int jys, int rec_num)
  1662. {
  1663. if(jys ==0)
  1664. {
  1665. if(!strncmp(HqData[jys].lpPreData[rec_num].zqdm, "99", 2))
  1666. return TRUE;
  1667. }
  1668. else
  1669. if(!strncmp(HqData[jys].lpPreData[rec_num].zqdm, "0000", 4)
  1670. && (HqData[jys].lpPreData[rec_num].zqdm[4] =='0'
  1671. ||HqData[jys].lpPreData[rec_num].zqdm[4] =='1'))
  1672. return TRUE;
  1673. return FALSE;
  1674. }
  1675. void ReadHqDataAll(void)
  1676. {
  1677. int jys, i;
  1678. char fileName[128];
  1679. HFILE hf;
  1680. OFSTRUCT os;
  1681. extern BOOL HqAllocMem(int);
  1682. HQ_REF_DATA_V202 DataV202,*lpDataV202;
  1683. i =250;
  1684. if(GraphData.lpMinPos ==NULL)
  1685. GraphData.lpMinPos =(short *)GlobalAllocPtr(GHND, i*sizeof(short));
  1686. else
  1687. GraphData.lpMinPos =(short *)GlobalReAllocPtr(GraphData.lpMinPos,
  1688. i*sizeof(short), GMEM_MOVEABLE);
  1689. if(GraphData.lpMinPos ==NULL)
  1690. {
  1691. GraphData.minEnd =0;
  1692. ErrMsg(NULL,"alloc record data memory failed!");
  1693. return;
  1694. }
  1695. if(GraphData.lpMinLc ==NULL)
  1696. GraphData.lpMinLc =(long *)GlobalAllocPtr(GHND, i*sizeof(long));
  1697. else
  1698. GraphData.lpMinLc =(long *)GlobalReAllocPtr(GraphData.lpMinLc,
  1699. i*sizeof(long), GHND);
  1700. if(GraphData.lpMinLc ==NULL)
  1701. {
  1702. GraphData.minEnd =0;
  1703. ErrMsg(NULL,"alloc record data memory failed!");
  1704. return;
  1705. }
  1706. strcpy(fileName, szDataPath);
  1707. strcat(fileName, "\dpdata.dat");
  1708. hf =OpenFile(fileName, &os, OF_SHARE_DENY_NONE|OF_READ);
  1709. if(hf !=HFILE_ERROR)
  1710. {
  1711. _lread(hf, &DpData, sizeof(DpData));
  1712. _lclose(hf);
  1713. }
  1714. for(jys =0; jys <2; jys++)
  1715. {
  1716. strcpy(fileName, szDataPath);
  1717. if(jys ==0) strcat(fileName, "\szhq.dat");
  1718. else strcat(fileName, "\shhq.dat");
  1719. hf =OpenFile(fileName, &os, OF_SHARE_DENY_NONE|OF_READ);
  1720. if(hf ==HFILE_ERROR) return;
  1721. if(_lread(hf, &HqData[jys].recCount, sizeof(int)) !=sizeof(int))
  1722. {
  1723. _lclose(hf);
  1724. return;
  1725. }
  1726. if(HqData[jys].recCount <=0)
  1727. {
  1728. _lclose(hf);
  1729. continue;
  1730. }
  1731. if(!HqAllocMem(jys))
  1732. {
  1733. _lclose(hf);
  1734. return;
  1735. }
  1736. if((long)HqData[jys].recCount *(sizeof(HQ_PRE_DATA)+sizeof(HQ_REF_DATA))+sizeof(int)
  1737. ==_filelength(hf))
  1738. {
  1739. _lread(hf, &HqData[jys].lpPreData[0], sizeof(HQ_PRE_DATA)*HqData[jys].recCount);
  1740. _lread(hf, &HqData[jys].lpRefData[0], sizeof(HQ_REF_DATA)*HqData[jys].recCount);
  1741. }
  1742. else
  1743. {   
  1744.     lpDataV202 =(HQ_REF_DATA_V202 *)malloc(sizeof(HQ_REF_DATA_V202)*HqData[jys].recCount);
  1745.     if(lpDataV202!=NULL)
  1746.     {
  1747.      if((unsigned int)(_read(hf,lpDataV202,sizeof(HQ_REF_DATA_V202)*HqData[jys].recCount))!=
  1748.      (unsigned int)(sizeof(HQ_REF_DATA_V202)*HqData[jys].recCount))
  1749.      {
  1750.      free(lpDataV202);
  1751.      lpDataV202=NULL;
  1752.      }     
  1753.     }
  1754. for(i=0;i<HqData[jys].recCount;i++)
  1755. {
  1756.     if(lpDataV202==NULL)
  1757.   _read(hf,&DataV202,sizeof(HQ_REF_DATA_V202));
  1758.   else
  1759.   memcpy(&DataV202,&lpDataV202[i],sizeof(HQ_REF_DATA_V202));
  1760.   HqData[jys].lpRefData[i].zdjg =(float)(DataV202.zdjg/100.00);
  1761.   HqData[jys].lpRefData[i].zgjg =(float)((DataV202.zgjg+DataV202.zdjg)/100.00);
  1762.   HqData[jys].lpRefData[i].zdjm =(float)((DataV202.zdjm+DataV202.zdjg)/100.00);
  1763.   HqData[jys].lpRefData[i].zgjm =(float)((DataV202.zgjm+DataV202.zdjg)/100.00);
  1764.   HqData[jys].lpRefData[i].zjjg =(float)((DataV202.zjjg+DataV202.zdjg)/100.00);
  1765.   HqData[jys].lpRefData[i].npzl =DataV202.npzl;
  1766.   HqData[jys].lpRefData[i].cjss =DataV202.npzl+DataV202.cjss;
  1767.   HqData[jys].lpRefData[i].wb =(float)(DataV202.wb/100.00);
  1768.  
  1769.   HqData[jys].lpPreData[i].zrsp =(float)((DataV202.zrsp+DataV202.zdjg)/100.00);
  1770.   HqData[jys].lpPreData[i].jrkp =(float)((DataV202.jrkp+DataV202.zdjg)/100.00);
  1771.   strcpy(HqData[jys].lpPreData[i].zqdm,DataV202.zqdm);
  1772.   strcpy(HqData[jys].lpPreData[i].zqmc,DataV202.zqmc);  
  1773. }
  1774.     if(lpDataV202!=NULL)
  1775. free(lpDataV202);
  1776. }
  1777. _lclose(hf);
  1778. }
  1779. strcpy(fileName, szDataPath);
  1780. strcat(fileName, "\maxmin.dat");
  1781. hf =OpenFile(fileName, &os, OF_SHARE_DENY_NONE|OF_READ);
  1782. if(hf !=HFILE_ERROR)
  1783. {
  1784. _lread(hf, &MaxMinData, sizeof(MaxMinData));
  1785. _lclose(hf);
  1786. }
  1787. }
  1788. void WriteHqDataAll(void)
  1789. {
  1790. int jys;
  1791. char fileName[128];
  1792. HFILE hf;
  1793. OFSTRUCT os;
  1794. strcpy(fileName, szDataPath);
  1795. strcat(fileName, "\dpdata.dat");
  1796. hf =OpenFile(fileName, &os, OF_SHARE_DENY_NONE|OF_CREATE|OF_READWRITE);
  1797. if(hf !=HFILE_ERROR)
  1798. {
  1799. _lwrite(hf, &DpData, sizeof(DpData));
  1800. _lclose(hf);
  1801. }
  1802. for(jys =0; jys <2; jys++)
  1803. {
  1804. if(HqData[jys].recCount <=0) continue;
  1805. strcpy(fileName, szDataPath);
  1806. if(jys ==0) strcat(fileName, "\szhq.dat");
  1807. else strcat(fileName, "\shhq.dat");
  1808. hf =OpenFile(fileName, &os, OF_SHARE_DENY_NONE|OF_CREATE|OF_READWRITE);
  1809. if(hf ==HFILE_ERROR) return;
  1810. if(_lwrite(hf, &HqData[jys].recCount, sizeof(int)) !=sizeof(int))
  1811. {
  1812. _lclose(hf);
  1813. return;
  1814. }
  1815. _lwrite(hf, &HqData[jys].lpPreData[0], sizeof(HQ_PRE_DATA)*HqData[jys].recCount);
  1816. _lwrite(hf, &HqData[jys].lpRefData[0], sizeof(HQ_REF_DATA)*HqData[jys].recCount);
  1817. _lclose(hf);
  1818. }
  1819. strcpy(fileName, szDataPath);
  1820. strcat(fileName, "\maxmin.dat");
  1821. hf =OpenFile(fileName, &os, OF_SHARE_DENY_NONE|OF_READ);
  1822. if(hf ==HFILE_ERROR)
  1823. {
  1824. _lwrite(hf, &MaxMinData, sizeof(MaxMinData));
  1825. _lclose(hf);
  1826. }
  1827. }
  1828. void DelOldData(void)
  1829. {
  1830. int jys;
  1831. char fileName[128];
  1832. OFSTRUCT os;
  1833. strcpy(fileName, szDataPath);
  1834. strcat(fileName, "\dpdata.dat");
  1835. unlink(fileName);
  1836. for(jys =0; jys <2; jys++)
  1837. {
  1838. strcpy(fileName, szDataPath);
  1839. if(jys ==0) strcat(fileName, "\szhq.dat");
  1840. else strcat(fileName, "\shhq.dat");
  1841. unlink(fileName);
  1842. }
  1843. strcpy(fileName, szDataPath);
  1844. strcat(fileName, "\maxmin.dat");
  1845. unlink(fileName);
  1846. _lclose(hfZx);
  1847. strcpy(fileName, szDataPath);
  1848. strcat(fileName, "\zx.txt");
  1849. unlink(fileName);
  1850. hfZx =OpenFile(fileName, &os, OF_SHARE_DENY_NONE|OF_CREATE|OF_READWRITE);
  1851. _lclose(hfZx);
  1852. sprintf(fileName,"%s\news.idx",szDataPath);
  1853. unlink(fileName);
  1854. }
  1855. void ReadHqData(int jys)
  1856. {
  1857. char fileName[128];
  1858. HFILE hf;
  1859. OFSTRUCT os;
  1860. extern BOOL HqAllocMem(int);
  1861. HQ_REF_DATA_V202 DataV202;
  1862. int i;
  1863. strcpy(fileName, szDataPath);
  1864. if(jys ==0) 
  1865. strcat(fileName, "\szhq.dat");
  1866. else 
  1867. strcat(fileName, "\shhq.dat");
  1868. hf =OpenFile(fileName, &os, OF_SHARE_DENY_NONE|OF_READ);
  1869. if(hf ==HFILE_ERROR) return;
  1870. if(_lread(hf, &HqData[jys].recCount, sizeof(int)) !=sizeof(int))
  1871. {
  1872. _lclose(hf);
  1873. return;
  1874. }
  1875. if(HqData[jys].recCount <=0)
  1876. {
  1877. _lclose(hf);
  1878. return;
  1879. }
  1880. if(!HqAllocMem(jys))
  1881. {
  1882. _lclose(hf);
  1883. return;
  1884. }
  1885. if((long)HqData[jys].recCount *(sizeof(HQ_PRE_DATA)+sizeof(HQ_REF_DATA))+sizeof(int)
  1886. ==_filelength(hf))
  1887. {
  1888. _lread(hf, &HqData[jys].lpPreData[0], sizeof(HQ_PRE_DATA)*HqData[jys].recCount);
  1889. _lread(hf, &HqData[jys].lpRefData[0], sizeof(HQ_REF_DATA)*HqData[jys].recCount);
  1890. }
  1891. else
  1892. {
  1893. for(i=0;i<HqData[jys].recCount;i++)
  1894. {
  1895.  _read(hf,&DataV202,sizeof(HQ_REF_DATA_V202));
  1896.  HqData[jys].lpRefData[i].zdjg =(float)(DataV202.zdjg/100.00);
  1897.  HqData[jys].lpRefData[i].zgjg =(float)(DataV202.zgjg/100.00)+HqData[jys].lpRefData[i].zdjg;
  1898.  HqData[jys].lpRefData[i].zdjm =(float)(DataV202.zdjm/100.00)+HqData[jys].lpRefData[i].zdjg;
  1899.  HqData[jys].lpRefData[i].zgjm =(float)(DataV202.zgjm/100.00)+HqData[jys].lpRefData[i].zdjg;
  1900.  HqData[jys].lpRefData[i].zjjg =(float)(DataV202.zjjg/100.00)+HqData[jys].lpRefData[i].zdjg;
  1901.  HqData[jys].lpRefData[i].npzl =DataV202.npzl;
  1902.  
  1903.  //HqData[jys].lpRefData[i].cjss =DataV202.npzl+DataV202.cjss;
  1904.  HqData[jys].lpRefData[i].cjss =DataV202.cjss;
  1905.  HqData[jys].lpRefData[i].cjje =DataV202.cjje;
  1906.  
  1907.  HqData[jys].lpRefData[i].wb =(float)(DataV202.wb/100.00);
  1908.  
  1909.  HqData[jys].lpPreData[i].zrsp =(float)(DataV202.zrsp/100.00)+HqData[jys].lpRefData[i].zdjg;
  1910.  HqData[jys].lpPreData[i].jrkp =(float)(DataV202.jrkp/100.00)+HqData[jys].lpRefData[i].zdjg;
  1911.  strcpy(HqData[jys].lpPreData[i].zqdm,DataV202.zqdm);
  1912.  strcpy(HqData[jys].lpPreData[i].zqmc,DataV202.zqmc);  
  1913. }
  1914. }
  1915. _lclose(hf);
  1916. }