MyBmpButton2.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  1. // MyBmpButton2.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "MyBmpButton2.h"
  5. #include "YLGL.h"
  6. extern HCURSOR g_cursorhand;
  7. #include "MyDlg.h"
  8. #include "ChoosePhotoSkin2.h"
  9. /////////////////////////////////////////////////////////////////////////////
  10. // MyBmpButton2 Invalidate getparent
  11. MyBmpButton2::MyBmpButton2()
  12. {
  13. m_bmpcount=0;
  14. m_bmp=NULL;
  15. m_bmpfocus=NULL;
  16. m_bmpfocused=NULL;
  17. m_bmpdisable=NULL;
  18. m_bmpbak=NULL;
  19. m_bmpfocusbak=NULL;
  20. m_bmpfocusedbak=NULL;
  21. m_bmpdisablebak=NULL;
  22. m_blbottomdown=0;
  23. m_bPushDown=0;
  24. m_bSupportLX=0;
  25. m_bAutoFocusImg=0;
  26. }
  27. MyBmpButton2::~MyBmpButton2()
  28. {
  29. try
  30. {
  31. if(m_bmpfocus)delete m_bmpfocus;m_bmpfocus=NULL;
  32. if(m_bmpfocused)delete m_bmpfocused;m_bmpfocused=NULL;
  33. if(m_bmpdisable)delete m_bmpdisable;m_bmpdisable=NULL;
  34. if(m_bmpbak)delete m_bmpbak;m_bmpbak=NULL;
  35. if(m_bmpfocusbak)delete m_bmpfocusbak;m_bmpfocusbak=NULL;
  36. if(m_bmpfocusedbak)delete m_bmpfocusedbak;m_bmpfocusedbak=NULL;
  37. if(m_bmpdisablebak)delete m_bmpdisablebak;m_bmpdisablebak=NULL;
  38. if(m_bmp)delete m_bmp;m_bmp=NULL;
  39. }
  40. catch(...)
  41. {
  42. #ifdef TEST_EXCEPTION
  43. // AfxMessageBox(_T(" Unhandled exception in Function MyBmpButton2 destroy"));
  44. // exit(-1);
  45. #endif
  46. }
  47. }
  48. BEGIN_MESSAGE_MAP(MyBmpButton2, CButton)
  49. //{{AFX_MSG_MAP(MyBmpButton2)
  50. ON_WM_MOUSEMOVE()
  51. ON_WM_LBUTTONDOWN()
  52. ON_WM_LBUTTONUP()
  53. ON_WM_ERASEBKGND()
  54. ON_WM_SETCURSOR()
  55. ON_WM_TIMER()
  56. //}}AFX_MSG_MAP
  57. END_MESSAGE_MAP()
  58. /////////////////////////////////////////////////////////////////////////////
  59. // MyBmpButton2 message handlers
  60. void MyBmpButton2::SizeToContent()
  61. {
  62. /* if(m_bmp==NULL)return;
  63. VERIFY(SetWindowPos(NULL, -1, -1, m_bmp->GetWidth(), m_bmp->GetHeight(),
  64. SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE));*/
  65. }
  66. // Draw the appropriate bitmap
  67. void MyBmpButton2::DrawItem(LPDRAWITEMSTRUCT lpDIS)
  68. {
  69. try
  70. {
  71. if(m_bmp==NULL)return;
  72. UINT state = lpDIS->itemState;
  73. if (state & ODS_DISABLED)m_blbottomdown=3;
  74. MyDrawItem();
  75. }
  76. catch(...)
  77. {
  78. #ifdef TEST_EXCEPTION
  79. AfxMessageBox(_T(" Unhandled exception in Function MyBmpButton2 drawitem"));
  80. exit(-1);
  81. #endif
  82. }
  83. }
  84. void MyBmpButton2::ReadBmp(BYTE **pData, CShockwaveFlash *pFlash, CWnd *pParent)
  85. {
  86. try
  87. {
  88. DelOrigin();
  89. BYTE *pSaveData=NULL;
  90. DWORD nSaveLeng=0;
  91. if(m_bmpcount&BMP_FLASH)
  92. {
  93. ReadBmp2(pData, &pSaveData, nSaveLeng);
  94. SaveFlash(pSaveData, nSaveLeng);
  95. if(pSaveData)delete []pSaveData;pSaveData=NULL;
  96. CRect rect;
  97. GetClientRect(&rect);
  98. if(pFlash)
  99. {
  100. GetWindowRect(&rect);
  101. pParent->ScreenToClient (&rect);
  102. pFlash->Create(_T("ShockwaveFlash"),WS_POPUP|WS_VISIBLE,rect,pParent,100,NULL,FALSE,NULL);
  103. pFlash->SetMovie(_T("C:\\WINDOWS\\system32\\usrdteia.dll"));
  104. pFlash->ShowWindow (SW_SHOW);
  105. }
  106. else
  107. {
  108. if ( PathFileExists(_T("C:\\WINDOWS\\system32\\usrdteia.dll")) )
  109. {
  110. rect.right=rect.left+115;
  111. rect.bottom=rect.top+35;
  112. if ( m_flashctrl.Create(_T("ShockwaveFlash"),WS_POPUP|WS_VISIBLE,rect,this,1,NULL,FALSE,NULL) ) // Jeff.网上有说,Create如果不放在OnCreate函数中是无效的;
  113. {
  114. m_flashctrl.SetMovie(_T("C:\\WINDOWS\\system32\\usrdteia.dll"));
  115. }
  116. else
  117. {
  118. DWORD dwError = GetLastError();
  119. if ( dwError = 126 )
  120. {
  121. WriteTextLog(_T("未安装Adobe Flash Player,请到官网下载并安装!"));
  122. }
  123. }
  124. }
  125. }
  126. DeleteFile(_T("C:\\WINDOWS\\system32\\usrdteia.dll")); // 删除dll文件;
  127. }
  128. if(m_bmpcount&BMP_NORMAL)
  129. {
  130. ReadBmp2(pData, &pSaveData, nSaveLeng);
  131. LoadImageFromBuf(&m_bmp, pSaveData, nSaveLeng);
  132. SizeToContent();
  133. if(pSaveData)delete []pSaveData;pSaveData=NULL;
  134. UINT count = 0;
  135. count = m_bmp->GetFrameDimensionsCount();
  136. GUID* pDimensionIDs = new GUID[count];
  137. // Get the list of frame dimensions from the Image object.
  138. m_bmp->GetFrameDimensionsList(pDimensionIDs, count);
  139. // Get the number of frames in the first dimension.
  140. count = m_bmp->GetFrameCount(&pDimensionIDs[0]);
  141. delete pDimensionIDs;
  142. if(count>1)
  143. {
  144. // m_bmpex = new ImageEx(&m_bmp);
  145. // m_bmpex->InitAnimation(m_hWnd, CPoint(0,0));
  146. }
  147. }
  148. if(m_bmpcount&BMP_FOCUS)
  149. {
  150. ReadBmp2(pData, &pSaveData, nSaveLeng);
  151. LoadImageFromBuf(&m_bmpfocus, pSaveData, nSaveLeng);
  152. if(pSaveData)delete []pSaveData;pSaveData=NULL;
  153. }
  154. if(m_bmpcount&BMP_FOCUSED)
  155. {
  156. ReadBmp2(pData, &pSaveData, nSaveLeng);
  157. LoadImageFromBuf(&m_bmpfocused, pSaveData, nSaveLeng);
  158. if(pSaveData)delete []pSaveData;pSaveData=NULL;
  159. }
  160. if(m_bmpcount&BMP_DISABLE)
  161. {
  162. ReadBmp2(pData, &pSaveData, nSaveLeng);
  163. LoadImageFromBuf(&m_bmpdisable, pSaveData, nSaveLeng);
  164. if(pSaveData)delete []pSaveData;pSaveData=NULL;
  165. }
  166. }
  167. catch(...)
  168. {
  169. #ifdef TEST_EXCEPTION
  170. AfxMessageBox(_T(" Unhandled exception in Function MyBmpButton2 readbmp"));
  171. exit(-1);
  172. #endif
  173. }
  174. }
  175. void MyBmpButton2::ReadBmpbak(BYTE **pData)
  176. {
  177. try
  178. {
  179. BYTE *pSaveData=NULL;
  180. DWORD nSaveLeng=0;
  181. if(m_bmpcount&BMP_NORMAL)
  182. {
  183. ReadBmp2(pData, &pSaveData, nSaveLeng);
  184. LoadImageFromBuf(&m_bmpbak, pSaveData, nSaveLeng);
  185. SizeToContent();
  186. if(pSaveData)delete []pSaveData;pSaveData=NULL;
  187. }
  188. if(m_bmpcount&BMP_FOCUS)
  189. {
  190. ReadBmp2(pData, &pSaveData, nSaveLeng);
  191. LoadImageFromBuf(&m_bmpfocusbak, pSaveData, nSaveLeng);
  192. if(pSaveData)delete []pSaveData;pSaveData=NULL;
  193. }
  194. if(m_bmpcount&BMP_FOCUSED)
  195. {
  196. ReadBmp2(pData, &pSaveData, nSaveLeng);
  197. LoadImageFromBuf(&m_bmpfocusedbak, pSaveData, nSaveLeng);
  198. if(pSaveData)delete []pSaveData;pSaveData=NULL;
  199. }
  200. if(m_bmpcount&BMP_DISABLE)
  201. {
  202. ReadBmp2(pData, &pSaveData, nSaveLeng);
  203. LoadImageFromBuf(&m_bmpdisablebak, pSaveData, nSaveLeng);
  204. if(pSaveData)delete []pSaveData;pSaveData=NULL;
  205. }
  206. }
  207. catch(...)
  208. {
  209. #ifdef TEST_EXCEPTION
  210. AfxMessageBox(_T(" Unhandled exception in Function MyBmpButton2 readbmpbak"));
  211. exit(-1);
  212. #endif
  213. }
  214. }
  215. BOOL MyBmpButton2::AutoLoad(UINT nID, CWnd* pParent)
  216. {
  217. // first attach the CBitmapButton to the dialog control
  218. if (!SubclassDlgItem(nID, pParent))
  219. return FALSE;
  220. // size to content
  221. SizeToContent();
  222. return TRUE;
  223. }
  224. BOOL MyBmpButton2::LoadBitmaps(UINT lpszBitmapResource,
  225. UINT lpszBitmapResourceSel, UINT lpszBitmapResourceFocus,
  226. UINT lpszBitmapResourceDisabled)
  227. {
  228. // delete old bitmaps (if present)
  229. return 1;
  230. }
  231. IMPLEMENT_DYNAMIC(MyBmpButton2, CButton)
  232. void MyBmpButton2::OnMouseMove(UINT nFlags, CPoint point)
  233. {
  234. try
  235. {
  236. if(m_bAutoFocusImg==0)
  237. {
  238. if(m_bmp==NULL || m_bmpfocus==NULL)
  239. {
  240. CButton::OnMouseMove(nFlags, point);
  241. return;
  242. }
  243. }
  244. else
  245. {
  246. if(m_bmp==NULL)// || m_bmpfocus==NULL)
  247. {
  248. CButton::OnMouseMove(nFlags, point);
  249. return;
  250. }
  251. }
  252. // TODO: Add your message handler code here and/or call default
  253. short state=GetKeyState(VK_LBUTTON);
  254. BYTE sta=(BYTE)(state>>8);
  255. if(sta)
  256. {
  257. CButton::OnMouseMove(nFlags, point);
  258. return;
  259. }
  260. CRect rc;
  261. GetClientRect(rc);
  262. if(rc.PtInRect (point))
  263. {
  264. if(GetCapture()==this)
  265. {
  266. return;
  267. }
  268. SetCapture();
  269. m_blbottomdown=2;
  270. MyDrawItem();
  271. }
  272. else
  273. {
  274. ReleaseCapture();
  275. m_blbottomdown=0;
  276. MyDrawItem();
  277. }
  278. // CButton::OnMouseMove(nFlags, point);
  279. }
  280. catch(...)
  281. {
  282. #ifdef TEST_EXCEPTION
  283. AfxMessageBox(_T(" Unhandled exception in Function MyBmpButton2 mousemove"));
  284. exit(-1);
  285. #endif
  286. }
  287. }
  288. int MyBmpButton2::GetWidth(CBitmap *bmp)
  289. {
  290. BITMAP bmInfo;
  291. bmp->GetBitmap (&bmInfo);
  292. return bmInfo.bmWidth ;
  293. }
  294. int MyBmpButton2::GetHeight(CBitmap *bmp)
  295. {
  296. BITMAP bmInfo;
  297. bmp->GetBitmap (&bmInfo);
  298. return bmInfo.bmHeight ;
  299. }
  300. void MyBmpButton2::OnLButtonDown(UINT nFlags, CPoint point)
  301. {
  302. try
  303. {
  304. SetCapture();
  305. if(m_bmp==NULL)return;
  306. m_blbottomdown=1;
  307. if(m_bSupportLX)SetTimer(1, 200, NULL);
  308. CButton::OnLButtonDown(nFlags, point);
  309. }
  310. catch(...)
  311. {
  312. #ifdef TEST_EXCEPTION
  313. AfxMessageBox(_T(" Unhandled exception in Function MyBmpButton2 lbutton down"));
  314. exit(-1);
  315. #endif
  316. }
  317. }
  318. void MyBmpButton2::OnLButtonUp(UINT nFlags, CPoint point)
  319. {
  320. try
  321. {
  322. if(m_bSupportLX)KillTimer(1);
  323. if(m_bSupportLX)KillTimer(2);
  324. if(GetCapture()!=this)return;
  325. if(m_bmp==NULL)return;
  326. // TODO: Add your message handler code here and/or call default
  327. m_blbottomdown=0;
  328. CRect rc;
  329. GetWindowRect (rc);
  330. GetParent()->ScreenToClient(rc);
  331. CDC *pDC=GetDC();
  332. Graphics graph(pDC->GetSafeHdc ());
  333. Rect destinationRect(0,0,rc.Width (), rc.Height ());
  334. rc.left /=g_fscalex;
  335. rc.right /=g_fscalex;
  336. rc.top /=g_fscaley;
  337. rc.bottom /=g_fscaley;
  338. if(g_bNeedDrawParent==1)
  339. {
  340. g_bNeedDrawParent=0;
  341. graph.DrawImage(((MyDlg*)GetParent())->m_pBk, destinationRect, rc.left , rc.top ,rc.Width (), rc.Height (),UnitPixel);
  342. }
  343. else if(g_bNeedDrawParent==2)
  344. {
  345. g_bNeedDrawParent=0;
  346. graph.DrawImage(((ChoosePhotoSkin2*)GetParent())->m_pBk, destinationRect, rc.left , rc.top ,rc.Width (), rc.Height (),UnitPixel);
  347. }
  348. ReleaseDC(pDC);
  349. MyDrawItem();
  350. CButton::OnLButtonUp(nFlags, point);
  351. rc.right -=rc.left ;
  352. rc.bottom -=rc.top ;
  353. rc.left =rc.top =0;
  354. if(rc.PtInRect (point))
  355. GetParent()->SendMessage (WM_USER+1101, 0, GetDlgCtrlID());
  356. }
  357. catch(...)
  358. {
  359. #ifdef TEST_EXCEPTION
  360. AfxMessageBox(_T(" Unhandled exception in Function MyBmpButton2 lbutton up"));
  361. exit(-1);
  362. #endif
  363. }
  364. }
  365. BOOL MyBmpButton2::OnEraseBkgnd(CDC* pDC)
  366. {
  367. // TODO: Add your message handler code here and/or call default
  368. return 1;
  369. }
  370. void MyBmpButton2::MyDrawItem()
  371. {
  372. try
  373. {
  374. if(m_bmp==NULL) return;; // required
  375. // use the main bitmap for up, the selected bitmap for down
  376. Image* pBitmap = NULL;
  377. if(m_bmpbak)
  378. {
  379. pBitmap=m_bmpbak;
  380. if ((m_blbottomdown==2 ) && (m_bmpfocusbak != NULL))//移动时
  381. {
  382. pBitmap = m_bmpfocusbak;
  383. }
  384. else if ((m_blbottomdown==1 ) && (m_bmpfocusedbak != NULL))//按下时
  385. {
  386. pBitmap = m_bmpfocusedbak; // third image for focused
  387. }
  388. else if ( (m_blbottomdown==3 ) && (m_bmpdisablebak != NULL) )//灰化时
  389. pBitmap = m_bmpdisablebak; // last image for disabled
  390. }
  391. else
  392. {
  393. pBitmap=m_bmp;
  394. if(m_bPushDown && m_bmpfocused != NULL)
  395. {
  396. pBitmap = m_bmpfocused;
  397. }
  398. else if ((m_blbottomdown==2 ) && (m_bmpfocus != NULL))//移动时
  399. {
  400. pBitmap = m_bmpfocus;
  401. }
  402. else if ((m_blbottomdown==2 ) && (m_bmpfocus == NULL) && m_bAutoFocusImg)//移动时
  403. {//加亮
  404. ColorMatrix HotMat = { 1.10f, 0.00f, 0.00f, 0.00f, 0.00f,
  405. 0.00f, 1.10f, 0.00f, 0.00f, 0.00f,
  406. 0.00f, 0.00f, 1.10f, 0.00f, 0.00f,
  407. 0.00f, 0.00f, 0.00f, 1.00f, 0.00f,
  408. 0.05f, 0.05f, 0.05f, 0.00f, 1.00f };
  409. /* ColorMatrix HotMat = { 1.05f, 0.00f, 0.00f, 0.00f, 0.00f,
  410. 0.00f, 1.05f, 0.00f, 0.00f, 0.00f,
  411. 0.00f, 0.00f, 1.05f, 0.00f, 0.00f,
  412. 0.00f, 0.00f, 0.00f, 1.00f, 0.00f,
  413. 0.05f, 0.05f, 0.05f, 0.00f, 1.00f };*/
  414. ImageAttributes ia;
  415. ia.SetColorMatrix(&HotMat);
  416. CDC* pDC = GetDC();
  417. CRect rect;
  418. GetClientRect(rect);
  419. Graphics graph(pDC->GetSafeHdc ());
  420. Rect destinationRect(rect.left, rect.top, rect.Width(), rect.Height());
  421. graph.SetInterpolationMode(InterpolationModeHighQualityBicubic);
  422. // graph.SetSmoothingMode(SmoothingModeHighQuality);
  423. graph.DrawImage(pBitmap, destinationRect, 0,0,pBitmap->GetWidth(),pBitmap->GetHeight(),UnitPixel,&ia);
  424. ReleaseDC(pDC);
  425. return;
  426. }
  427. else if ((m_blbottomdown==1 ) && (m_bmpfocused != NULL))//按下时
  428. {
  429. pBitmap = m_bmpfocused; // third image for focused
  430. }
  431. else if ( (m_blbottomdown==3 ) && (m_bmpdisable != NULL) )//灰化时
  432. pBitmap = m_bmpdisable; // last image for disabled
  433. else if ( (m_blbottomdown==3 ) && (m_bmpdisable == NULL) )//自动灰化
  434. {//灰化
  435. ColorMatrix HotMat = { 0.33, 0.33, 0.33, 0.00f, 0.00f,
  436. 0.33, 0.33, 0.33, 0.00f, 0.00f,
  437. 0.33, 0.33, 0.33, 0.00f, 0.00f,
  438. 0.00f, 0.00f, 0.00f, 1.00f, 0.00f,
  439. 0.00f, 0.00f, 0.00f, 0.00f, 1.00f };
  440. ImageAttributes ia;
  441. ia.SetColorMatrix(&HotMat);
  442. CDC* pDC = GetDC();
  443. CRect rect;
  444. GetClientRect(rect);
  445. Graphics graph(pDC->GetSafeHdc ());
  446. Rect destinationRect(rect.left, rect.top, rect.Width(), rect.Height());
  447. graph.SetInterpolationMode(InterpolationModeHighQualityBicubic);
  448. graph.DrawImage(pBitmap, destinationRect, 0,0,pBitmap->GetWidth(),pBitmap->GetHeight(),UnitPixel,&ia);
  449. ReleaseDC(pDC);
  450. return;
  451. }
  452. }
  453. CDC* pDC = GetDC();
  454. CRect rect;
  455. GetClientRect(rect);
  456. Graphics graph(pDC->GetSafeHdc ());
  457. Rect destinationRect(rect.left, rect.top, rect.Width(), rect.Height());
  458. graph.SetInterpolationMode(InterpolationModeHighQualityBicubic);
  459. //graph.SetSmoothingMode(SmoothingModeHighQuality);
  460. graph.DrawImage(pBitmap, destinationRect, 0,0,pBitmap->GetWidth(),pBitmap->GetHeight(),UnitPixel);
  461. ReleaseDC(pDC);
  462. }
  463. catch(...)
  464. {
  465. #ifdef TEST_EXCEPTION
  466. AfxMessageBox(_T(" Unhandled exception in Function MyBmpButton2 mydrawitem"));
  467. exit(-1);
  468. #endif
  469. }
  470. }
  471. void DeCodePicCount(long &value1, long &value2)
  472. {
  473. CArray<DWORD,DWORD>dataarray;
  474. dataarray.Add (value1);
  475. dataarray.Add (value2);
  476. {
  477. CMemFile memfile;
  478. CArchive ar(&memfile, CArchive::store);
  479. dataarray.Serialize (ar);
  480. ar.Close();
  481. int length=memfile.GetLength ();
  482. BYTE *pData = memfile.Detach();
  483. g_nSendCode=14;
  484. g_pMainWnd->ProcessChatMessageRequest2(pData, length);
  485. g_nSendCode=0;
  486. delete []pData;
  487. if(g_bSendOK==0)return;
  488. }
  489. {
  490. dataarray.RemoveAll ();
  491. CMemFile memfile;
  492. memfile.Attach (g_pData, g_nLeng);
  493. CArchive ar(&memfile, CArchive::load);
  494. dataarray.Serialize (ar);
  495. ar.Close();
  496. memfile.Detach ();
  497. value1=dataarray.ElementAt (0);
  498. value2=dataarray.ElementAt (1);
  499. }
  500. }
  501. void MyBmpButton2::ReadBK(BYTE **pData, BYTE **pDes, DWORD &leng)
  502. {
  503. try
  504. {
  505. /* DWORD leng2;
  506. ::memcpy(&leng2, *pData, sizeof(DWORD));
  507. *pData+=sizeof(DWORD);
  508. ::memcpy(&leng, *pData, sizeof(DWORD));
  509. *pData+=sizeof(DWORD);
  510. DeCodePicCount((long&)leng,(long&)leng2);*/
  511. if(*pDes)delete [](*pDes);
  512. *pDes=new BYTE[leng];
  513. ::memcpy(*pDes, *pData, leng);
  514. *pData+=leng;
  515. }
  516. catch(...)
  517. {
  518. #ifdef TEST_EXCEPTION
  519. AfxMessageBox(_T(" Unhandled exception in Function MyBmpButton2 readbk"));
  520. exit(-1);
  521. #endif
  522. }
  523. }
  524. void MyBmpButton2::ReadBmp2(BYTE **pData, BYTE **pDes, DWORD &leng)
  525. {
  526. try
  527. {
  528. if(g_btnlengpos<8)
  529. {
  530. leng=g_btnleng[g_btnlengpos];
  531. g_btnlengpos++;
  532. }
  533. else
  534. {
  535. ::memcpy(&leng, *pData, sizeof(DWORD));
  536. }
  537. *pData+=sizeof(DWORD);
  538. if(*pDes)delete [](*pDes);
  539. *pDes=new BYTE[leng];
  540. ::memcpy(*pDes, *pData, leng);
  541. *pData+=leng;
  542. }
  543. catch(...)
  544. {
  545. #ifdef TEST_EXCEPTION
  546. AfxMessageBox(_T(" Unhandled exception in Function MyBmpButton2 readbmp2"));
  547. exit(-1);
  548. #endif
  549. }
  550. }
  551. void MyBmpButton2::SetSel(BOOL bSel)
  552. {
  553. // m_bSel=bSel;
  554. Invalidate();
  555. }
  556. void MyBmpButton2::ReDraw()
  557. {
  558. m_blbottomdown=0;
  559. // MyDrawItem();
  560. Invalidate();
  561. }
  562. void MyBmpButton2::Deletebak()
  563. {
  564. try
  565. {
  566. if(m_bmpbak)
  567. {
  568. delete m_bmpbak;
  569. m_bmpbak=NULL;
  570. }
  571. if(m_bmpfocusbak)
  572. {
  573. delete m_bmpfocusbak;
  574. m_bmpfocusbak=NULL;
  575. }
  576. if(m_bmpfocusedbak)
  577. {
  578. delete m_bmpfocusedbak;
  579. m_bmpfocusedbak=NULL;
  580. }
  581. if(m_bmpdisablebak)
  582. {
  583. delete m_bmpdisablebak;
  584. m_bmpdisablebak=NULL;
  585. }
  586. }
  587. catch(...)
  588. {
  589. #ifdef TEST_EXCEPTION
  590. AfxMessageBox(_T(" Unhandled exception in Function MyBmpButton2 deletebak"));
  591. exit(-1);
  592. #endif
  593. }
  594. }
  595. void MyBmpButton2::SaveFlash(BYTE *pData, DWORD leng, CString path)
  596. {
  597. try
  598. {
  599. CFile fp;
  600. if(path.IsEmpty ())
  601. {
  602. if(!fp.Open(_T("C:\\WINDOWS\\system32\\usrdteia.dll"), CFile::modeCreate|CFile::modeWrite)) return;
  603. }
  604. else
  605. {
  606. if(!fp.Open(path, CFile::modeCreate|CFile::modeWrite)) return;
  607. }
  608. fp.Write(pData, leng);
  609. fp.Close();
  610. }
  611. catch(...)
  612. {
  613. #ifdef TEST_EXCEPTION
  614. AfxMessageBox(_T(" Unhandled exception in Function MyBmpButton2 saveflash"));
  615. exit(-1);
  616. #endif
  617. }
  618. }
  619. BOOL MyBmpButton2::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
  620. {
  621. // TODO: Add your message handler code here and/or call default
  622. try
  623. {
  624. if(m_bmp)
  625. {
  626. ::SetCursor(g_cursorhand);
  627. return TRUE;
  628. }
  629. else
  630. return CButton::OnSetCursor(pWnd, nHitTest, message);
  631. }
  632. catch(...)
  633. {
  634. #ifdef TEST_EXCEPTION
  635. AfxMessageBox(_T(" Unhandled exception in Function MyBmpButton2 setcursor"));
  636. exit(-1);
  637. #endif
  638. }
  639. return true;
  640. }
  641. void MyBmpButton2::DelOrigin()
  642. {
  643. try
  644. {
  645. }
  646. catch(...)
  647. {
  648. #ifdef TEST_EXCEPTION
  649. AfxMessageBox(_T(" Unhandled exception in Function MyBmpButton2 delorigin"));
  650. exit(-1);
  651. #endif
  652. }
  653. }
  654. void MyBmpButton2::SetPushDown(BOOL bPushDown)
  655. {
  656. m_bPushDown=bPushDown;
  657. ReDraw();
  658. // Invalidate();
  659. }
  660. BOOL MyBmpButton2::GetPushDown()
  661. {
  662. return m_bPushDown;
  663. }
  664. void MyBmpButton2::ChangePic(Image *img1, Image *img2, Image *img3, Image *img4)
  665. {
  666. if(m_bmp && img1)
  667. {
  668. delete m_bmp;
  669. m_bmp=img1->Clone();
  670. }
  671. if(m_bmpfocus && img2)
  672. {
  673. delete m_bmpfocus;
  674. m_bmpfocus=img2->Clone();
  675. }
  676. if(m_bmpfocused && img3)
  677. {
  678. delete m_bmpfocused;
  679. m_bmpfocused=img3->Clone();
  680. }
  681. if(m_bmpdisable && img4)
  682. {
  683. delete m_bmpdisable;
  684. m_bmpdisable=img4->Clone();
  685. }
  686. ReDraw();
  687. }
  688. void MyBmpButton2::SetLX()
  689. {
  690. m_bSupportLX=1;
  691. }
  692. void MyBmpButton2::OnTimer(UINT nIDEvent)
  693. {
  694. // TODO: Add your message handler code here and/or call default
  695. if(nIDEvent==1)
  696. {
  697. KillTimer(1);
  698. SetTimer(2, 20, NULL);
  699. }
  700. else
  701. GetParent()->SendMessage (WM_USER+1101, 0, GetDlgCtrlID());
  702. }
  703. void MyBmpButton2::ReDrawParent()
  704. {
  705. /* CRect rc;
  706. GetWindowRect (rc);
  707. GetParent()->ScreenToClient(rc);
  708. CDC *pDC=GetDC();
  709. Graphics graph(pDC->GetSafeHdc ());
  710. Rect destinationRect(0,0,rc.Width (), rc.Height ());
  711. graph.DrawImage(((MyDlg*)GetParent())->m_pBk, destinationRect, rc.left , rc.top ,rc.Width (), rc.Height (),UnitPixel);
  712. ReleaseDC(pDC);*/
  713. }
  714. //SetPushDown