MyDlg.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. // MyDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "MyDlg.h"
  5. #include "LYFZSendMsg.h"
  6. RESDATA2 g_resdata2;
  7. BOOL g_bAlphaWnd=0;
  8. HCURSOR g_cursorhand=NULL;
  9. /////////////////////////////////////////////////////////////////////////////
  10. // MyDlg dialog
  11. MyDlg::MyDlg(CWnd* pParent /*=NULL*/)
  12. : CDialog(MyDlg::IDD, pParent)
  13. {
  14. //{{AFX_DATA_INIT(MyDlg)
  15. // NOTE: the ClassWizard will add member initialization here
  16. //}}AFX_DATA_INIT
  17. m_pBk=NULL;
  18. m_pParent=NULL;
  19. }
  20. MyDlg::MyDlg(DWORD id, CWnd* pParent)
  21. : CDialog(id, pParent)
  22. {
  23. //{{AFX_DATA_INIT(MyDlg)
  24. // NOTE: the ClassWizard will add member initialization here
  25. //}}AFX_DATA_INIT
  26. m_pBk=NULL;
  27. m_pParent=NULL;
  28. }
  29. void MyDlg::DoDataExchange(CDataExchange* pDX)
  30. {
  31. CDialog::DoDataExchange(pDX);
  32. //{{AFX_DATA_MAP(MyDlg)
  33. //}}AFX_DATA_MAP}
  34. }
  35. BEGIN_MESSAGE_MAP(MyDlg, CDialog)
  36. //{{AFX_MSG_MAP(MyDlg)
  37. ON_WM_PAINT()
  38. ON_WM_DESTROY()
  39. ON_WM_ERASEBKGND()
  40. //}}AFX_MSG_MAP
  41. ON_MESSAGE(WM_USER+1101,OnBtnClick)
  42. END_MESSAGE_MAP()
  43. /////////////////////////////////////////////////////////////////////////////
  44. // MyDlg message handlers
  45. void SizeToContent(HWND hwnd, Image *img)
  46. {
  47. if(img==NULL)return;
  48. if(g_bAlphaWnd)
  49. {
  50. g_bAlphaWnd=0;
  51. SetWindowPos(hwnd, HWND_NOTOPMOST, (g_dm.dmPelsWidth-g_fscalex*img->GetWidth())/2, (g_dm.dmPelsHeight-g_fscaley*img->GetHeight())/2, g_fscalex*img->GetWidth(), g_fscaley*img->GetHeight(), SWP_SHOWWINDOW);
  52. }
  53. else
  54. SetWindowPos(hwnd, HWND_NOTOPMOST, (g_dm.dmPelsWidth-g_fscalex*img->GetWidth())/2, (g_dm.dmPelsHeight-g_fscaley*img->GetHeight())/2, g_fscalex*img->GetWidth(), g_fscaley*img->GetHeight(), NULL);
  55. }
  56. void MyDlg::OnBtnClick (WPARAM wParam, LPARAM lParam)
  57. {
  58. BtnClick(wParam, lParam);
  59. }
  60. BOOL MyDlg::OnInitDialog()
  61. {
  62. CDialog::OnInitDialog();
  63. // TODO: Add extra initialization here
  64. if(g_cursorhand==NULL)
  65. g_cursorhand=AfxGetApp()->LoadCursor(IDC_CURSORHAND);
  66. BYTE *pData=NULL;
  67. BYTE *pDataBegin;
  68. if(!LoadLia(g_mainpath+"\\skin\\"+m_liapath, &pData, &pDataBegin, &m_pBk, m_hWnd))
  69. {
  70. EndDialog(0);
  71. return false;
  72. }
  73. /* CFile fp;
  74. if(!fp.Open (g_mainpath+"\\skin\\"+m_liapath, CFile::modeRead))
  75. {
  76. AfxMessageBox(_T("liaÎļþδÕÒµ½."), MB_ICONINFORMATION);
  77. EndDialog(0);
  78. return false;
  79. }
  80. DWORD count=fp.GetLength ();
  81. BYTE *pData=new BYTE[count];
  82. BYTE *pDataBegin=pData;
  83. fp.Read (pData, count);
  84. fp.Close ();
  85. /////////////
  86. CStringArray childarray;
  87. DWORD childlength;
  88. memcpy(&childlength, pData, sizeof(DWORD));
  89. pData+=sizeof(DWORD);
  90. BYTE *pChildData=new BYTE[childlength];
  91. memcpy(pChildData, pData, childlength);
  92. pData+=childlength;
  93. CMemFile memfile;
  94. memfile.Attach (pChildData,childlength);
  95. CArchive ar(&memfile, CArchive::load);
  96. childarray.Serialize (ar);
  97. ar.Close();
  98. memfile.Detach ();
  99. delete []pChildData;
  100. //////////////////////
  101. memcpy(&g_resdata2, pData, sizeof(RESDATA2));
  102. pData+=sizeof(RESDATA2);
  103. if(g_resdata2.bHasBk )
  104. {
  105. BYTE *m_pSaveBk=NULL;
  106. DWORD leng=0;
  107. MyBmpButton2::ReadBK(&pData, &m_pSaveBk, leng);
  108. LoadImageFromBuf(&m_pBk, m_pSaveBk, leng);
  109. SizeToContent(m_hWnd, m_pBk);
  110. if(m_pBk->GetWidth()==1024 && m_pBk->GetHeight()==768)
  111. ::SetWindowPos(m_hWnd,HWND_TOP,0 ,0,g_dm.dmPelsWidth,g_dm.dmPelsHeight,SWP_SHOWWINDOW);
  112. }*/
  113. for(int i=0; i<g_resdata2.nPicCount; i++)
  114. {
  115. g_resdata2.rect[i].left *=g_fscalex;
  116. g_resdata2.rect[i].right *=g_fscalex;
  117. g_resdata2.rect[i].top *=g_fscaley;
  118. g_resdata2.rect[i].bottom *=g_fscaley;
  119. if(g_resdata2.nPicBmpCount [i])
  120. {
  121. MyBmpButton2 *pic=new MyBmpButton2;
  122. m_picarray.Add((DWORD)pic);
  123. CRect rc=g_resdata2.rect[i];
  124. CString str;
  125. str.Format (_T("%d"), i+1);
  126. pic->Create(str, WS_CHILD|WS_VISIBLE|BS_OWNERDRAW , rc, this, i+100);
  127. pic->m_bmpcount =g_resdata2.nPicBmpCount [i];
  128. pic->ReadBmp (&pData, NULL, this);
  129. }
  130. else
  131. m_picarray.Add (NULL);
  132. m_rcarray.Add(g_resdata2.rect[i]);
  133. }
  134. delete []pDataBegin;
  135. Init();
  136. return false; // return TRUE unless you set the focus to a control
  137. // EXCEPTION: OCX Property Pages should return FALSE
  138. }
  139. void MyDlg::OnPaint()
  140. {
  141. try
  142. {
  143. CPaintDC dc(this); // device context for painting
  144. // TODO: Add your message handler code here
  145. /* if(::FindParent (m_hWnd) )
  146. {
  147. CRect rc;
  148. GetWindowRect (rc);
  149. GetParent()->ScreenToClient(rc);
  150. Graphics graph(dc.GetSafeHdc ());
  151. Rect destinationRect(0,0,rc.Width (), rc.Height ());
  152. graph.DrawImage(((MyDlg*)GetParent())->m_pBk, destinationRect, rc.left , rc.top ,rc.Width (), rc.Height (),UnitPixel);
  153. }*/
  154. if(m_pBk==NULL)
  155. {
  156. return ;
  157. }
  158. CRect rc;
  159. GetClientRect(rc);
  160. Graphics graph(dc.GetSafeHdc ());
  161. Rect destinationRect(0,0,rc.Width (), rc.Height ());
  162. int width=m_pBk->GetWidth() ;
  163. int height=m_pBk->GetHeight() ;
  164. graph.DrawImage(m_pBk, destinationRect, 0,0,width,height,UnitPixel);
  165. // Do not call CDialog::OnPaint() for painting messages
  166. }
  167. catch(...)
  168. {
  169. }
  170. }
  171. void MyDlg::OnPaint2(CWnd *pWnd)
  172. {
  173. try
  174. {
  175. CPaintDC dc(pWnd); // device context for painting
  176. // TODO: Add your message handler code here
  177. CRect rc;
  178. GetClientRect(rc);
  179. if(m_pBk==NULL)
  180. {
  181. return ;
  182. }
  183. int width=m_pBk->GetWidth() ;
  184. int height=m_pBk->GetHeight() ;
  185. Graphics graph(dc.GetSafeHdc ());
  186. Rect destinationRect(0,0,rc.Width (), rc.Height ());
  187. graph.DrawImage(m_pBk, destinationRect, 0,0,width,height,UnitPixel);
  188. }
  189. catch(...)
  190. {
  191. }
  192. }
  193. void MyDlg::OnDestroy()
  194. {
  195. try
  196. {
  197. CDialog::OnDestroy();
  198. if(m_pBk)delete m_pBk;
  199. MyBmpButton2 *pic=NULL;
  200. for(int i=0; i<m_picarray.GetSize(); i++)
  201. {
  202. pic=(MyBmpButton2*)m_picarray.ElementAt(i);
  203. if(pic)
  204. {
  205. pic->DestroyWindow();
  206. delete pic;
  207. }
  208. }
  209. m_picarray.RemoveAll();
  210. Destory();
  211. }
  212. catch(...)
  213. {
  214. }
  215. }
  216. BOOL MyDlg::OnEraseBkgnd(CDC* pDC)
  217. {
  218. // TODO: Add your message handler code here and/or call default
  219. return 1;
  220. }
  221. void MyDlg::OnOK()
  222. {
  223. // TODO: Add extra validation here
  224. }
  225. void MyDlg::OnCancel()
  226. {
  227. // TODO: Add extra cleanup here
  228. CDialog::OnCancel();
  229. }
  230. void MyDlg::SetLiaPath(CString path)
  231. {
  232. m_liapath=path;
  233. }
  234. BOOL MyDlg::PreTranslateMessage(MSG* pMsg)
  235. {
  236. return PreTransMsg(pMsg);
  237. // return CDialog::PreTranslateMessage(pMsg);
  238. return 1;
  239. }
  240. BEGIN_EVENTSINK_MAP(MyDlg, CDialog)
  241. //{{AFX_EVENTSINK_MAP(MyDlg)
  242. ON_EVENT(MyDlg, 100, 150 /* FSCommand */, OnFSCommandShockwaveflash1, VTS_BSTR VTS_BSTR)
  243. //}}AFX_EVENTSINK_MAP
  244. END_EVENTSINK_MAP()
  245. void MyDlg::OnFSCommandShockwaveflash1(LPCTSTR command, LPCTSTR args)
  246. {
  247. // TODO: Add your control notification handler code here
  248. OnFSCommand( command, args);
  249. }