MyBmpButton2.cpp 15 KB

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