Dlg_ToolBar.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  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 "DlgUserManager.h"
  8. #include "Dlg_GroupManage.h"
  9. #include "ScriptSetDlg.h"
  10. #include "DlgEditPwd.h"
  11. #include "DlgQueryWarningRec.h"
  12. #include "DlgSystemLog.h"
  13. #include "DlgNoticeRec.h"
  14. #include "SystemParaSetDlg.h"
  15. #include "MainFrm.h"
  16. // CDlg_ToolBar 对话框
  17. IMPLEMENT_DYNAMIC(CDlg_ToolBar, CDialog)
  18. CDlg_ToolBar::CDlg_ToolBar(CWnd* pParent /*=NULL*/)
  19. : CDialog(CDlg_ToolBar::IDD, pParent)
  20. {
  21. }
  22. CDlg_ToolBar::~CDlg_ToolBar()
  23. {
  24. }
  25. void CDlg_ToolBar::DoDataExchange(CDataExchange* pDX)
  26. {
  27. CDialog::DoDataExchange(pDX);
  28. DDX_Control(pDX, IDC_STA_CLOCK, m_clock);
  29. }
  30. BEGIN_MESSAGE_MAP(CDlg_ToolBar, CDialog)
  31. ON_WM_PAINT()
  32. ON_WM_MOUSEMOVE()
  33. ON_WM_LBUTTONDOWN()
  34. ON_WM_LBUTTONUP()
  35. ON_WM_TIMER()
  36. END_MESSAGE_MAP()
  37. // CDlg_ToolBar 消息处理程序
  38. BOOL CDlg_ToolBar::OnInitDialog()
  39. {
  40. CDialog::OnInitDialog();
  41. // TODO: 在此添加额外的初始化
  42. char picDir[_MAX_PATH] = {0};
  43. strcpy(picDir, g_strDirectory);
  44. strcat(picDir, "\\");
  45. strcat(picDir, _BITMAPDIR);
  46. strcat(picDir, "CMSTop.bmp" );
  47. DisplayBMP( 0,0,2400,106,picDir,false );
  48. int screenx=GetSystemMetrics(SM_CXSCREEN);
  49. int screeny=GetSystemMetrics(SM_CYSCREEN);
  50. GetDlgItem(IDC_STA_CLOCK)->MoveWindow( CRect(screenx-120,5,screenx,30) );
  51. CTime time=CTime::GetCurrentTime();
  52. int nHour=time.GetHour();
  53. int nMinute=time.GetMinute();
  54. int nSecond=time.GetSecond();
  55. m_clock.SetBkColor(RGB(9,52,86));//7,58,103
  56. m_clock.SetTextColor(RGB(0,255,0));
  57. m_clock.SetClock(nHour,nMinute,nSecond);
  58. SetTimer( 1,100,NULL );
  59. return TRUE; // return TRUE unless you set the focus to a control
  60. // 异常: OCX 属性页应返回 FALSE
  61. }
  62. void CDlg_ToolBar::SetPos( int iWidth,int iHeight )
  63. {
  64. CRect rc1;
  65. rc1.left = 0;
  66. rc1.right = rc1.left+2400;
  67. rc1.top = 0;
  68. rc1.bottom = rc1.top+iHeight;
  69. this->MoveWindow( rc1 );
  70. CRect rc2;
  71. rc2.left = 0;
  72. rc2.right = 2400;
  73. rc2.top = 0;
  74. rc2.bottom = 106;
  75. GetDlgItem(IDC_STATIC1)->MoveWindow( rc2 );
  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, "CMSTop.bmp" );
  93. DisplayBMP( 0,0,2400,106,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);
  255. CRect RectVer(screenx-110,5,screenx,23);
  256. if( RectVer.PtInRect( point ) )
  257. {
  258. HCURSOR hCursor;
  259. hCursor = AfxGetApp() -> LoadCursor(IDC_HANDCUR);
  260. ::SetCursor(hCursor);
  261. return;
  262. }
  263. CRect rect[10];
  264. GetDlgItem(IDC_PIC1)->GetWindowRect( rect[0] ); ScreenToClient( &rect[0] );
  265. GetDlgItem(IDC_PIC2)->GetWindowRect( rect[1] ); ScreenToClient( &rect[1] );
  266. GetDlgItem(IDC_PIC3)->GetWindowRect( rect[2] ); ScreenToClient( &rect[2] );
  267. GetDlgItem(IDC_PIC4)->GetWindowRect( rect[3] ); ScreenToClient( &rect[3] );
  268. GetDlgItem(IDC_PIC5)->GetWindowRect( rect[4] ); ScreenToClient( &rect[4] );
  269. GetDlgItem(IDC_PIC6)->GetWindowRect( rect[5] ); ScreenToClient( &rect[5] );
  270. GetDlgItem(IDC_PIC7)->GetWindowRect( rect[6] ); ScreenToClient( &rect[6] );
  271. GetDlgItem(IDC_PIC8)->GetWindowRect( rect[7] ); ScreenToClient( &rect[7] );
  272. GetDlgItem(IDC_PIC9)->GetWindowRect( rect[8] ); ScreenToClient( &rect[8] );
  273. GetDlgItem(IDC_PIC10)->GetWindowRect( rect[9] );ScreenToClient( &rect[9] );
  274. for( int i=0;i<10;i++ )
  275. {
  276. if( rect[i].PtInRect( point ) )
  277. {
  278. HCURSOR hCursor;
  279. hCursor = AfxGetApp() -> LoadCursor(IDC_HANDCUR);
  280. ::SetCursor(hCursor);
  281. break;
  282. }
  283. }
  284. CDialog::OnMouseMove(nFlags, point);
  285. }
  286. void CDlg_ToolBar::OnLButtonDown(UINT nFlags, CPoint point)
  287. {
  288. // TODO: 在此添加消息处理程序代码和/或调用默认值
  289. int screenx=GetSystemMetrics(SM_CXSCREEN);
  290. CRect RectVer(screenx-110,5,screenx,23);
  291. if( RectVer.PtInRect( point ) )
  292. {
  293. HCURSOR hCursor;
  294. hCursor = AfxGetApp() -> LoadCursor(IDC_HANDCUR);
  295. ::SetCursor(hCursor);
  296. return;
  297. }
  298. CRect rect[10];
  299. GetDlgItem(IDC_PIC1)->GetWindowRect( rect[0] ); ScreenToClient( &rect[0] );
  300. GetDlgItem(IDC_PIC2)->GetWindowRect( rect[1] ); ScreenToClient( &rect[1] );
  301. GetDlgItem(IDC_PIC3)->GetWindowRect( rect[2] ); ScreenToClient( &rect[2] );
  302. GetDlgItem(IDC_PIC4)->GetWindowRect( rect[3] ); ScreenToClient( &rect[3] );
  303. GetDlgItem(IDC_PIC5)->GetWindowRect( rect[4] ); ScreenToClient( &rect[4] );
  304. GetDlgItem(IDC_PIC6)->GetWindowRect( rect[5] ); ScreenToClient( &rect[5] );
  305. GetDlgItem(IDC_PIC7)->GetWindowRect( rect[6] ); ScreenToClient( &rect[6] );
  306. GetDlgItem(IDC_PIC8)->GetWindowRect( rect[7] ); ScreenToClient( &rect[7] );
  307. GetDlgItem(IDC_PIC9)->GetWindowRect( rect[8] ); ScreenToClient( &rect[8] );
  308. GetDlgItem(IDC_PIC10)->GetWindowRect( rect[9] );ScreenToClient( &rect[9] );
  309. for( int i=0;i<10;i++ )
  310. {
  311. if( rect[i].PtInRect( point ) )
  312. {
  313. HCURSOR hCursor;
  314. hCursor = AfxGetApp() -> LoadCursor(IDC_CURSOR2);
  315. ::SetCursor(hCursor);
  316. break;
  317. }
  318. }
  319. CDialog::OnLButtonDown(nFlags, point);
  320. }
  321. void CDlg_ToolBar::OnLButtonUp(UINT nFlags, CPoint point)
  322. {
  323. // TODO: 在此添加消息处理程序代码和/或调用默认值
  324. CMainFrame *pMainFrm=(CMainFrame*)AfxGetApp()->m_pMainWnd;
  325. if( pMainFrm==NULL )
  326. return;
  327. int screenx=GetSystemMetrics(SM_CXSCREEN);
  328. CRect RectVer(screenx-110,5,screenx,23);
  329. if( RectVer.PtInRect( point ) )
  330. {
  331. if( pDevicesManager->m_sServerVer!="" )
  332. {
  333. HCURSOR hCursor;
  334. hCursor = AfxGetApp() -> LoadCursor(IDC_HANDCUR);
  335. ::SetCursor(hCursor);
  336. CString show;
  337. show.Format( "服务端版本 : %s \n客户端版本 : %s ",pDevicesManager->m_sServerVer,g_strVersion );
  338. MessageBox( show,0 );
  339. }
  340. return;
  341. }
  342. CRect rect[10];
  343. GetDlgItem(IDC_PIC1)->GetWindowRect( rect[0] ); ScreenToClient( &rect[0] );
  344. GetDlgItem(IDC_PIC2)->GetWindowRect( rect[1] ); ScreenToClient( &rect[1] );
  345. GetDlgItem(IDC_PIC3)->GetWindowRect( rect[2] ); ScreenToClient( &rect[2] );
  346. GetDlgItem(IDC_PIC4)->GetWindowRect( rect[3] ); ScreenToClient( &rect[3] );
  347. GetDlgItem(IDC_PIC5)->GetWindowRect( rect[4] ); ScreenToClient( &rect[4] );
  348. GetDlgItem(IDC_PIC6)->GetWindowRect( rect[5] ); ScreenToClient( &rect[5] );
  349. GetDlgItem(IDC_PIC7)->GetWindowRect( rect[6] ); ScreenToClient( &rect[6] );
  350. GetDlgItem(IDC_PIC8)->GetWindowRect( rect[7] ); ScreenToClient( &rect[7] );
  351. GetDlgItem(IDC_PIC9)->GetWindowRect( rect[8] ); ScreenToClient( &rect[8] );
  352. GetDlgItem(IDC_PIC10)->GetWindowRect( rect[9] );ScreenToClient( &rect[9] );
  353. int nType = -1;
  354. for( int i=0;i<10;i++ )
  355. {
  356. if( rect[i].PtInRect( point ) )
  357. {
  358. HCURSOR hCursor;
  359. hCursor = AfxGetApp() -> LoadCursor(IDC_HANDCUR);
  360. ::SetCursor(hCursor);
  361. nType = i;
  362. break;
  363. }
  364. }
  365. switch( nType )
  366. {
  367. case 0:
  368. //{
  369. // CHAR szMaxID[MAX_ID + 1] = {0};
  370. // CDBInterface::GetInstancePtr()->GetMaxID("t_data_rec", "id", szMaxID);
  371. //}
  372. pMainFrm->OnEvent();
  373. break;
  374. case 1:
  375. pMainFrm->OnNoticeRec();
  376. break;
  377. case 2:
  378. pMainFrm->OnSummaryLog();
  379. break;
  380. case 3:
  381. pMainFrm->OnSystemLog();
  382. break;
  383. case 4:
  384. pMainFrm->OnSingleAnalog();
  385. break;
  386. case 5:
  387. pMainFrm->OnUsers();
  388. break;
  389. case 6:
  390. pMainFrm->OnEditPwdTool();
  391. break;
  392. case 7:
  393. pMainFrm->OnSysPara();
  394. break;
  395. case 8:
  396. pMainFrm->m_wndDockPageBar1.ShowWindow(SW_SHOW);
  397. pMainFrm->m_wndDockPageBar1.SendMessage(WM_MY_INVALIDATE,0,0 );
  398. break;
  399. case 9:
  400. pMainFrm->OnSuperEnd();
  401. return;
  402. }
  403. CDialog::OnLButtonUp(nFlags, point);
  404. }
  405. void CDlg_ToolBar::OnTimer(UINT nIDEvent)
  406. {
  407. // TODO: 在此添加消息处理程序代码和/或调用默认值
  408. CTime time=CTime::GetCurrentTime();
  409. int nHour=time.GetHour();
  410. int nMinute=time.GetMinute();
  411. int nSecond=time.GetSecond();
  412. m_clock.SetClock(nHour,nMinute,nSecond);
  413. CDialog::OnTimer(nIDEvent);
  414. }