// LoadRect.cpp : implementation file // #include "stdafx.h" #include "LoadRect.h" #include "YLGL.h" ///////////////////////////////////////////////////////////////////////////// // LoadRect dialog LoadRect::LoadRect(CWnd* pParent /*=NULL*/): CDialog(LoadRect::IDD, pParent) { m_pBk = NULL; m_pParent = NULL; m_dtx = 0; m_dty = 0; } LoadRect::LoadRect(DWORD id, CWnd* pParent): CDialog(id, pParent) { m_pBk = NULL; m_pParent = NULL; m_dtx = 0; m_dty = 0; } void LoadRect::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(LoadRect, CDialog) //{{AFX_MSG_MAP(LoadRect) ON_WM_PAINT() ON_WM_DESTROY() ON_WM_ERASEBKGND() //}}AFX_MSG_MAP //ON_MESSAGE(WM_USER + 1101, OnBtnClick) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // LoadRect message handlers // void LoadRect::OnBtnClick(WPARAM wParam, LPARAM lParam) // { // } BOOL LoadRect::OnInitDialog() { CDialog::OnInitDialog(); return false; } void LoadRect::OnPaint() { try { CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here /* if(::FindParent (m_hWnd) ) { CRect rc; GetWindowRect (rc); GetParent()->ScreenToClient(rc); Graphics graph(dc.GetSafeHdc ()); Rect destinationRect(0,0,rc.Width (), rc.Height ()); graph.DrawImage(((LoadRect*)GetParent())->m_pBk, destinationRect, rc.left , rc.top ,rc.Width (), rc.Height (),UnitPixel); }*/ if (m_pBk == NULL) { return; } CRect rc; GetClientRect(rc); Graphics graph(dc.GetSafeHdc()); Rect destinationRect(0, 0, rc.Width(), rc.Height()); int width = m_pBk->GetWidth(); int height = m_pBk->GetHeight(); graph.DrawImage(m_pBk, destinationRect, 0, 0, width, height, UnitPixel); // Do not call CDialog::OnPaint() for painting messages } catch (...) { } } void LoadRect::OnPaint2(CWnd *pWnd) { try { CPaintDC dc(pWnd); // device context for painting // TODO: Add your message handler code here CRect rc; GetClientRect(rc); if (m_pBk == NULL) { return; } int width = m_pBk->GetWidth(); int height = m_pBk->GetHeight(); Graphics graph(dc.GetSafeHdc()); Rect destinationRect(0, 0, rc.Width(), rc.Height()); graph.DrawImage(m_pBk, destinationRect, 0, 0, width, height, UnitPixel); } catch (...) { } } void LoadRect::OnDestroy() { try { if (m_pBk)delete m_pBk; MyBmpButton2 *pic = NULL; for (int i = 0; i < m_picarray.GetSize(); i++) { pic = (MyBmpButton2*)m_picarray.ElementAt(i); if (pic) { pic->DestroyWindow(); delete pic; } } m_picarray.RemoveAll(); CDialog::OnDestroy(); } catch (...) { } } BOOL LoadRect::OnEraseBkgnd(CDC* pDC) { return 1; } void LoadRect::OnOK() { } void LoadRect::OnCancel() { CDialog::OnCancel(); } void LoadRect::SetLiaPath(CString path) { m_liapath = path; } BOOL LoadRect::PreTranslateMessage(MSG* pMsg) { return CDialog::PreTranslateMessage(pMsg); } BEGIN_EVENTSINK_MAP(LoadRect, CDialog) ON_EVENT(LoadRect, 100, 150 /* FSCommand */, OnFSCommandShockwaveflash1, VTS_BSTR VTS_BSTR) END_EVENTSINK_MAP() void LoadRect::OnFSCommandShockwaveflash1(LPCTSTR command, LPCTSTR args) { // TODO: Add your control notification handler code here } BOOL LoadRect::Load() { HGLOBAL hGlobal = NULL; HRSRC hSource = NULL; LPVOID lpVoid = NULL; int nSize = 0; BOOL bResult = FALSE; if (m_liapath == "4.lia") hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA1), "LIA"); else if (m_liapath == "5.lia") hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA2), "LIA"); else if (m_liapath == "6.lia") hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA3), "LIA"); else if (m_liapath == "7.lia") hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA4), "LIA"); else if (m_liapath == "8.lia") hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA5), "LIA"); else if (m_liapath == "9.lia") hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA6), "LIA"); else if (m_liapath == "10.lia") hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA7), "LIA"); else if (m_liapath == "10-2.lia") hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA8), "LIA"); else if (m_liapath == "11.lia") hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA9), "LIA"); else if (m_liapath == "12.lia") hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA10), "LIA"); else if (m_liapath == "13.lia") hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA11), "LIA"); else if (m_liapath == "14.lia") hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA12), "LIA"); else if (m_liapath == "15.lia") hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA13), "LIA"); else if (m_liapath == "16.lia") hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA14), "LIA"); else if (m_liapath == "17.lia") hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA15), "LIA"); else if (m_liapath == "18.lia") hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA17), "LIA"); else if (m_liapath == "19.lia") hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA18), "LIA"); else if (m_liapath == "6-2.lia") hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA16), "LIA"); else if (m_liapath == "20.lia") hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA19), "LIA"); else if (m_liapath == "21.lia") hSource = FindResource(NULL, MAKEINTRESOURCE(IDR_LIA20), "LIA"); else return 0; if (hSource == NULL) return 0; hGlobal = LoadResource(NULL, hSource); if (hGlobal == NULL) return 0; lpVoid = LockResource(hGlobal); if (lpVoid == NULL) return 0; nSize = (UINT)SizeofResource(NULL, hSource); BYTE *pData = new BYTE[nSize]; memcpy(pData, (BYTE*)hGlobal, nSize); UnlockResource(hGlobal); // 16Bit Windows Needs This FreeResource(hGlobal); // 16Bit Windows Needs This (32Bit - Automatic Release) BYTE *pDataBegin = pData; ///////////// CStringArray childarray; DWORD childlength; memcpy(&childlength, pData, sizeof(DWORD)); pData += sizeof(DWORD); BYTE *pChildData = new BYTE[childlength]; memcpy(pChildData, pData, childlength); pData += childlength; CMemFile memfile; memfile.Attach(pChildData, childlength); CArchive ar(&memfile, CArchive::load); childarray.Serialize(ar); ar.Close(); memfile.Detach(); delete[]pChildData; ////////////////////// memcpy(&g_resdata2, pData, sizeof(RESDATA2)); pData += sizeof(RESDATA2); if (g_resdata2.bHasBk) { BYTE *m_pSaveBk = NULL; DWORD leng = 0; MyBmpButton2::ReadBK(&pData, &m_pSaveBk, leng); LoadImageFromBuf(&m_pBk, m_pSaveBk, leng); } for (int i = 0; i < g_resdata2.nPicCount; i++) { if (g_resdata2.nPicBmpCount[i]) { MyBmpButton2 *pic = new MyBmpButton2; m_picarray.Add((DWORD)pic); CRect rc = g_resdata2.rect[i]; CString str; str.Format(_T("%d"), i + 1); pic->Create(str, WS_CHILD | WS_VISIBLE | BS_OWNERDRAW, rc, this, i + 100); pic->m_bmpcount = g_resdata2.nPicBmpCount[i]; pic->ReadBmp(&pData, NULL, this); pic->m_childpath = childarray.ElementAt(i); } else m_picarray.Add(NULL); g_resdata2.rect[i].left += m_dtx; g_resdata2.rect[i].right += m_dtx; g_resdata2.rect[i].top += m_dty; g_resdata2.rect[i].bottom += m_dty; m_rcarray.Add(g_resdata2.rect[i]); } delete[]pDataBegin; return 1; } void LoadRect::SetMargins(int dtx, int dty) { m_dtx = dtx; m_dty = dty; }