Dlg_ToolBar.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. // Dlg_ToolBar.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "Dlg_ToolBar.h"
  5. #include "Global.h"
  6. #include ".\dlg_toolbar.h"
  7. //#include "ScriptSetDlg.h"
  8. #include "DlgEditPwd.h"
  9. #include "SystemParaSetDlg.h"
  10. #include "MainFrm.h"
  11. // CDlg_ToolBar 对话框
  12. IMPLEMENT_DYNAMIC(CDlg_ToolBar, CDialog)
  13. CDlg_ToolBar::CDlg_ToolBar(CWnd* pParent /*=NULL*/)
  14. : CDialog(CDlg_ToolBar::IDD, pParent)
  15. {
  16. }
  17. CDlg_ToolBar::~CDlg_ToolBar()
  18. {
  19. }
  20. void CDlg_ToolBar::DoDataExchange(CDataExchange* pDX)
  21. {
  22. CDialog::DoDataExchange(pDX);
  23. DDX_Control(pDX, IDC_STA_CLOCK, m_clock);
  24. }
  25. BEGIN_MESSAGE_MAP(CDlg_ToolBar, CDialog)
  26. ON_WM_PAINT()
  27. ON_WM_MOUSEMOVE()
  28. ON_WM_LBUTTONDOWN()
  29. ON_WM_LBUTTONUP()
  30. ON_WM_TIMER()
  31. END_MESSAGE_MAP()
  32. // CDlg_ToolBar 消息处理程序
  33. BOOL CDlg_ToolBar::OnInitDialog()
  34. {
  35. CDialog::OnInitDialog();
  36. // TODO: 在此添加额外的初始化
  37. char picDir[_MAX_PATH] = {0};
  38. strcpy(picDir, g_strDirectory);
  39. strcat(picDir, "\\");
  40. strcat(picDir, _BITMAPDIR);
  41. strcat(picDir, "topbar.bmp" );
  42. DisplayBMP( 0,0,1920,79,picDir,false );
  43. int screenx=GetSystemMetrics(SM_CXSCREEN);
  44. int screeny=GetSystemMetrics(SM_CYSCREEN);
  45. GetDlgItem(IDC_STA_CLOCK)->MoveWindow( CRect(screenx-120,5,screenx,30) );
  46. CTime time=CTime::GetCurrentTime();
  47. int nHour=time.GetHour();
  48. int nMinute=time.GetMinute();
  49. int nSecond=time.GetSecond();
  50. m_clock.SetBkColor(RGB(9,52,86));//7,58,103
  51. m_clock.SetTextColor(RGB(0,255,0));
  52. m_clock.SetClock(nHour,nMinute,nSecond);
  53. SetTimer( 1,100,NULL );
  54. return TRUE; // return TRUE unless you set the focus to a control
  55. // 异常: OCX 属性页应返回 FALSE
  56. }
  57. void CDlg_ToolBar::SetPos( int iWidth,int iHeight )
  58. {
  59. CRect rc1;
  60. rc1.left = 0;
  61. rc1.right = rc1.left+1920;
  62. rc1.top = 0;
  63. rc1.bottom = rc1.top+iHeight;
  64. this->MoveWindow( rc1 );
  65. CRect rc2;
  66. rc2.left = 0;
  67. rc2.right = 1920;
  68. rc2.top = 0;
  69. rc2.bottom = 79;
  70. GetDlgItem(IDC_STATIC1)->MoveWindow( rc2 );
  71. //_rtClient = rc1;
  72. _rtClient.left = 7;
  73. _rtClient.top = 52;
  74. _rtClient.right = 825;
  75. _rtClient.bottom = 79;
  76. //CRect rc3;
  77. //rc3.left = 0;
  78. //rc3.right = iWidth;
  79. //rc3.top = 85;
  80. //rc3.bottom = 120;
  81. //GetDlgItem(IDC_STATIC2)->MoveWindow( rc3 );
  82. }
  83. void CDlg_ToolBar::OnPaint()
  84. {
  85. CPaintDC dc(this); // device context for painting
  86. // TODO: 在此处添加消息处理程序代码
  87. // 不为绘图消息调用 CDialog::OnPaint()
  88. char picDir[_MAX_PATH] = {0};
  89. strcpy(picDir, g_strDirectory);
  90. strcat(picDir, "\\");
  91. strcat(picDir, _BITMAPDIR);
  92. strcat(picDir, "topbar.bmp" );
  93. DisplayBMP( 0,0,1920,79,picDir,false );//DisplayBMP( 0,0,2400,106,picDir,false );
  94. }
  95. BOOL CDlg_ToolBar::DisplayBMP( int nX1,int nY1,int nXX,int nYY,CString strBMPFile,BOOL bStretch )
  96. {
  97. #if 0
  98. CClientDC dc( this );
  99. GdiplusStartupInput m_gdiplusStartupInput;
  100. // ULONG_PTR m_pGdiToken;
  101. wchar_t m_wstrServerName[255] ;
  102. MultiByteToWideChar(CP_ACP,0,strBMPFile,-1,m_wstrServerName,256);
  103. Graphics graphics( dc );
  104. //wchar_t * p=strJPGFile.AllocSysStrinig();
  105. Image image( m_wstrServerName, FALSE) ;
  106. //if(bStretch)
  107. //{
  108. // StretchBlt(hDC,nX1,nY1,nXX,nYY,hMemDC,0,0,Width,Height,SRCCOPY);
  109. //}
  110. //else
  111. //{
  112. // Width = min(Width,nXX);
  113. // Height = min(Height,nYY);
  114. // BitBlt(hDC,nX1,nY1,Width,Height,hMemDC,0,0,SRCCOPY);
  115. //}
  116. if(bStretch)
  117. {
  118. graphics.DrawImage( &image, nX1,nY1,nXX,nYY );
  119. }
  120. else
  121. {
  122. WORD Width = (WORD)image.GetWidth();
  123. WORD Height = (WORD)image.GetHeight();
  124. //Width = min(Width,nXX);
  125. //Height = min(Height,nYY);
  126. //graphics.DrawImage( &image, nX1,nY1,Width,Height );
  127. graphics.DrawImage( &image, nX1,nY1,0,0,nXX,nYY,UnitPixel );
  128. }
  129. return true;
  130. #else
  131. CClientDC dc( this );
  132. OFSTRUCT of;
  133. unsigned fh = OpenFile ((char const*)strBMPFile, &of, OF_READ);
  134. if(fh==-1) return FALSE;
  135. DWORD size = (DWORD)(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
  136. HANDLE hDIBInfo = GlobalAlloc(GMEM_MOVEABLE,size);
  137. SetStretchBltMode(dc,HALFTONE);
  138. BITMAPFILEHEADER bf;
  139. LPBITMAPINFOHEADER lpbi;
  140. lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDIBInfo);
  141. _lread(fh,(LPSTR)&bf,sizeof (bf));
  142. _lread(fh,(LPSTR)lpbi,sizeof(BITMAPINFOHEADER));
  143. WORD nClrs = (WORD)lpbi->biClrUsed;
  144. size = ((((lpbi->biWidth*lpbi->biBitCount)+31)&~31)>>3)*lpbi->biHeight;
  145. if(nClrs==0 && lpbi->biBitCount!=24) nClrs = 1<<lpbi->biBitCount;
  146. if(lpbi->biClrUsed == 0) lpbi->biClrUsed = (DWORD)nClrs;
  147. if(lpbi->biSizeImage == 0) lpbi->biSizeImage = size;
  148. WORD Size = (WORD)lpbi->biSize;
  149. WORD Width = (WORD)lpbi->biWidth;
  150. WORD Height = (WORD)lpbi->biHeight;
  151. WORD ClrUsed = (WORD)lpbi->biClrUsed;
  152. WORD BitCount = (WORD)lpbi->biBitCount;
  153. DWORD SizeImage = lpbi->biSizeImage;
  154. WORD SizeRGB = nClrs*sizeof(RGBQUAD);
  155. WORD SizeHeader = Size+SizeRGB;
  156. GlobalUnlock(hDIBInfo);
  157. hDIBInfo = GlobalReAlloc(hDIBInfo,SizeHeader+SizeImage, 0);
  158. lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDIBInfo);
  159. _lread(fh,(LPSTR)(lpbi)+Size,SizeRGB);
  160. if(bf.bfOffBits!=0L) _llseek(fh,bf.bfOffBits,SEEK_SET);
  161. DWORD ul = SizeImage;
  162. BYTE *hp = (BYTE *)((LPSTR)lpbi + SizeHeader);
  163. while(ul>30000L)
  164. {
  165. _lread(fh,(LPSTR)hp,30000L);
  166. ul -= 30000L;
  167. hp += 30000L;
  168. }
  169. _lread(fh,(LPSTR)hp,(WORD)ul);
  170. _lclose(fh);
  171. HPALETTE hPalette,hOldPal;
  172. HANDLE hPalHeader = NULL;
  173. HDC hDC = dc.m_hDC;
  174. LPBITMAPINFOHEADER lpHeader = lpbi;
  175. WORD wDIBUse = DIB_RGB_COLORS;
  176. if(ClrUsed)
  177. {
  178. WORD size = sizeof(LOGPALETTE) + ClrUsed * sizeof(PALETTEENTRY);
  179. NPLOGPALETTE npPal = (NPLOGPALETTE)LocalAlloc(LMEM_FIXED,size);
  180. npPal->palVersion = 0x300;
  181. npPal->palNumEntries = ClrUsed;
  182. RGBQUAD FAR *lpRGB = (RGBQUAD FAR *)((LPSTR)lpbi + Size);
  183. for(WORD i=0;i<ClrUsed;i++,lpRGB++)
  184. {
  185. npPal->palPalEntry[i].peRed = lpRGB->rgbRed;
  186. npPal->palPalEntry[i].peGreen = lpRGB->rgbGreen;
  187. npPal->palPalEntry[i].peBlue = lpRGB->rgbBlue;
  188. npPal->palPalEntry[i].peFlags = 0;
  189. }
  190. hPalette = CreatePalette((LPLOGPALETTE)npPal);
  191. LocalFree((HANDLE)npPal);
  192. hOldPal = SelectPalette(hDC,hPalette,FALSE);
  193. RealizePalette(hDC);
  194. if(BitCount!=24)
  195. {
  196. size = Size+ClrUsed*sizeof(WORD);
  197. hPalHeader = GlobalAlloc(GMEM_MOVEABLE,size);
  198. LPBITMAPINFOHEADER lpPalInfo;
  199. lpPalInfo = (LPBITMAPINFOHEADER)GlobalLock(hPalHeader);
  200. *lpPalInfo = *lpbi;
  201. WORD FAR *lpTable = (WORD FAR *)((LPSTR)lpPalInfo + Size);
  202. for(WORD i=0;i<ClrUsed;i++) *lpTable++ = i;
  203. GlobalUnlock(hPalHeader);
  204. lpHeader = (LPBITMAPINFOHEADER) GlobalLock(hPalHeader);
  205. wDIBUse = DIB_PAL_COLORS;
  206. }
  207. }
  208. HDC hMemDC = CreateCompatibleDC(hDC);
  209. HBITMAP hDDBitmap = CreateCompatibleBitmap(hDC,Width,Height);
  210. SetDIBits(hDC,hDDBitmap,0,Height,(LPSTR)lpbi + SizeHeader,
  211. (LPBITMAPINFO)lpHeader,wDIBUse);
  212. HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMemDC,hDDBitmap);
  213. if(bStretch)
  214. {
  215. StretchBlt(hDC,nX1,nY1,nXX,nYY,hMemDC,0,0,Width,Height,SRCCOPY);
  216. }
  217. else
  218. {
  219. Width = min(Width,nXX);
  220. Height = min(Height,nYY);
  221. BitBlt(hDC,nX1,nY1,Width,Height,hMemDC,0,0,SRCCOPY);
  222. }
  223. SelectObject(hMemDC,hOldBitmap);
  224. DeleteDC(hMemDC);
  225. DeleteObject(hDDBitmap);
  226. DeleteObject( dc );
  227. if(ClrUsed)
  228. {
  229. SelectPalette(hDC,hOldPal,FALSE);
  230. DeleteObject(hPalette);
  231. if(BitCount!=24)
  232. {
  233. GlobalUnlock(hPalHeader);
  234. GlobalFree(hPalHeader);
  235. }
  236. }
  237. DeleteObject( hDC );
  238. GlobalUnlock(hDIBInfo);
  239. GlobalFree(hDIBInfo);
  240. int screenx=GetSystemMetrics(SM_CXSCREEN);
  241. CClientDC dc2( this );
  242. dc2.SetBkMode( TRANSPARENT );
  243. dc2.SetTextColor( RGB(62,132,192) );
  244. CString sShow;
  245. sShow.Format( "【ver:%s】",g_strVersion );
  246. dc2.TextOut( screenx-110,58,sShow );
  247. DeleteObject( dc2 );
  248. return TRUE;
  249. #endif
  250. }
  251. void CDlg_ToolBar::OnMouseMove(UINT nFlags, CPoint point)
  252. {
  253. // TODO: 在此添加消息处理程序代码和/或调用默认值
  254. int screenx=GetSystemMetrics(SM_CXSCREEN); // 获取屏幕宽度 [8/27/2013 Zero]
  255. //CRect RectVer(screenx-110,5,screenx,23);
  256. CRect RectVer(screenx-110,8,screenx,28);
  257. //if( RectVer.PtInRect( point ) )
  258. if( _rtClient.PtInRect( point ) )
  259. {
  260. HCURSOR hCursor;
  261. hCursor = AfxGetApp() -> LoadCursor(IDC_HANDCUR);
  262. ::SetCursor(hCursor);
  263. return;
  264. }
  265. CRect rect[10];
  266. GetDlgItem(IDC_PIC1)->GetWindowRect( rect[0] ); ScreenToClient( &rect[0] );
  267. GetDlgItem(IDC_PIC2)->GetWindowRect( rect[1] ); ScreenToClient( &rect[1] );
  268. GetDlgItem(IDC_PIC3)->GetWindowRect( rect[2] ); ScreenToClient( &rect[2] );
  269. GetDlgItem(IDC_PIC4)->GetWindowRect( rect[3] ); ScreenToClient( &rect[3] );
  270. GetDlgItem(IDC_PIC5)->GetWindowRect( rect[4] ); ScreenToClient( &rect[4] );
  271. GetDlgItem(IDC_PIC6)->GetWindowRect( rect[5] ); ScreenToClient( &rect[5] );
  272. GetDlgItem(IDC_PIC7)->GetWindowRect( rect[6] ); ScreenToClient( &rect[6] );
  273. GetDlgItem(IDC_PIC8)->GetWindowRect( rect[7] ); ScreenToClient( &rect[7] );
  274. GetDlgItem(IDC_PIC9)->GetWindowRect( rect[8] ); ScreenToClient( &rect[8] );
  275. GetDlgItem(IDC_PIC10)->GetWindowRect( rect[9] );ScreenToClient( &rect[9] );
  276. for( int i=0;i<10;i++ )
  277. {
  278. if( rect[i].PtInRect( point ) )
  279. {
  280. HCURSOR hCursor;
  281. hCursor = AfxGetApp() -> LoadCursor(IDC_HANDCUR);
  282. ::SetCursor(hCursor);
  283. break;
  284. }
  285. }
  286. CDialog::OnMouseMove(nFlags, point);
  287. }
  288. void CDlg_ToolBar::OnLButtonDown(UINT nFlags, CPoint point)
  289. {
  290. // TODO: 在此添加消息处理程序代码和/或调用默认值
  291. int screenx = GetSystemMetrics(SM_CXSCREEN);// 获取屏幕宽度 [8/27/2013 Zero]
  292. CRect RectVer(screenx-110,5,screenx,23);
  293. //if( RectVer.PtInRect( point ) )
  294. if( _rtClient.PtInRect( point ) )
  295. {
  296. HCURSOR hCursor;
  297. hCursor = AfxGetApp() -> LoadCursor(IDC_HANDCUR);
  298. ::SetCursor(hCursor);
  299. return;
  300. }
  301. CRect rect[10];
  302. GetDlgItem(IDC_PIC1)->GetWindowRect( rect[0] ); ScreenToClient( &rect[0] );
  303. GetDlgItem(IDC_PIC2)->GetWindowRect( rect[1] ); ScreenToClient( &rect[1] );
  304. GetDlgItem(IDC_PIC3)->GetWindowRect( rect[2] ); ScreenToClient( &rect[2] );
  305. GetDlgItem(IDC_PIC4)->GetWindowRect( rect[3] ); ScreenToClient( &rect[3] );
  306. GetDlgItem(IDC_PIC5)->GetWindowRect( rect[4] ); ScreenToClient( &rect[4] );
  307. GetDlgItem(IDC_PIC6)->GetWindowRect( rect[5] ); ScreenToClient( &rect[5] );
  308. GetDlgItem(IDC_PIC7)->GetWindowRect( rect[6] ); ScreenToClient( &rect[6] );
  309. GetDlgItem(IDC_PIC8)->GetWindowRect( rect[7] ); ScreenToClient( &rect[7] );
  310. GetDlgItem(IDC_PIC9)->GetWindowRect( rect[8] ); ScreenToClient( &rect[8] );
  311. GetDlgItem(IDC_PIC10)->GetWindowRect( rect[9] );ScreenToClient( &rect[9] );
  312. for( int i=0;i<10;i++ )
  313. {
  314. if( rect[i].PtInRect( point ) )
  315. {
  316. HCURSOR hCursor;
  317. hCursor = AfxGetApp() -> LoadCursor(IDC_CURSOR2);
  318. ::SetCursor(hCursor);
  319. break;
  320. }
  321. }
  322. CDialog::OnLButtonDown(nFlags, point);
  323. }
  324. void CDlg_ToolBar::OnLButtonUp(UINT nFlags, CPoint point)
  325. {
  326. // TODO: 在此添加消息处理程序代码和/或调用默认值
  327. CMainFrame *pMainFrm=(CMainFrame*)AfxGetApp()->m_pMainWnd;
  328. if( pMainFrm==NULL )
  329. return;
  330. int screenx=GetSystemMetrics(SM_CXSCREEN);// 获取屏幕宽度 [8/27/2013 Zero]
  331. CRect RectVer(screenx-110,5,screenx,23);
  332. //CRect RectVer(7,,screenx,23);
  333. CRect rect[10];
  334. GetDlgItem(IDC_PIC1)->GetWindowRect( rect[0] );
  335. ScreenToClient( &rect[0] );
  336. GetDlgItem(IDC_PIC2)->GetWindowRect( rect[1] );
  337. ScreenToClient( &rect[1] );
  338. GetDlgItem(IDC_PIC3)->GetWindowRect( rect[2] );
  339. ScreenToClient( &rect[2] );
  340. GetDlgItem(IDC_PIC4)->GetWindowRect( rect[3] );
  341. ScreenToClient( &rect[3] );
  342. GetDlgItem(IDC_PIC5)->GetWindowRect( rect[4] );
  343. ScreenToClient( &rect[4] );
  344. GetDlgItem(IDC_PIC6)->GetWindowRect( rect[5] );
  345. ScreenToClient( &rect[5] );
  346. GetDlgItem(IDC_PIC7)->GetWindowRect( rect[6] );
  347. ScreenToClient( &rect[6] );
  348. GetDlgItem(IDC_PIC8)->GetWindowRect( rect[7] );
  349. ScreenToClient( &rect[7] );
  350. GetDlgItem(IDC_PIC9)->GetWindowRect( rect[8] );
  351. ScreenToClient( &rect[8] );
  352. GetDlgItem(IDC_PIC10)->GetWindowRect( rect[9] );
  353. ScreenToClient( &rect[9] );
  354. GetDlgItem(IDC_PIC1)->GetClientRect( rect[0] );
  355. ClientToScreen(&rect[0]);
  356. GetDlgItem(IDC_PIC2)->GetClientRect( rect[1] );
  357. ClientToScreen(&rect[1]);
  358. GetDlgItem(IDC_PIC3)->GetClientRect( rect[2] );
  359. ClientToScreen(&rect[2]);
  360. GetDlgItem(IDC_PIC4)->GetClientRect( rect[3] );
  361. ClientToScreen(&rect[3]);
  362. GetDlgItem(IDC_PIC5)->GetClientRect( rect[4] );
  363. ClientToScreen(&rect[4]);
  364. GetDlgItem(IDC_PIC6)->GetClientRect( rect[5] );
  365. ClientToScreen(&rect[5]);
  366. GetDlgItem(IDC_PIC7)->GetClientRect( rect[6] );
  367. ClientToScreen(&rect[6]);
  368. GetDlgItem(IDC_PIC8)->GetClientRect( rect[7] );
  369. ClientToScreen(&rect[7]);
  370. GetDlgItem(IDC_PIC9)->GetClientRect( rect[8] );
  371. ClientToScreen(&rect[8]);
  372. GetDlgItem(IDC_PIC10)->GetClientRect( rect[9] );
  373. ClientToScreen(&rect[9]);
  374. int nType = -1;
  375. for( int i=0;i<10;i++ )
  376. {
  377. if( rect[i].PtInRect( point ) )
  378. {
  379. HCURSOR hCursor;
  380. hCursor = AfxGetApp() -> LoadCursor(IDC_HANDCUR);
  381. ::SetCursor(hCursor);
  382. nType = i;
  383. break;
  384. }
  385. }
  386. switch( nType )
  387. {
  388. case 0:
  389. //{
  390. // CHAR szMaxID[MAX_ID + 1] = {0};
  391. // CDBInterface::GetInstancePtr()->GetMaxID("t_data_rec", "id", szMaxID);
  392. //}
  393. pMainFrm->OnEvent();
  394. break;
  395. case 1:
  396. pMainFrm->OnNoticeRec();
  397. break;
  398. case 2:
  399. pMainFrm->OnSummaryLog();
  400. break;
  401. case 3:
  402. pMainFrm->OnSystemLog();
  403. break;
  404. case 4:
  405. pMainFrm->OnSingleAnalog();
  406. break;
  407. case 5:
  408. pMainFrm->OnUsers();
  409. break;
  410. case 6:
  411. pMainFrm->OnEditPwdTool();
  412. break;
  413. case 7:
  414. pMainFrm->OnSysPara();
  415. break;
  416. case 8:
  417. pMainFrm->m_hleftDockBar.ShowWindow(SW_SHOW);
  418. pMainFrm->m_hleftDockBar.SendMessage(WM_MY_INVALIDATE,0,0 );
  419. break;
  420. case 9:
  421. pMainFrm->OnSuperEnd();
  422. return;
  423. }
  424. CDialog::OnLButtonUp(nFlags, point);
  425. }
  426. void CDlg_ToolBar::OnTimer(UINT nIDEvent)
  427. {
  428. // TODO: 在此添加消息处理程序代码和/或调用默认值
  429. CTime time=CTime::GetCurrentTime();
  430. int nHour=time.GetHour();
  431. int nMinute=time.GetMinute();
  432. int nSecond=time.GetSecond();
  433. m_clock.SetClock(nHour,nMinute,nSecond);
  434. CDialog::OnTimer(nIDEvent);
  435. }