MyBmpButton2.cpp 17 KB

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