LoadRect.cpp 7.0 KB

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