LoadRect.cpp 7.6 KB

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