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

金融证券系统

开发平台:

Visual C++

  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <malloc.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include <math.h>
  7. #include <commdlg.h>
  8. #include "resource.h"
  9. #include "global.h"
  10. #include "fx.h"
  11. #define SELECTED_COLOR RGB(255,0,0)
  12. extern  CHOOSECOLOR cc;
  13. extern  char *DIAGR_NAME;
  14. extern HWND ghWndFx;
  15. int DrawDiagram(HDC hDc,int CurRecPrt,int Show,PARA *Para,DATA *Data,PAINT_PARA *PaintPara,long Feature)
  16. {
  17. int i,j,k;
  18. double  fhdj,               //高密度
  19. fwdt,               //宽密度
  20. step,               //每相邻横坐标的值差
  21. repl;
  22. int fwdk,                   //一个K线的宽
  23. htitle,                 //顶标注区高
  24. ltitle,                 //顶标注区长度的一半
  25. wleft,                  //左标注区宽
  26. wtitle,                 //顶标注区长度
  27. show,                   //显示记录数
  28. coor;                   //横坐标数目
  29. long feature;               //画图特性码
  30. HPEN hPen,hDPen[20];
  31. HBRUSH hBBrush;
  32. char tmp[20];
  33. TEXTMETRIC tm;
  34. HDC hdc;
  35.     if(Para->rc.bottom ==0||Para->rc.right ==0)
  36.      return TRUE;
  37. if(hDc!=NULL) hdc =hDc;
  38. else  hdc =GetDC(ghWndFx);
  39. if(Feature==0L) feature=Para->feature;
  40. else feature=Feature;
  41. SetTextColor(hdc,RGB(200,155,0));
  42. SetBkColor(hdc,RGB(0,0,0));
  43. SetTextAlign(hdc,TA_LEFT|TA_TOP);
  44. SetBkMode(hdc, OPAQUE);
  45. SelectObject(hdc,GetStockObject(SYSTEM_FONT));
  46. SelectObject(hdc,GetStockObject(BLACK_PEN));
  47. SelectObject(hdc,GetStockObject(BLACK_BRUSH));
  48. GetTextMetrics(hdc, &tm);
  49. Rectangle(hdc,0,0,PaintPara->rc.right/2,tm.tmHeight+2);
  50. TextOut(hdc,0, 2, DIAGR_NAME, strlen(DIAGR_NAME));
  51. SetBkMode(hdc, TRANSPARENT);
  52. SelectObject(hdc, PaintPara->hFont);
  53. show =Show;
  54. if(show+CurRecPrt>Data->size) show=Data->size-CurRecPrt;
  55. SelectObject(hdc, GetStockObject(WHITE_PEN));
  56. GetTextMetrics(hdc, &tm);
  57.  
  58. htitle=(int)(tm.tmHeight+tm.tmHeight*30/100);
  59. Para->htitle =htitle;
  60. if(Fx->PaintPara.wleft==0)
  61. {
  62.      wleft=(int)(tm.tmAveCharWidth*10+tm.tmMaxCharWidth*20/100);
  63.      Fx->PaintPara.wleft=wleft;
  64.     }
  65.     else
  66.      wleft=Fx->PaintPara.wleft;
  67. //画外框
  68. if(feature&DW_FRAME&&!(feature&DW_SELE))
  69. {
  70. SelectObject(hdc,GetStockObject(BLACK_BRUSH));
  71. hPen =CreatePen(PS_SOLID, FRAME_WIDTH, RGB(200,200,200));
  72. SelectObject(hdc,hPen);
  73. SelectObject(hdc,GetStockObject(BLACK_BRUSH));
  74. Rectangle(hdc,Para->rc.left+1,Para->rc.top,
  75. Para->rc.right,Para->rc.bottom);    
  76. Rectangle(hdc,Para->rc.left+wleft,Para->rc.top,
  77. Para->rc.right,Para->rc.bottom);
  78. SelectObject(hdc, GetStockObject(BLACK_PEN));
  79. DeleteObject(hPen);    
  80. }
  81. //画选中标志
  82. SetBkMode(hdc, OPAQUE);
  83. SelectObject(hdc,GetStockObject(WHITE_PEN));
  84. if(PaintPara->object==Para->no)
  85. SelectObject(hdc,GetStockObject(GRAY_BRUSH));
  86. else
  87. SelectObject(hdc,GetStockObject(BLACK_BRUSH));
  88. Rectangle(hdc,Para->rc.left+2,Para->rc.top+1,
  89. Para->rc.left+wleft-1,Para->rc.top+htitle+2);
  90. SelectObject(hdc,GetStockObject(BLACK_BRUSH));
  91. SetBkMode(hdc, TRANSPARENT);
  92.     if(Data->size <=0||show==0)
  93.     { 
  94.         if(hDc==NULL) ReleaseDC(ghWndFx,hdc);
  95.       return FALSE;
  96.     }
  97.     if(DW_DELE&feature)
  98. SetROP2(hdc,R2_XORPEN);    
  99. SetRect(&Para->rc,Para->rc.left +FRAME_WIDTH,Para->rc.top +FRAME_WIDTH,
  100. Para->rc.right -FRAME_WIDTH,Para->rc.bottom -FRAME_WIDTH);
  101. if(DEFSHOWDOT>show)
  102. fwdt =(float)(Para->rc.right-Para->rc.left-wleft-5)/DEFSHOWDOT;
  103. else
  104. fwdt =(float)(Para->rc.right-Para->rc.left-wleft-5)/show;
  105. fwdk=(int)(fwdt*80/100);
  106.     
  107. Para->fwdt =fwdt;
  108. //计算最大值
  109. if(feature&DW_MAX)
  110. {
  111. Para->price[0]=0;
  112. for(i=CurRecPrt; i<CurRecPrt+show; i++)
  113.      for(j=0;j<Data->num;j++)
  114.      {
  115. //if(Para->color[j]==0)
  116. // continue;     
  117. if(Para->price[0]<Data->v[j][i]) 
  118. Para->price[0]=Data->v[j][i];
  119. }
  120. }
  121. }
  122. //计算最小值
  123. if(feature&DW_MIN)
  124. {
  125. Para->price[1]=Para->price[0];    
  126. for(i=CurRecPrt; i<CurRecPrt+show; i++)
  127.      for(j=0;j<Data->num;j++)
  128.      {
  129.      if(Para->color[j]==0&&Data->method[0]==VOULMN_BAR_METHOD)
  130.      continue;
  131. if(Para->price[1]>Data->v[j][i]&&Data->v[j][i]!=0) 
  132. Para->price[1]=Data->v[j][i];
  133. }
  134. }
  135. }
  136. //if(Para->price[0]==0||Para->price[0]==Para->price[1])
  137. if(Para->price[0]==Para->price[1])
  138. fhdj=1;
  139. else
  140. fhdj =(double)(Para->rc.bottom-Para->rc.top-htitle)/(double)(Para->price[0]-Para->price[1]);
  141. Para->fhdj =fhdj;
  142. //标顶部数据名称
  143. SetTextAlign(hdc, TA_LEFT|TA_TOP);
  144. wtitle =(Para->rc.right-wleft -5)/4;
  145. ltitle =wtitle/2;
  146. for(i=0,j=0;i<10;i++)
  147. {
  148. if(strlen(Para->pname[i])==0)
  149. continue;
  150. strcpy(tmp,Para->pname[i]);
  151. Para->xtitle[j]=j*wtitle +5;
  152. if(feature&DW_NAME)
  153. {
  154. if((feature&DW_DELE|feature&DW_SELE)&&GetSerial(feature)==i)
  155. SetTextColor(hdc,SELECTED_COLOR);
  156. else
  157. SetTextColor(hdc,Para->color[i]);
  158. TextOut(hdc,Para->xtitle[j]+wleft,Para->rc.top+2,
  159. tmp,strlen(tmp));
  160. }
  161. Para->xtitle[j]+=ltitle+wleft;
  162. j++;
  163. }
  164. //标左边坐标
  165. coor =5;
  166. step = (Para->price[0]-Para->price[1])/coor;
  167. while(step*fhdj<tm.tmHeight&&coor>0)
  168. {
  169. coor--;
  170. if(coor==0) 
  171. {
  172. step =0;
  173. coor =1;
  174. break;
  175. }
  176. step = (Para->price[0]-Para->price[1])/coor;
  177. }
  178. SetViewportOrg(hdc, Para->rc.left+wleft,
  179. (int)((Para->price[0]-Para->price[1])*fhdj)+Para->rc.top+htitle);
  180. SetTextAlign(hdc, TA_RIGHT|TA_TOP);
  181. if(feature&DW_SELE|feature&DW_DELE)
  182. SetTextColor(hdc,SELECTED_COLOR);
  183.     else
  184. SetTextColor(hdc, RGB(255, 255, 0));
  185. SelectObject(hdc, PaintPara->hFont);
  186. for(i=1;i<=coor&&(feature&DW_LEFT);i++)
  187. {
  188. MoveTo(hdc,0,(int)(-1*(step*fhdj*i)));
  189. hLineTo(hdc,Para->rc.right-wleft-FRAME_WIDTH,(int)(-1*(step*fhdj*i)));
  190. if(Data->method[0]==VOULMN_BAR_METHOD)
  191. sprintf(tmp, "%.0f",Para->price[1]+step*i);
  192. else
  193. sprintf(tmp, "%.2f",Para->price[1]+step*i);
  194. TextOut(hdc, -1*FRAME_WIDTH,(int)(-1*(step*fhdj*i)), tmp, strlen(tmp));
  195. }
  196. //画警告线
  197. SetViewportOrg(hdc, Para->rc.left+wleft,
  198. (int)(Para->price[0]*fhdj)+Para->rc.top+htitle);
  199. if(feature&DW_ALERT)
  200. {   
  201. for(j=0;j<3;j++)
  202. {
  203. if(Para->price[2+j]==0) 
  204. continue;
  205. if((feature&DW_DELE|feature&DW_SELE)&&GetSerial(feature)==j)
  206. hPen=CreatePen(PS_DOT,1,SELECTED_COLOR);  
  207.      else
  208.      hPen=CreatePen(PS_DOT,1,RGB(10,150,100));  
  209.      SelectObject(hdc,hPen);
  210. MoveTo(hdc,0,-1*(int)(fhdj*Para->price[2+j]));
  211. LineTo(hdc,Para->rc.right-wleft-FRAME_WIDTH,-1*(int)(fhdj*Para->price[2+j]));
  212. SelectObject(hdc, GetStockObject(BLACK_PEN));
  213. DeleteObject(hPen);
  214. }
  215. }
  216. //画0轴
  217. if(Para->price[1]<=0&&Para->price[0]>=0&&feature&DW_X_COOR)
  218. {   
  219. if(feature&DW_DELE|feature&DW_SELE)
  220. hPen=CreatePen(PS_SOLID,1,SELECTED_COLOR);  
  221.     else
  222. hPen =CreatePen(PS_SOLID, 1, RGB(65,65,65));
  223. SelectObject(hdc, hPen);         
  224. MoveTo(hdc,0,0);
  225. LineTo(hdc, Para->rc.right-wleft,0);
  226. SelectObject(hdc, GetStockObject(WHITE_PEN));
  227. DeleteObject(hPen);
  228. }
  229.     //建立画笔
  230.     for(j=0;j<20;j++)
  231.     {   
  232.      if(Para->color[j]!=0)
  233.      {   
  234. if((feature&DW_DELE|feature&DW_SELE)&&!(j/10)^GetSerial(feature))
  235. hDPen[j]=CreatePen(PS_SOLID,1,SELECTED_COLOR);  
  236.          else
  237.      hDPen[j] =CreatePen(PS_SOLID, 1, Para->color[j]);
  238.      }
  239.      else
  240.          hDPen[j] =0;
  241.     }
  242.     hBBrush=CreateSolidBrush(RGB(0,255,255));
  243.     SelectObject(hdc,GetStockObject(BLACK_BRUSH));
  244. //画分析数据线
  245. for(j=0;j<10;j++)
  246. {   
  247. if(Para->color[j]==0)
  248. continue;
  249. if(!(feature>>j&0x1))
  250. continue;
  251. //价K线
  252. if(Data->method[j] ==PRICE_BAR_METHOD&&j<7)
  253. {
  254. if(Para->color[j+3]!=0)
  255. continue;
  256. for(i =CurRecPrt,k=1; i<CurRecPrt+show; i++,k++)
  257. {
  258. if(Data->v[j][i]<Data->v[j+1][i])      //ks<ss
  259. {       
  260. SelectObject(hdc, hDPen[j]);
  261. Rectangle(hdc,(int)(fwdt*k),-(int)(Data->v[j][i]*fhdj),
  262. (int)(fwdt*k)+fwdk,-(int)(Data->v[j+1][i]*fhdj));
  263. if(Data->v[j+2][i]>Data->v[j+1][i])
  264. {
  265. MoveTo(hdc,(int)((fwdt*k)+fwdk/2),-(int)(Data->v[j+1][i]*fhdj));
  266. LineTo(hdc,(int)((fwdt*k)+fwdk/2),-(int)(Data->v[j+2][i]*fhdj));
  267. }
  268. if(Data->v[j+3][i]<Data->v[j][i])
  269. {
  270. MoveTo(hdc,(int)((fwdt*k)+fwdk/2),-(int)(Data->v[j][i]*fhdj));
  271. LineTo(hdc,(int)((fwdt*k)+fwdk/2),-(int)(Data->v[j+3][i]*fhdj));
  272. }
  273. }
  274. if(Data->v[j][i]==Data->v[j+1][i])     //ks ==ss
  275. {
  276.      SelectObject(hdc, hDPen[j]);
  277.      MoveTo(hdc,(int)(fwdt*k),-(int)(Data->v[j][i]*fhdj));
  278.      LineTo(hdc,(int)(fwdt*k)+fwdk,-(int)(Data->v[j][i]*fhdj));
  279. if(Data->v[j+2][i]>Data->v[j][i])
  280. {
  281. MoveTo(hdc,(int)((fwdt*k)+fwdk/2),-(int)(Data->v[j][i]*fhdj));
  282. LineTo(hdc,(int)((fwdt*k)+fwdk/2),-(int)(Data->v[j+2][i]*fhdj));
  283. }
  284. if(Data->v[j+3][i]<Data->v[j+1][i])
  285. {
  286. MoveTo(hdc,(int)((fwdt*k)+fwdk/2),-(int)(Data->v[j+1][i]*fhdj));
  287. LineTo(hdc,(int)((fwdt*k)+fwdk/2),-(int)(Data->v[j+3][i]*fhdj));
  288. }     
  289. }   
  290.  
  291.  
  292. if(Data->v[j][i]>Data->v[j+1][i]) //ks>ss
  293. {    
  294. SelectObject(hdc, hDPen[10+j]);
  295. SelectObject(hdc,hBBrush);
  296. Rectangle(hdc,(int)(fwdt*k),-(int)(Data->v[j+1][i]*fhdj),
  297. (int)(fwdt*k)+fwdk,-(int)(Data->v[j][i]*fhdj));
  298. if(Data->v[j+2][i]>Data->v[j][i])
  299. {                              
  300. MoveTo(hdc,(int)((fwdt*k)+fwdk/2),-(int)(Data->v[j][i]*fhdj));
  301. LineTo(hdc,(int)((fwdt*k)+fwdk/2),-(int)(Data->v[j+2][i]*fhdj));
  302. }
  303. if(Data->v[j+3][i]<Data->v[j+1][i])
  304. {
  305. MoveTo(hdc,(int)((fwdt*k)+fwdk/2),-(int)(Data->v[j+1][i]*fhdj));
  306. LineTo(hdc,(int)((fwdt*k)+fwdk/2),-(int)(Data->v[j+3][i]*fhdj));
  307. }
  308. SelectObject(hdc,GetStockObject(BLACK_BRUSH));
  309. }
  310.     }
  311. }
  312. //方形
  313. if(Data->method[j] ==VOULMN_BAR_METHOD)
  314. {
  315. for(i =CurRecPrt,k=1; i<CurRecPrt+show; i++,k++)
  316. {
  317. if(Data->v[j+1][i]<=0)
  318. {       
  319. SelectObject(hdc, hDPen[j]);
  320. if(fwdk>0)
  321. Rectangle(hdc,(int)(fwdt*k),-(int)(Data->v[j][i]*fhdj),
  322. (int)(fwdt*k)+fwdk,-(int)(Para->price[1]*fhdj));
  323. else
  324. {
  325. MoveTo(hdc,(int)(fwdt*k+fwdk/2),-(int)(Para->price[1]*fhdj));
  326. LineTo(hdc,(int)(fwdt*k+fwdk/2),-(int)(Data->v[j][i]*fhdj));
  327. }
  328. }
  329. if(Data->v[j+1][i]>0)
  330. {    
  331. SelectObject(hdc, hDPen[10+j]);
  332. SelectObject(hdc,hBBrush);
  333. if(fwdk>0)
  334. Rectangle(hdc,(int)(fwdt*k),-(int)(Data->v[j][i]*fhdj),
  335. (int)(fwdt*k)+fwdk,-(int)(Para->price[1]*fhdj));
  336. else
  337. {
  338. MoveTo(hdc,(int)(fwdt*k+fwdk/2),-(int)(Para->price[1]*fhdj));
  339. LineTo(hdc,(int)(fwdt*k+fwdk/2),-(int)(Data->v[j][i]*fhdj));
  340. }
  341. SelectObject(hdc,GetStockObject(BLACK_BRUSH));
  342. }
  343.         
  344. }
  345. }
  346. //曲线
  347. if(Data->method[j] ==CURVE_METHOD)
  348. {
  349. for(i=CurRecPrt,k=1;i<CurRecPrt+show&&Data->v[j][i]==0;i++,k++);
  350. if(i<CurRecPrt+show)
  351. {
  352. if(Data->v[j][i]<Para->price[1])
  353. repl =Para->price[1];
  354. else if(Data->v[j][i]>Para->price[0])
  355.      repl =Para->price[0];
  356.      else
  357.      repl =Data->v[j][i];
  358. MoveTo(hdc,(int)(fwdt*k+fwdk/2),(int)(-1*fhdj*repl));
  359. SelectObject(hdc,hDPen[j]);
  360. for(; i<CurRecPrt+show; i++,k++)
  361. {    
  362. if(Data->v[j][i]<Para->price[1])
  363. repl =Para->price[1];
  364. else if(Data->v[j][i]>Para->price[0])
  365.      repl =Para->price[0];
  366.      else
  367.      repl =Data->v[j][i];
  368.          LineTo(hdc,(int)(fwdt*k+fwdk/2),-1*(int)(fhdj*repl));
  369. }
  370. }
  371.     }
  372. //画柱线
  373. if(Data->method[j] ==VERT_LINE_METHOD)
  374. {
  375. for(i=CurRecPrt,k=1; i<CurRecPrt+show; i++,k++)
  376. {   
  377. if(Data->v[j][i]==0) continue;
  378.      if(Data->v[j][i]>=0)
  379.      SelectObject(hdc,hDPen[j]);
  380.      else
  381.      SelectObject(hdc,hDPen[10+j]);
  382.      if(Para->price[1]<=0)
  383. MoveTo(hdc,(int)(fwdt*k)+fwdk/2,0);
  384. else
  385.     MoveTo(hdc,(int)(fwdt*k)+fwdk/2,-1*(int)(Para->price[1]*fhdj));
  386.          LineTo(hdc,(int)(fwdt*k)+fwdk/2,-1*(int)(Data->v[j][i]*fhdj));
  387. }
  388. }
  389. }
  390. SetViewportOrg(hdc, 0, 0); 
  391. SetTextAlign(hdc, TA_LEFT|TA_TOP);
  392. for(i=0,j=0;i<10&&(feature&DW_TOP);i++) 
  393. {   
  394. if(strlen(Para->pname[i])==0)
  395. continue;
  396. if(Para->color[i]==0)
  397. continue;
  398. if((feature&DW_DELE|feature&DW_SELE)&&GetSerial(feature)==i)
  399. SetTextColor(hdc,SELECTED_COLOR);
  400. else
  401. SetTextColor(hdc,Para->color[i]);
  402. if(Data->method[0]==VOULMN_BAR_METHOD)
  403.     sprintf(tmp,"%.0f",Data->v[i][CurRecPrt+show -1]);
  404. else
  405. sprintf(tmp,"%.2f",Data->v[i][CurRecPrt+show -1]);
  406. TextOut(hdc,Para->xtitle[j],Para->rc.top+2,
  407. tmp,strlen(tmp));
  408. j++;
  409. }
  410. SelectObject(hdc, GetStockObject(BLACK_BRUSH));
  411. DeleteObject(hBBrush);
  412. SelectObject(hdc, GetStockObject(BLACK_PEN));
  413.     for(j=0;j<20;j++)
  414.     {   
  415.      if(hDPen[j]!=0)
  416. DeleteObject(hDPen[j]);
  417.     }
  418. SetRect(&Para->rc,Para->rc.left -FRAME_WIDTH,Para->rc.top -FRAME_WIDTH,
  419. Para->rc.right +FRAME_WIDTH,Para->rc.bottom +FRAME_WIDTH);
  420.     if(hDc==NULL)
  421.      ReleaseDC(ghWndFx,hdc);    
  422.     else
  423.      SetROP2(hDc, R2_COPYPEN);
  424. return TRUE;
  425. }
  426. long GetObjectItem(int x,int y,int CurRecPrt,int Show,PARA *Para,DATA *Data,PAINT_PARA *PaintPara)
  427. {
  428. int i,j,k;
  429. double  fhdj,               //高密度
  430. fwdt,               //宽密度
  431. repl,
  432. v;
  433. int fwdk,                   //一个K线的宽
  434. htitle,                 //顶标注区高
  435. ltitle,                 //顶标注区长度的一半
  436. wleft,                  //左标注区宽
  437. wtitle,                 //顶标注区长度
  438. show;                   //显示记录数
  439. POINT pt;
  440. RECT rc;
  441. //初始化变量
  442. fhdj =Para->fhdj;
  443. fwdt =Para->fwdt;
  444. if(fhdj==0||fwdt==0) return(DW_NULL);
  445. fwdk = (int)(fwdt*80/100);
  446. htitle =Para->htitle;
  447. ltitle =(Para->xtitle[1] -Para->xtitle[0])/2;
  448. wleft =Fx->PaintPara.wleft;
  449. wtitle = Para->xtitle[1] -Para->xtitle[0];
  450. show =Show;
  451. pt.x =x;
  452. pt.y =y;
  453.     
  454.     
  455. //外框
  456. for(i=0;i<5;i++)
  457. if(i==0)
  458. SetRect(&rc,Para->rc.left,Para->rc.top,Para->rc.left+2,Para->rc.bottom);
  459. if(i==1)
  460. SetRect(&rc,Para->rc.left,Para->rc.top,Para->rc.right+2,Para->rc.top+2);
  461. if(i==2)
  462.     SetRect(&rc,Para->rc.right-2,Para->rc.top,Para->rc.right,Para->rc.bottom);
  463. if(i==3)
  464.     SetRect(&rc,Para->rc.left,Para->rc.bottom-2,Para->rc.right,Para->rc.bottom);
  465. if(i==4)
  466.     SetRect(&rc,Para->rc.left+wleft,Para->rc.top,Para->rc.left+wleft+2,Para->rc.bottom);
  467. if(PtInRect(&rc,pt))
  468. return(SetSerial((long)i,DW_FRAME));
  469. }
  470. //选中标志
  471. SetRect(&rc,Para->rc.left+2,Para->rc.top+1,Para->rc.left+wleft-1,
  472. Para->rc.top+htitle+2);
  473. if(PtInRect(&rc,pt))
  474. return DW_SELE;
  475. SetRect(&Para->rc,Para->rc.left +FRAME_WIDTH,Para->rc.top +FRAME_WIDTH,
  476. Para->rc.right -FRAME_WIDTH,Para->rc.bottom -FRAME_WIDTH);
  477. //标顶部数据名称
  478. for(i=0,j=0;i<10;i++)
  479. {
  480. if(strlen(Para->pname[i])==0)
  481. continue; 
  482. SetRect(&rc,Para->xtitle[j]-ltitle,Para->rc.top+2,Para->xtitle[j],
  483. Para->rc.top+htitle);
  484. if(PtInRect(&rc,pt))
  485. {
  486. SetRect(&Para->rc,Para->rc.left -FRAME_WIDTH,Para->rc.top -FRAME_WIDTH,
  487. Para->rc.right +FRAME_WIDTH,Para->rc.bottom +FRAME_WIDTH);
  488. return(SetSerial((long)(i),DW_NAME));
  489. }
  490. j++;
  491. }
  492. //标左边坐标
  493. SetRect(&rc,5,Para->rc.top+htitle+2,wleft-2,Para->rc.bottom-2);
  494. if(PtInRect(&rc,pt))
  495. {
  496. SetRect(&Para->rc,Para->rc.left -FRAME_WIDTH,Para->rc.top -FRAME_WIDTH,
  497. Para->rc.right +FRAME_WIDTH,Para->rc.bottom +FRAME_WIDTH);
  498. return DW_LEFT;
  499. }
  500. //警告线
  501. pt.x =x-(Para->rc.left+wleft);
  502. pt.y =y-((int)(Para->price[0]*fhdj)+Para->rc.top+htitle);
  503. if(pt.x>0&&pt.x<Para->rc.right-wleft-FRAME_WIDTH)
  504. {
  505. for(j=0;j<3;j++)
  506. {
  507. if(Para->price[2+j]==0) 
  508. continue;
  509. if(pt.y==-1*(int)(fhdj*Para->price[2+j]))
  510. {
  511. SetRect(&Para->rc,Para->rc.left -FRAME_WIDTH,Para->rc.top -FRAME_WIDTH,
  512. Para->rc.right +FRAME_WIDTH,Para->rc.bottom +FRAME_WIDTH);
  513. return(SetSerial((long)j,DW_ALERT));
  514. }
  515. }
  516. }
  517. //0轴
  518. if(Para->price[1]<=0&&Para->price[0]>=0)
  519. {
  520. if(pt.x>0&&pt.x<Para->rc.right-wleft&&pt.y==0)
  521. {
  522. SetRect(&Para->rc,Para->rc.left -FRAME_WIDTH,Para->rc.top -FRAME_WIDTH,
  523. Para->rc.right +FRAME_WIDTH,Para->rc.bottom +FRAME_WIDTH);
  524. return DW_X_COOR;
  525. }
  526. }
  527. //pt.x=(int)(fwdt*k+fwdk/2)
  528. k=(int)((pt.x-fwdk/2)/fwdt) +1;
  529. v =-pt.y/fhdj;
  530. i=CurRecPrt +k -1;
  531. //分析数据线
  532. for(j=0;j<10&&k<=show&&k>0;j++)
  533. {   
  534. if(Para->color[j]==0)
  535. continue;
  536. //价K线
  537. if(Data->method[j] ==PRICE_BAR_METHOD&&j<7)
  538. {
  539. if(Para->color[j+3]!=0)
  540. continue;
  541. if(Data->v[j][i]<Data->v[j+1][i])      //ks<ss
  542. {       
  543. SetRect(&rc,(int)(fwdt*k),-(int)(Data->v[j+1][i]*fhdj),
  544. (int)(fwdt*k)+fwdk,-(int)(Data->v[j][i]*fhdj));
  545. if(PtInRect(&rc,pt))
  546. {
  547. SetRect(&Para->rc,Para->rc.left -FRAME_WIDTH,Para->rc.top -FRAME_WIDTH,
  548. Para->rc.right +FRAME_WIDTH,Para->rc.bottom +FRAME_WIDTH);
  549.   return(SetSerial(0L,1L<<j));
  550. }
  551. //if(Data->v[j+2][i]>Data->v[j+1][i])
  552. //{
  553. // MoveTo(hdc,(int)((fwdt*k)+fwdk/2),-(int)(Data->v[j+1][i]*fhdj));
  554. // LineTo(hdc,(int)((fwdt*k)+fwdk/2),-(int)(Data->v[j+2][i]*fhdj));
  555. //}
  556. //if(Data->v[j+3][i]<Data->v[j][i])
  557. //{
  558. // MoveTo(hdc,(int)((fwdt*k)+fwdk/2),-(int)(Data->v[j][i]*fhdj));
  559. // LineTo(hdc,(int)((fwdt*k)+fwdk/2),-(int)(Data->v[j+3][i]*fhdj));
  560. //}
  561. }
  562. if(Data->v[j][i]==Data->v[j+1][i])     //ks ==ss
  563. {
  564.         if(pt.y>=-(int)(Data->v[j][i]*fhdj)-1&&         
  565.          pt.y<=-(int)(Data->v[j][i]*fhdj)-1)
  566.         {
  567.  SetRect(&Para->rc,Para->rc.left -FRAME_WIDTH,Para->rc.top -FRAME_WIDTH,
  568. Para->rc.right +FRAME_WIDTH,Para->rc.bottom +FRAME_WIDTH);
  569.  return(SetSerial(0L,1L<<j));
  570.         }
  571. }  
  572.  
  573. if(Data->v[j][i]>Data->v[j+1][i]) //ks>ss
  574. {    
  575. SetRect(&rc,(int)(fwdt*k),-(int)(Data->v[j][i]*fhdj),
  576. (int)(fwdt*k)+fwdk,-(int)(Data->v[j+1][i]*fhdj));
  577. if(PtInRect(&rc,pt))
  578. {
  579. SetRect(&Para->rc,Para->rc.left -FRAME_WIDTH,Para->rc.top -FRAME_WIDTH,
  580. Para->rc.right +FRAME_WIDTH,Para->rc.bottom +FRAME_WIDTH);
  581.  return(SetSerial(1L,1L<<j));
  582. }
  583. //if(Data->v[j+2][i]>Data->v[j][i])
  584. //{                              
  585. // MoveTo(hdc,(int)((fwdt*k)+fwdk/2),-(int)(Data->v[j][i]*fhdj));
  586. // LineTo(hdc,(int)((fwdt*k)+fwdk/2),-(int)(Data->v[j+2][i]*fhdj));
  587. //}
  588. //if(Data->v[j+3][i]<Data->v[j+1][i])
  589. //{
  590. // MoveTo(hdc,(int)((fwdt*k)+fwdk/2),-(int)(Data->v[j+1][i]*fhdj));
  591. // LineTo(hdc,(int)((fwdt*k)+fwdk/2),-(int)(Data->v[j+3][i]*fhdj));
  592. //}
  593. }
  594. }
  595. //方形
  596. if(Data->method[j] ==VOULMN_BAR_METHOD)
  597. {
  598. if(Data->v[j+1][i]<=0)
  599. {       
  600. if(fwdk>0)
  601. {
  602. SetRect(&rc,(int)(fwdt*k),-(int)(Data->v[j][i]*fhdj),
  603. (int)(fwdt*k)+fwdk,-(int)(Para->price[1]*fhdj));
  604. if(PtInRect(&rc,pt)) 
  605. {
  606. SetRect(&Para->rc,Para->rc.left -FRAME_WIDTH,Para->rc.top -FRAME_WIDTH,
  607. Para->rc.right +FRAME_WIDTH,Para->rc.bottom +FRAME_WIDTH);
  608. return(1L<<j);
  609. }
  610. }
  611. else
  612. {
  613. if(pt.y<-(int)(Para->price[1]*fhdj)&&
  614. pt.y>-(int)(Data->v[j][i]*fhdj))
  615. {
  616. SetRect(&Para->rc,Para->rc.left -FRAME_WIDTH,Para->rc.top -FRAME_WIDTH,
  617. Para->rc.right +FRAME_WIDTH,Para->rc.bottom +FRAME_WIDTH);
  618. return(1L<<j);
  619. }
  620. }
  621. }
  622. if(Data->v[j+1][i]>0)
  623. {    
  624. if(fwdk>0)
  625. {
  626. SetRect(&rc,(int)(fwdt*k),-(int)(Data->v[j][i]*fhdj),
  627. (int)(fwdt*k)+fwdk,-(int)(Para->price[1]*fhdj));
  628. if(PtInRect(&rc,pt))
  629. {
  630. SetRect(&Para->rc,Para->rc.left -FRAME_WIDTH,Para->rc.top -FRAME_WIDTH,
  631. Para->rc.right +FRAME_WIDTH,Para->rc.bottom +FRAME_WIDTH);
  632. return(SetSerial(1L,1L<<j));
  633. }
  634. }
  635. else
  636. {
  637. if(pt.y<-(int)(Para->price[1]*fhdj)&&
  638. pt.y>-(int)(Data->v[j][i]*fhdj))
  639. {
  640. SetRect(&Para->rc,Para->rc.left -FRAME_WIDTH,Para->rc.top -FRAME_WIDTH,
  641. Para->rc.right +FRAME_WIDTH,Para->rc.bottom +FRAME_WIDTH);
  642. return(SetSerial(1L,1L<<j));
  643. }
  644. }
  645. }        
  646. }
  647. //曲线
  648. if(Data->method[j] ==CURVE_METHOD)
  649. {
  650. if(Data->v[j][i]<Para->price[1])
  651. repl =Para->price[1];
  652. else if(Data->v[j][i]>Para->price[0])
  653.     repl =Para->price[0];
  654.     else
  655.      repl =Data->v[j][i];
  656.     if(pt.y>=-1*(int)(fhdj*repl)-1&&pt.y<=-1*(int)(fhdj*repl)+1)
  657.     {
  658. SetRect(&Para->rc,Para->rc.left -FRAME_WIDTH,Para->rc.top -FRAME_WIDTH,
  659. Para->rc.right +FRAME_WIDTH,Para->rc.bottom +FRAME_WIDTH);     
  660. return(1L<<j); 
  661. }
  662.     }
  663. //画柱线
  664. if(Data->method[j] ==VERT_LINE_METHOD)
  665. {
  666.          if(pt.y<=0&&pt.y>=-1*(int)(Data->v[j][i]*fhdj))
  667.          {
  668. SetRect(&Para->rc,Para->rc.left -FRAME_WIDTH,Para->rc.top -FRAME_WIDTH,
  669. Para->rc.right +FRAME_WIDTH,Para->rc.bottom +FRAME_WIDTH);        
  670.          return(SetSerial(0L,1L<<j));
  671.          }
  672.          if(pt.y>=0&&pt.y<=-1*(int)(Data->v[j][i]*fhdj))
  673.          {
  674. SetRect(&Para->rc,Para->rc.left -FRAME_WIDTH,Para->rc.top -FRAME_WIDTH,
  675. Para->rc.right +FRAME_WIDTH,Para->rc.bottom +FRAME_WIDTH);        
  676.          return(SetSerial(1L,1L<<j));
  677.          }        
  678. }
  679. }
  680. pt.x=x;
  681. pt.y=y;
  682. for(i=0,j=0;i<10;i++) 
  683. {   
  684. if(strlen(Para->pname[i])==0)
  685. continue;
  686. SetRect(&rc,Para->xtitle[j],Para->rc.top+2,Para->xtitle[j]+ltitle,
  687. Para->rc.top+htitle);
  688. if(PtInRect(&rc,pt))
  689. {
  690. SetRect(&Para->rc,Para->rc.left -FRAME_WIDTH,Para->rc.top -FRAME_WIDTH,
  691. Para->rc.right +FRAME_WIDTH,Para->rc.bottom +FRAME_WIDTH);
  692. return(SetSerial((long)(i),DW_TOP));
  693. }
  694. j++;
  695. }
  696. SetRect(&Para->rc,Para->rc.left -FRAME_WIDTH,Para->rc.top -FRAME_WIDTH,
  697. Para->rc.right +FRAME_WIDTH,Para->rc.bottom +FRAME_WIDTH);
  698. return(DW_NULL);
  699. }
  700. int SetColor(HWND hwnd)
  701. {
  702. COLORREF dwCustClrs[16]={RGB(255,255,255),RGB(239,239,239),
  703. RGB(223,223,223),RGB(207,207,207),
  704. RGB(191,191,191),RGB(175,175,175),
  705. RGB(159,159,159),RGB(143,143,143),
  706. RGB(127,127,127),RGB(111,111,111),
  707. RGB( 95, 95, 95),RGB( 79, 79, 79),
  708. RGB( 63, 63, 63),RGB( 47, 47, 47),
  709. RGB( 31, 31, 31),RGB( 15, 15, 15)};
  710. memset(&cc,0,sizeof(CHOOSECOLOR));
  711. cc.lStructSize =sizeof(CHOOSECOLOR);
  712. cc.hwndOwner =hwnd;
  713. cc.hInstance =NULL;
  714. cc.rgbResult=0L;
  715. cc.lpCustColors = dwCustClrs;
  716. cc.Flags = CC_PREVENTFULLOPEN;
  717. cc.rgbResult=0L;
  718. cc.lpTemplateName =(LPSTR)NULL;
  719. if(ChooseColor(&cc))
  720. return 0; //(cc.rgbResult);
  721. else
  722. return -1;
  723. }