LoadRect.cpp 6.4 KB

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