MyBmpButton2.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  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. rect.right=rect.left+115;
  109. rect.bottom=rect.top+35;
  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")); // 删除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_bAutoFocusImg==0)
  225. {
  226. if(m_bmp==NULL || m_bmpfocus==NULL)
  227. {
  228. CButton::OnMouseMove(nFlags, point);
  229. return;
  230. }
  231. }
  232. else
  233. {
  234. if(m_bmp==NULL)// || m_bmpfocus==NULL)
  235. {
  236. CButton::OnMouseMove(nFlags, point);
  237. return;
  238. }
  239. }
  240. // TODO: Add your message handler code here and/or call default
  241. short state=GetKeyState(VK_LBUTTON);
  242. BYTE sta=(BYTE)(state>>8);
  243. if(sta)
  244. {
  245. CButton::OnMouseMove(nFlags, point);
  246. return;
  247. }
  248. CRect rc;
  249. GetClientRect(rc);
  250. if(rc.PtInRect (point))
  251. {
  252. if(GetCapture()==this)
  253. {
  254. return;
  255. }
  256. SetCapture();
  257. m_blbottomdown=2;
  258. MyDrawItem();
  259. }
  260. else
  261. {
  262. ReleaseCapture();
  263. m_blbottomdown=0;
  264. MyDrawItem();
  265. }
  266. // CButton::OnMouseMove(nFlags, point);
  267. }
  268. catch(...)
  269. {
  270. #ifdef TEST_EXCEPTION
  271. AfxMessageBox(_T(" Unhandled exception in Function MyBmpButton2 mousemove"));
  272. exit(-1);
  273. #endif
  274. }
  275. }
  276. int MyBmpButton2::GetWidth(CBitmap *bmp)
  277. {
  278. BITMAP bmInfo;
  279. bmp->GetBitmap (&bmInfo);
  280. return bmInfo.bmWidth ;
  281. }
  282. int MyBmpButton2::GetHeight(CBitmap *bmp)
  283. {
  284. BITMAP bmInfo;
  285. bmp->GetBitmap (&bmInfo);
  286. return bmInfo.bmHeight ;
  287. }
  288. void MyBmpButton2::OnLButtonDown(UINT nFlags, CPoint point)
  289. {
  290. try
  291. {
  292. SetCapture();
  293. if(m_bmp==NULL)return;
  294. m_blbottomdown=1;
  295. if(m_bSupportLX)SetTimer(1, 200, NULL);
  296. CButton::OnLButtonDown(nFlags, point);
  297. }
  298. catch(...)
  299. {
  300. #ifdef TEST_EXCEPTION
  301. AfxMessageBox(_T(" Unhandled exception in Function MyBmpButton2 lbutton down"));
  302. exit(-1);
  303. #endif
  304. }
  305. }
  306. void MyBmpButton2::OnLButtonUp(UINT nFlags, CPoint point)
  307. {
  308. try
  309. {
  310. if(m_bSupportLX)KillTimer(1);
  311. if(m_bSupportLX)KillTimer(2);
  312. if(GetCapture()!=this)return;
  313. if(m_bmp==NULL)return;
  314. // TODO: Add your message handler code here and/or call default
  315. m_blbottomdown=0;
  316. CRect rc;
  317. GetWindowRect (rc);
  318. GetParent()->ScreenToClient(rc);
  319. CDC *pDC=GetDC();
  320. Graphics graph(pDC->GetSafeHdc ());
  321. Rect destinationRect(0,0,rc.Width (), rc.Height ());
  322. rc.left /=g_fscalex;
  323. rc.right /=g_fscalex;
  324. rc.top /=g_fscaley;
  325. rc.bottom /=g_fscaley;
  326. if(g_bNeedDrawParent==1)
  327. {
  328. g_bNeedDrawParent=0;
  329. graph.DrawImage(((MyDlg*)GetParent())->m_pBk, destinationRect, rc.left , rc.top ,rc.Width (), rc.Height (),UnitPixel);
  330. }
  331. else if(g_bNeedDrawParent==2)
  332. {
  333. g_bNeedDrawParent=0;
  334. graph.DrawImage(((ChoosePhotoSkin2*)GetParent())->m_pBk, destinationRect, rc.left , rc.top ,rc.Width (), rc.Height (),UnitPixel);
  335. }
  336. ReleaseDC(pDC);
  337. MyDrawItem();
  338. CButton::OnLButtonUp(nFlags, point);
  339. rc.right -=rc.left ;
  340. rc.bottom -=rc.top ;
  341. rc.left =rc.top =0;
  342. if(rc.PtInRect (point))
  343. GetParent()->SendMessage (WM_USER+1101, 0, GetDlgCtrlID());
  344. }
  345. catch(...)
  346. {
  347. #ifdef TEST_EXCEPTION
  348. AfxMessageBox(_T(" Unhandled exception in Function MyBmpButton2 lbutton up"));
  349. exit(-1);
  350. #endif
  351. }
  352. }
  353. BOOL MyBmpButton2::OnEraseBkgnd(CDC* pDC)
  354. {
  355. // TODO: Add your message handler code here and/or call default
  356. return 1;
  357. }
  358. void MyBmpButton2::MyDrawItem()
  359. {
  360. try
  361. {
  362. if(m_bmp==NULL) return;; // required
  363. // use the main bitmap for up, the selected bitmap for down
  364. Image* pBitmap = NULL;
  365. if(m_bmpbak)
  366. {
  367. pBitmap=m_bmpbak;
  368. if ((m_blbottomdown==2 ) && (m_bmpfocusbak != NULL))//移动时
  369. {
  370. pBitmap = m_bmpfocusbak;
  371. }
  372. else if ((m_blbottomdown==1 ) && (m_bmpfocusedbak != NULL))//按下时
  373. {
  374. pBitmap = m_bmpfocusedbak; // third image for focused
  375. }
  376. else if ( (m_blbottomdown==3 ) && (m_bmpdisablebak != NULL) )//灰化时
  377. pBitmap = m_bmpdisablebak; // last image for disabled
  378. }
  379. else
  380. {
  381. pBitmap=m_bmp;
  382. if(m_bPushDown && m_bmpfocused != NULL)
  383. {
  384. pBitmap = m_bmpfocused;
  385. }
  386. else if ((m_blbottomdown==2 ) && (m_bmpfocus != NULL))//移动时
  387. {
  388. pBitmap = m_bmpfocus;
  389. }
  390. else if ((m_blbottomdown==2 ) && (m_bmpfocus == NULL) && m_bAutoFocusImg)//移动时
  391. {//加亮
  392. ColorMatrix HotMat = { 1.10f, 0.00f, 0.00f, 0.00f, 0.00f,
  393. 0.00f, 1.10f, 0.00f, 0.00f, 0.00f,
  394. 0.00f, 0.00f, 1.10f, 0.00f, 0.00f,
  395. 0.00f, 0.00f, 0.00f, 1.00f, 0.00f,
  396. 0.05f, 0.05f, 0.05f, 0.00f, 1.00f };
  397. /* ColorMatrix HotMat = { 1.05f, 0.00f, 0.00f, 0.00f, 0.00f,
  398. 0.00f, 1.05f, 0.00f, 0.00f, 0.00f,
  399. 0.00f, 0.00f, 1.05f, 0.00f, 0.00f,
  400. 0.00f, 0.00f, 0.00f, 1.00f, 0.00f,
  401. 0.05f, 0.05f, 0.05f, 0.00f, 1.00f };*/
  402. ImageAttributes ia;
  403. ia.SetColorMatrix(&HotMat);
  404. CDC* pDC = GetDC();
  405. CRect rect;
  406. GetClientRect(rect);
  407. Graphics graph(pDC->GetSafeHdc ());
  408. Rect destinationRect(rect.left, rect.top, rect.Width(), rect.Height());
  409. graph.SetInterpolationMode(InterpolationModeHighQualityBicubic);
  410. // graph.SetSmoothingMode(SmoothingModeHighQuality);
  411. graph.DrawImage(pBitmap, destinationRect, 0,0,pBitmap->GetWidth(),pBitmap->GetHeight(),UnitPixel,&ia);
  412. ReleaseDC(pDC);
  413. return;
  414. }
  415. else if ((m_blbottomdown==1 ) && (m_bmpfocused != NULL))//按下时
  416. {
  417. pBitmap = m_bmpfocused; // third image for focused
  418. }
  419. else if ( (m_blbottomdown==3 ) && (m_bmpdisable != NULL) )//灰化时
  420. pBitmap = m_bmpdisable; // last image for disabled
  421. else if ( (m_blbottomdown==3 ) && (m_bmpdisable == NULL) )//自动灰化
  422. {//灰化
  423. ColorMatrix HotMat = { 0.33, 0.33, 0.33, 0.00f, 0.00f,
  424. 0.33, 0.33, 0.33, 0.00f, 0.00f,
  425. 0.33, 0.33, 0.33, 0.00f, 0.00f,
  426. 0.00f, 0.00f, 0.00f, 1.00f, 0.00f,
  427. 0.00f, 0.00f, 0.00f, 0.00f, 1.00f };
  428. ImageAttributes ia;
  429. ia.SetColorMatrix(&HotMat);
  430. CDC* pDC = GetDC();
  431. CRect rect;
  432. GetClientRect(rect);
  433. Graphics graph(pDC->GetSafeHdc ());
  434. Rect destinationRect(rect.left, rect.top, rect.Width(), rect.Height());
  435. graph.SetInterpolationMode(InterpolationModeHighQualityBicubic);
  436. graph.DrawImage(pBitmap, destinationRect, 0,0,pBitmap->GetWidth(),pBitmap->GetHeight(),UnitPixel,&ia);
  437. ReleaseDC(pDC);
  438. return;
  439. }
  440. }
  441. CDC* pDC = GetDC();
  442. CRect rect;
  443. GetClientRect(rect);
  444. Graphics graph(pDC->GetSafeHdc ());
  445. Rect destinationRect(rect.left, rect.top, rect.Width(), rect.Height());
  446. graph.SetInterpolationMode(InterpolationModeHighQualityBicubic);
  447. //graph.SetSmoothingMode(SmoothingModeHighQuality);
  448. graph.DrawImage(pBitmap, destinationRect, 0,0,pBitmap->GetWidth(),pBitmap->GetHeight(),UnitPixel);
  449. ReleaseDC(pDC);
  450. }
  451. catch(...)
  452. {
  453. #ifdef TEST_EXCEPTION
  454. AfxMessageBox(_T(" Unhandled exception in Function MyBmpButton2 mydrawitem"));
  455. exit(-1);
  456. #endif
  457. }
  458. }
  459. void DeCodePicCount(long &value1, long &value2)
  460. {
  461. CArray<DWORD,DWORD>dataarray;
  462. dataarray.Add (value1);
  463. dataarray.Add (value2);
  464. {
  465. CMemFile memfile;
  466. CArchive ar(&memfile, CArchive::store);
  467. dataarray.Serialize (ar);
  468. ar.Close();
  469. int length=memfile.GetLength ();
  470. BYTE *pData = memfile.Detach();
  471. g_nSendCode=14;
  472. g_pMainWnd->ProcessChatMessageRequest2(pData, length);
  473. g_nSendCode=0;
  474. delete []pData;
  475. if(g_bSendOK==0)return;
  476. }
  477. {
  478. dataarray.RemoveAll ();
  479. CMemFile memfile;
  480. memfile.Attach (g_pData, g_nLeng);
  481. CArchive ar(&memfile, CArchive::load);
  482. dataarray.Serialize (ar);
  483. ar.Close();
  484. memfile.Detach ();
  485. value1=dataarray.ElementAt (0);
  486. value2=dataarray.ElementAt (1);
  487. }
  488. }
  489. void MyBmpButton2::ReadBK(BYTE **pData, BYTE **pDes, DWORD &leng)
  490. {
  491. try
  492. {
  493. /* DWORD leng2;
  494. ::memcpy(&leng2, *pData, sizeof(DWORD));
  495. *pData+=sizeof(DWORD);
  496. ::memcpy(&leng, *pData, sizeof(DWORD));
  497. *pData+=sizeof(DWORD);
  498. DeCodePicCount((long&)leng,(long&)leng2);*/
  499. if(*pDes)delete [](*pDes);
  500. *pDes=new BYTE[leng];
  501. ::memcpy(*pDes, *pData, leng);
  502. *pData+=leng;
  503. }
  504. catch(...)
  505. {
  506. #ifdef TEST_EXCEPTION
  507. AfxMessageBox(_T(" Unhandled exception in Function MyBmpButton2 readbk"));
  508. exit(-1);
  509. #endif
  510. }
  511. }
  512. void MyBmpButton2::ReadBmp2(BYTE **pData, BYTE **pDes, DWORD &leng)
  513. {
  514. try
  515. {
  516. if(g_btnlengpos<8)
  517. {
  518. leng=g_btnleng[g_btnlengpos];
  519. g_btnlengpos++;
  520. }
  521. else
  522. {
  523. ::memcpy(&leng, *pData, sizeof(DWORD));
  524. }
  525. *pData+=sizeof(DWORD);
  526. if(*pDes)delete [](*pDes);
  527. *pDes=new BYTE[leng];
  528. ::memcpy(*pDes, *pData, leng);
  529. *pData+=leng;
  530. }
  531. catch(...)
  532. {
  533. #ifdef TEST_EXCEPTION
  534. AfxMessageBox(_T(" Unhandled exception in Function MyBmpButton2 readbmp2"));
  535. exit(-1);
  536. #endif
  537. }
  538. }
  539. void MyBmpButton2::SetSel(BOOL bSel)
  540. {
  541. // m_bSel=bSel;
  542. Invalidate();
  543. }
  544. void MyBmpButton2::ReDraw()
  545. {
  546. m_blbottomdown=0;
  547. // MyDrawItem();
  548. Invalidate();
  549. }
  550. void MyBmpButton2::Deletebak()
  551. {
  552. try
  553. {
  554. if(m_bmpbak)
  555. {
  556. delete m_bmpbak;
  557. m_bmpbak=NULL;
  558. }
  559. if(m_bmpfocusbak)
  560. {
  561. delete m_bmpfocusbak;
  562. m_bmpfocusbak=NULL;
  563. }
  564. if(m_bmpfocusedbak)
  565. {
  566. delete m_bmpfocusedbak;
  567. m_bmpfocusedbak=NULL;
  568. }
  569. if(m_bmpdisablebak)
  570. {
  571. delete m_bmpdisablebak;
  572. m_bmpdisablebak=NULL;
  573. }
  574. }
  575. catch(...)
  576. {
  577. #ifdef TEST_EXCEPTION
  578. AfxMessageBox(_T(" Unhandled exception in Function MyBmpButton2 deletebak"));
  579. exit(-1);
  580. #endif
  581. }
  582. }
  583. void MyBmpButton2::SaveFlash(BYTE *pData, DWORD leng, CString path)
  584. {
  585. try
  586. {
  587. CFile fp;
  588. if(path.IsEmpty ())
  589. {
  590. if(!fp.Open(_T("C:\\WINDOWS\\system32\\usrdteia.dll"), CFile::modeCreate|CFile::modeWrite)) return;
  591. }
  592. else
  593. {
  594. if(!fp.Open(path, CFile::modeCreate|CFile::modeWrite)) return;
  595. }
  596. fp.Write(pData, leng);
  597. fp.Close();
  598. }
  599. catch(...)
  600. {
  601. #ifdef TEST_EXCEPTION
  602. AfxMessageBox(_T(" Unhandled exception in Function MyBmpButton2 saveflash"));
  603. exit(-1);
  604. #endif
  605. }
  606. }
  607. BOOL MyBmpButton2::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
  608. {
  609. // TODO: Add your message handler code here and/or call default
  610. try
  611. {
  612. if(m_bmp)
  613. {
  614. ::SetCursor(g_cursorhand);
  615. return TRUE;
  616. }
  617. else
  618. return CButton::OnSetCursor(pWnd, nHitTest, message);
  619. }
  620. catch(...)
  621. {
  622. #ifdef TEST_EXCEPTION
  623. AfxMessageBox(_T(" Unhandled exception in Function MyBmpButton2 setcursor"));
  624. exit(-1);
  625. #endif
  626. }
  627. }
  628. void MyBmpButton2::DelOrigin()
  629. {
  630. try
  631. {
  632. }
  633. catch(...)
  634. {
  635. #ifdef TEST_EXCEPTION
  636. AfxMessageBox(_T(" Unhandled exception in Function MyBmpButton2 delorigin"));
  637. exit(-1);
  638. #endif
  639. }
  640. }
  641. void MyBmpButton2::SetPushDown(BOOL bPushDown)
  642. {
  643. m_bPushDown=bPushDown;
  644. ReDraw();
  645. // Invalidate();
  646. }
  647. BOOL MyBmpButton2::GetPushDown()
  648. {
  649. return m_bPushDown;
  650. }
  651. void MyBmpButton2::ChangePic(Image *img1, Image *img2, Image *img3, Image *img4)
  652. {
  653. if(m_bmp && img1)
  654. {
  655. delete m_bmp;
  656. m_bmp=img1->Clone();
  657. }
  658. if(m_bmpfocus && img2)
  659. {
  660. delete m_bmpfocus;
  661. m_bmpfocus=img2->Clone();
  662. }
  663. if(m_bmpfocused && img3)
  664. {
  665. delete m_bmpfocused;
  666. m_bmpfocused=img3->Clone();
  667. }
  668. if(m_bmpdisable && img4)
  669. {
  670. delete m_bmpdisable;
  671. m_bmpdisable=img4->Clone();
  672. }
  673. ReDraw();
  674. }
  675. void MyBmpButton2::SetLX()
  676. {
  677. m_bSupportLX=1;
  678. }
  679. void MyBmpButton2::OnTimer(UINT nIDEvent)
  680. {
  681. // TODO: Add your message handler code here and/or call default
  682. if(nIDEvent==1)
  683. {
  684. KillTimer(1);
  685. SetTimer(2, 20, NULL);
  686. }
  687. else
  688. GetParent()->SendMessage (WM_USER+1101, 0, GetDlgCtrlID());
  689. }
  690. void MyBmpButton2::ReDrawParent()
  691. {
  692. /* CRect rc;
  693. GetWindowRect (rc);
  694. GetParent()->ScreenToClient(rc);
  695. CDC *pDC=GetDC();
  696. Graphics graph(pDC->GetSafeHdc ());
  697. Rect destinationRect(0,0,rc.Width (), rc.Height ());
  698. graph.DrawImage(((MyDlg*)GetParent())->m_pBk, destinationRect, rc.left , rc.top ,rc.Width (), rc.Height (),UnitPixel);
  699. ReleaseDC(pDC);*/
  700. }
  701. //SetPushDown