LoadRect.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. // LoadRect.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "LoadRect.h"
  5. #include "YLGL.h"
  6. /////////////////////////////////////////////////////////////////////////////
  7. // LoadRect dialog
  8. LoadRect::LoadRect(CWnd* pParent /*=NULL*/): CDialog(LoadRect::IDD, pParent)
  9. {
  10. m_pBk = NULL;
  11. m_pParent = NULL;
  12. m_dtx = 0;
  13. m_dty = 0;
  14. }
  15. LoadRect::LoadRect(DWORD id, CWnd* pParent): CDialog(id, pParent)
  16. {
  17. m_pBk = NULL;
  18. m_pParent = NULL;
  19. m_dtx = 0;
  20. m_dty = 0;
  21. }
  22. void LoadRect::DoDataExchange(CDataExchange* pDX)
  23. {
  24. CDialog::DoDataExchange(pDX);
  25. }
  26. BEGIN_MESSAGE_MAP(LoadRect, CDialog)
  27. //{{AFX_MSG_MAP(LoadRect)
  28. ON_WM_PAINT()
  29. ON_WM_DESTROY()
  30. ON_WM_ERASEBKGND()
  31. //}}AFX_MSG_MAP
  32. //ON_MESSAGE(WM_USER + 1101, OnBtnClick)
  33. END_MESSAGE_MAP()
  34. /////////////////////////////////////////////////////////////////////////////
  35. // LoadRect message handlers
  36. // void LoadRect::OnBtnClick(WPARAM wParam, LPARAM lParam)
  37. // {
  38. // }
  39. BOOL LoadRect::OnInitDialog()
  40. {
  41. CDialog::OnInitDialog();
  42. return false;
  43. }
  44. void LoadRect::OnPaint()
  45. {
  46. try
  47. {
  48. CPaintDC dc(this); // device context for painting
  49. // TODO: Add your message handler code here
  50. /* if(::FindParent (m_hWnd) )
  51. {
  52. CRect rc;
  53. GetWindowRect (rc);
  54. GetParent()->ScreenToClient(rc);
  55. Graphics graph(dc.GetSafeHdc ());
  56. Rect destinationRect(0,0,rc.Width (), rc.Height ());
  57. graph.DrawImage(((LoadRect*)GetParent())->m_pBk, destinationRect, rc.left , rc.top ,rc.Width (), rc.Height (),UnitPixel);
  58. }*/
  59. if (m_pBk == NULL)
  60. {
  61. return;
  62. }
  63. CRect rc;
  64. GetClientRect(rc);
  65. Graphics graph(dc.GetSafeHdc());
  66. Rect destinationRect(0, 0, rc.Width(), rc.Height());
  67. int width = m_pBk->GetWidth();
  68. int height = m_pBk->GetHeight();
  69. graph.DrawImage(m_pBk, destinationRect, 0, 0, width, height, UnitPixel);
  70. // Do not call CDialog::OnPaint() for painting messages
  71. }
  72. catch (...)
  73. {
  74. }
  75. }
  76. void LoadRect::OnPaint2(CWnd *pWnd)
  77. {
  78. try
  79. {
  80. CPaintDC dc(pWnd); // device context for painting
  81. // TODO: Add your message handler code here
  82. CRect rc;
  83. GetClientRect(rc);
  84. if (m_pBk == NULL)
  85. {
  86. return;
  87. }
  88. int width = m_pBk->GetWidth();
  89. int height = m_pBk->GetHeight();
  90. Graphics graph(dc.GetSafeHdc());
  91. Rect destinationRect(0, 0, rc.Width(), rc.Height());
  92. graph.DrawImage(m_pBk, destinationRect, 0, 0, width, height, UnitPixel);
  93. }
  94. catch (...)
  95. {
  96. }
  97. }
  98. void LoadRect::OnDestroy()
  99. {
  100. try
  101. {
  102. if (m_pBk)delete m_pBk;
  103. MyBmpButton2 *pic = NULL;
  104. for (int i = 0; i < m_picarray.GetSize(); i++)
  105. {
  106. pic = (MyBmpButton2*)m_picarray.ElementAt(i);
  107. if (pic)
  108. {
  109. pic->DestroyWindow();
  110. delete pic;
  111. }
  112. }
  113. m_picarray.RemoveAll();
  114. CDialog::OnDestroy();
  115. }
  116. catch (...)
  117. {
  118. }
  119. }
  120. BOOL LoadRect::OnEraseBkgnd(CDC* pDC)
  121. {
  122. return 1;
  123. }
  124. void LoadRect::OnOK()
  125. {
  126. }
  127. void LoadRect::OnCancel()
  128. {
  129. CDialog::OnCancel();
  130. }
  131. void LoadRect::SetLiaPath(CString path)
  132. {
  133. m_liapath = path;
  134. }
  135. BOOL LoadRect::PreTranslateMessage(MSG* pMsg)
  136. {
  137. return CDialog::PreTranslateMessage(pMsg);
  138. }
  139. BEGIN_EVENTSINK_MAP(LoadRect, CDialog)
  140. ON_EVENT(LoadRect, 100, 150 /* FSCommand */, OnFSCommandShockwaveflash1, VTS_BSTR VTS_BSTR)
  141. END_EVENTSINK_MAP()
  142. void LoadRect::OnFSCommandShockwaveflash1(LPCTSTR command, LPCTSTR args)
  143. {
  144. // TODO: Add your control notification handler code here
  145. }
  146. BOOL LoadRect::Load()
  147. {
  148. HGLOBAL hGlobal = NULL;
  149. HRSRC hSource = NULL;
  150. LPVOID lpVoid = NULL;
  151. int nSize = 0;
  152. BOOL bResult = FALSE;
  153. if (m_liapath == "4.lia")
  154. hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA1), "LIA");
  155. else if (m_liapath == "5.lia")
  156. hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA2), "LIA");
  157. else if (m_liapath == "6.lia")
  158. hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA3), "LIA");
  159. else if (m_liapath == "7.lia")
  160. hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA4), "LIA");
  161. else if (m_liapath == "8.lia")
  162. hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA5), "LIA");
  163. else if (m_liapath == "9.lia")
  164. hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA6), "LIA");
  165. else if (m_liapath == "10.lia")
  166. hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA7), "LIA");
  167. else if (m_liapath == "10-2.lia")
  168. hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA8), "LIA");
  169. else if (m_liapath == "11.lia")
  170. hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA9), "LIA");
  171. else if (m_liapath == "12.lia")
  172. hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA10), "LIA");
  173. else if (m_liapath == "13.lia")
  174. hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA11), "LIA");
  175. else if (m_liapath == "14.lia")
  176. hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA12), "LIA");
  177. else if (m_liapath == "15.lia")
  178. hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA13), "LIA");
  179. else if (m_liapath == "16.lia")
  180. hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA14), "LIA");
  181. else if (m_liapath == "17.lia")
  182. hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA15), "LIA");
  183. else if (m_liapath == "18.lia")
  184. hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA17), "LIA");
  185. else if (m_liapath == "19.lia")
  186. hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA18), "LIA");
  187. else if (m_liapath == "6-2.lia")
  188. hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA16), "LIA");
  189. else if (m_liapath == "20.lia")
  190. hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA19), "LIA");
  191. else if (m_liapath == "21.lia")
  192. hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA20), "LIA");
  193. else
  194. return 0;
  195. if (hSource == NULL)
  196. return 0;
  197. hGlobal = LoadResource(NULL, hSource);
  198. if (hGlobal == NULL)
  199. return 0;
  200. lpVoid = LockResource(hGlobal);
  201. if (lpVoid == NULL)
  202. return 0;
  203. nSize = (UINT)SizeofResource(NULL, hSource);
  204. BYTE *pData = new BYTE[nSize];
  205. memcpy(pData, (BYTE*)hGlobal, nSize);
  206. UnlockResource(hGlobal); // 16Bit Windows Needs This
  207. FreeResource(hGlobal); // 16Bit Windows Needs This (32Bit - Automatic Release)
  208. BYTE *pDataBegin = pData;
  209. /////////////
  210. CStringArray childarray;
  211. DWORD childlength;
  212. memcpy(&childlength, pData, sizeof(DWORD));
  213. pData += sizeof(DWORD);
  214. BYTE *pChildData = new BYTE[childlength];
  215. memcpy(pChildData, pData, childlength);
  216. pData += childlength;
  217. CMemFile memfile;
  218. memfile.Attach(pChildData, childlength);
  219. CArchive ar(&memfile, CArchive::load);
  220. childarray.Serialize(ar);
  221. ar.Close();
  222. memfile.Detach();
  223. delete[]pChildData;
  224. //////////////////////
  225. memcpy(&g_resdata2, pData, sizeof(RESDATA2));
  226. pData += sizeof(RESDATA2);
  227. if (g_resdata2.bHasBk)
  228. {
  229. BYTE *m_pSaveBk = NULL;
  230. DWORD leng = 0;
  231. MyBmpButton2::ReadBK(&pData, &m_pSaveBk, leng);
  232. LoadImageFromBuf(&m_pBk, m_pSaveBk, leng);
  233. }
  234. for (int i = 0; i < g_resdata2.nPicCount; i++)
  235. {
  236. if (g_resdata2.nPicBmpCount[i])
  237. {
  238. MyBmpButton2 *pic = new MyBmpButton2;
  239. m_picarray.Add((DWORD)pic);
  240. CRect rc = g_resdata2.rect[i];
  241. CString str;
  242. str.Format(_T("%d"), i + 1);
  243. pic->Create(str, WS_CHILD | WS_VISIBLE | BS_OWNERDRAW, rc, this, i + 100);
  244. pic->m_bmpcount = g_resdata2.nPicBmpCount[i];
  245. pic->ReadBmp(&pData, NULL, this);
  246. pic->m_childpath = childarray.ElementAt(i);
  247. }
  248. else
  249. m_picarray.Add(NULL);
  250. g_resdata2.rect[i].left += m_dtx;
  251. g_resdata2.rect[i].right += m_dtx;
  252. g_resdata2.rect[i].top += m_dty;
  253. g_resdata2.rect[i].bottom += m_dty;
  254. m_rcarray.Add(g_resdata2.rect[i]);
  255. }
  256. delete[]pDataBegin;
  257. return 1;
  258. }
  259. void LoadRect::SetMargins(int dtx, int dty)
  260. {
  261. m_dtx = dtx;
  262. m_dty = dty;
  263. }