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