bool CWin::ExistsSkinFile(STRINGorID xml, LPCTSTR type) {//busy to do it return false; CDuiString strResourcePath = GetSkinPath(); strResourcePath += GetSkinFolder().GetData(); CMarkup m_xml; switch (GetResourceType()) { case UILIB_FILE: { if (HIWORD(xml.m_lpstr) != NULL) { if (*(xml.m_lpstr) == _T('<')) { return true; } else { CDuiString sFile = strResourcePath + xml.m_lpstr; HANDLE hFile = ::CreateFile(sFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) return false; DWORD dwSize = ::GetFileSize(hFile, NULL); if (dwSize == 0) return false; if (dwSize > 4096 * 1024) return false; DWORD dwRead = 0; BYTE* pByte = new BYTE[dwSize]; ::ReadFile(hFile, pByte, dwSize, &dwRead, NULL); ::CloseHandle(hFile); if (dwRead != dwSize) { delete[] pByte; return false; } delete[] pByte; return true; } } else{ } } break; case UILIB_ZIP: { } break; case UILIB_RESOURCE: { } break; case UILIB_ZIPRESOURCE: { } } return false; }
LRESULT ChatDialog::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { LONG styleValue = ::GetWindowLong(*this, GWL_STYLE); styleValue &= ~WS_CAPTION; ::SetWindowLong(*this, GWL_STYLE, styleValue | WS_CLIPSIBLINGS | WS_CLIPCHILDREN); RECT rcClient; ::GetClientRect(*this, &rcClient); ::SetWindowPos(*this, NULL, rcClient.left, rcClient.top, rcClient.right - rcClient.left, \ rcClient.bottom - rcClient.top, SWP_FRAMECHANGED); paint_manager_.Init(m_hWnd); paint_manager_.AddPreMessageFilter(this); CDialogBuilder builder; paint_manager_.SetResourcePath(GetSkinFolder().c_str()); #if USE(ZIP_SKIN) #if defined(UNDER_CE) static bool resource_unzipped = false; if (!resource_unzipped) { resource_unzipped = true; paint_manager_.SetResourceZip(kResourceSkinZipFileName); paint_manager_.UnzipResource(); paint_manager_.SetResourceZip(_T("")); } tString tstrSkin = paint_manager_.GetResourcePath(); tstrSkin += GetSkinFile(); #else paint_manager_.SetResourceZip(kResourceSkinZipFileName); tString tstrSkin = GetSkinFile(); #endif #else tString tstrSkin = paint_manager_.GetResourcePath(); tstrSkin += GetSkinFile(); #endif CControlUI* pRoot = NULL; if( !m_dlgBuilder.GetMarkup()->IsValid() ) { pRoot = m_dlgBuilder.Create(tstrSkin.c_str(), (UINT)0, this, &paint_manager_); } else { pRoot = m_dlgBuilder.Create((UINT)0, &paint_manager_); } paint_manager_.AttachDialog(pRoot); paint_manager_.AddNotifier(this); Init(); return 0; }
LRESULT WindowImplBase::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { ::SetWindowLong(*this, GWL_STYLE, GetStyle() | WS_CLIPSIBLINGS | WS_CLIPCHILDREN); RECT rcClient; ::GetClientRect(*this, &rcClient); ::SetWindowPos(*this, NULL, rcClient.left, rcClient.top, rcClient.right - rcClient.left, \ rcClient.bottom - rcClient.top, SWP_FRAMECHANGED); paint_manager_.Init(m_hWnd); paint_manager_.AddPreMessageFilter(this); CDialogBuilder builder; paint_manager_.SetResourcePath(GetSkinFolder().c_str()); CControlUI* pRoot = NULL; #if USE(EMBEDED_RESOURCE) STRINGorID xml(_ttoi(GetSkinFile().c_str())); pRoot = builder.Create(xml, _T("xml"), this, &paint_manager_); #else #if USE(ZIP_SKIN) #if defined(UNDER_CE) static bool resource_unzipped = false; if (!resource_unzipped) { resource_unzipped = true; paint_manager_.SetResourceZip(kResourceSkinZipFileName); paint_manager_.UnzipResource(); paint_manager_.SetResourceZip(_T("")); } tString tstrSkin = paint_manager_.GetResourcePath(); tstrSkin += GetSkinFile(); #else paint_manager_.SetResourceZip(kResourceSkinZipFileName); tString tstrSkin = GetSkinFile(); #endif #else // DuiLib中用的是相对路径,绝对路径会出错,最好能够内部判断一下。 //tString tstrSkin = paint_manager_.GetResourcePath(); tString tstrSkin = GetSkinFile(); #endif pRoot = builder.Create(tstrSkin.c_str(), (UINT)0, this, &paint_manager_); #endif paint_manager_.AttachDialog(pRoot); paint_manager_.AddNotifier(this); Init(); return 0; }
void CMainFrame::InitWindow() { DWORD d = 0xaabbccdd; BYTE r = GetRValue(d); BYTE g = GetGValue(d); BYTE b = GetBValue(d); CString strResourcePath=m_PaintManager.GetInstancePath(); strResourcePath+=GetSkinFolder().GetData(); CString sPic; sPic.Format(_T("%smain.bmp"), strResourcePath); DuiLib::STRINGorID tmp(sPic.GetBuffer()); HRGN hRgn = DuiLib::CRenderEngine::CreateImageRegion((DuiLib::CRenderEngine::LoadImage(tmp)), RGB(0,255,0)); SetRgn(hRgn); // CRgn rgn; // rgn.CreateRectRgn(100,100,200,200); // ::SetWindowRgn(m_hWnd, rgn, TRUE); SetTimer(2, 1000); }
LRESULT CMainFrame::OnTimer(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { bHandled = TRUE; UINT nIDEvent = (UINT)wParam; switch(nIDEvent) { case 1: case 2: default:break; } if (g_nCount > 5) g_nCount = 0; CString strResourcePath=m_PaintManager.GetInstancePath(); strResourcePath+=GetSkinFolder().GetData(); CString sPic; sPic.Format(_T("%sSignalRect0%d.png"), strResourcePath, g_nCount); DuiLib::CControlUI* pctrl = static_cast<DuiLib::CControlUI*>(m_PaintManager.FindControl(_T("ctrl"))); if (pctrl) pctrl->SetBkImage(sPic); g_nCount++; return 0; }
static BOOL CALLBACK DlgSkinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_DESTROY: { if (hPreviewBitmap) DeleteObject(hPreviewBitmap); break; } case WM_INITDIALOG: { int it; TranslateDialogDefault(hwndDlg); it=FillAvailableSkinList(hwndDlg); { /* Text Colors */ DWORD c1,c2,c3,c4; c1=DBGetContactSettingDword(NULL,"Menu", "TextColour", CLCDEFAULT_TEXTCOLOUR); c2=DBGetContactSettingDword(NULL,"Menu", "SelTextColour", CLCDEFAULT_SELTEXTCOLOUR); c3=DBGetContactSettingDword(NULL,"FrameTitleBar", "TextColour", CLCDEFAULT_TEXTCOLOUR); c4=DBGetContactSettingDword(NULL,"StatusBar", "TextColour", CLCDEFAULT_TEXTCOLOUR); SendDlgItemMessage(hwndDlg,IDC_COLOUR_MENUNORMAL,CPM_SETCOLOUR,0,c1); SendDlgItemMessage(hwndDlg,IDC_COLOUR_MENUSELECTED,CPM_SETCOLOUR,0,c2); SendDlgItemMessage(hwndDlg,IDC_COLOUR_FRAMES,CPM_SETCOLOUR,0,c3); SendDlgItemMessage(hwndDlg,IDC_COLOUR_STATUSBAR,CPM_SETCOLOUR,0,c4); SendDlgItemMessage(hwndDlg,IDC_COLOUR_MENUNORMAL,CPM_SETDEFAULTCOLOUR,0,c1); SendDlgItemMessage(hwndDlg,IDC_COLOUR_MENUSELECTED,CPM_SETDEFAULTCOLOUR,0,c2); SendDlgItemMessage(hwndDlg,IDC_COLOUR_FRAMES,CPM_SETDEFAULTCOLOUR,0,c3); SendDlgItemMessage(hwndDlg,IDC_COLOUR_STATUSBAR,CPM_SETDEFAULTCOLOUR,0,c4); /* End of Text colors */ } TreeView_SelectItem(GetDlgItem(hwndDlg,IDC_TREE1),(HTREEITEM)it); } return 0; case WM_COMMAND: { int isLoad=0; switch (LOWORD(wParam)) { case IDC_COLOUR_MENUNORMAL: case IDC_COLOUR_MENUSELECTED: case IDC_COLOUR_FRAMES: case IDC_COLOUR_STATUSBAR: SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; case IDC_BUTTON_INFO: { char Author[255]; char URL[MAX_PATH]; char Contact[255]; char Description[400]; char text[2000]; SkinListData *sd=NULL; HTREEITEM hti=TreeView_GetSelection(GetDlgItem(hwndDlg,IDC_TREE1)); if (hti==0) return 0; { TVITEMA tvi={0}; tvi.hItem=hti; tvi.mask=TVIF_HANDLE|TVIF_PARAM; TreeView_GetItem(GetDlgItem(hwndDlg,IDC_TREE1),&tvi); sd=(SkinListData*)(tvi.lParam); } if (!sd) return 0; if (sd->File && !strchr(sd->File,'%')) { GetPrivateProfileStringA("Skin_Description_Section","Author","(unknown)",Author,sizeof(Author),sd->File); GetPrivateProfileStringA("Skin_Description_Section","URL","",URL,sizeof(URL),sd->File); GetPrivateProfileStringA("Skin_Description_Section","Contact","",Contact,sizeof(Contact),sd->File); GetPrivateProfileStringA("Skin_Description_Section","Description","",Description,sizeof(Description),sd->File); _snprintf(text,sizeof(text),Translate("%s\n\n%s\n\nAuthor(s):\t %s\nContact:\t %s\nWeb:\t %s\n\nFile:\t %s"), sd->Name,Description,Author,Contact,URL,sd->File); } else { _snprintf(text,sizeof(text),Translate("%s\n\n%s\n\nAuthor(s): %s\nContact:\t %s\nWeb:\t %s\n\nFile:\t %s"), "Luna v0.4",Translate("This is default Modern Contact list skin based on 'Luna' theme"),"Angeli-Ka (graphics), FYR (template)","JID: [email protected]","modern.saopp.info",Translate("Inside library")); } MessageBoxA(hwndDlg,text,"Skin Information",MB_OK|MB_ICONINFORMATION); } break; case IDC_BUTTON_APPLY_SKIN: if (HIWORD(wParam)==BN_CLICKED) { SkinListData *sd=NULL; HTREEITEM hti=TreeView_GetSelection(GetDlgItem(hwndDlg,IDC_TREE1)); if (hti==0) return 0; { TVITEM tvi={0}; tvi.hItem=hti; tvi.mask=TVIF_HANDLE|TVIF_PARAM; TreeView_GetItem(GetDlgItem(hwndDlg,IDC_TREE1),&tvi); sd=(SkinListData*)(tvi.lParam); } if (!sd) return 0; if (glSkinWasModified>0) { int res=0; if (glSkinWasModified==1) res=MessageBoxA(hwndDlg,Translate("Skin editor contains not stored changes.\n\nAll changes will be lost.\n\n Continue to load new skin?"),Translate("Warning!"),MB_OKCANCEL|MB_ICONWARNING|MB_DEFBUTTON2|MB_TOPMOST); else res=MessageBoxA(hwndDlg,Translate("Current skin was not saved to file.\n\nAll changes will be lost.\n\n Continue to load new skin?"),Translate("Warning!"),MB_OKCANCEL|MB_ICONWARNING|MB_DEFBUTTON2|MB_TOPMOST); if (res!=IDOK) return 0; } LoadSkinFromIniFile(sd->File); LoadSkinFromDB(); glOtherSkinWasLoaded=TRUE; pcli->pfnClcBroadcast( INTM_RELOADOPTIONS,0,0); CLUIFramesOnClistResize2(0,0,0); RedrawCompleteWindow(); CLUIFramesOnClistResize2(0,0,0); { HWND hwnd=(HWND)CallService(MS_CLUI_GETHWND,0,0); RECT rc={0}; GetWindowRect(hwnd, &rc); OnMoving(hwnd,&rc); } if (hCLUIwnd) { SendDlgItemMessage(hCLUIwnd,IDC_LEFTMARGINSPIN,UDM_SETPOS,0,DBGetContactSettingByte(NULL,"CLUI","LeftClientMargin",0)); SendDlgItemMessage(hCLUIwnd,IDC_RIGHTMARGINSPIN,UDM_SETPOS,0,DBGetContactSettingByte(NULL,"CLUI","RightClientMargin",0)); SendDlgItemMessage(hCLUIwnd,IDC_TOPMARGINSPIN,UDM_SETPOS,0,DBGetContactSettingByte(NULL,"CLUI","TopClientMargin",0)); SendDlgItemMessage(hCLUIwnd,IDC_BOTTOMMARGINSPIN,UDM_SETPOS,0,DBGetContactSettingByte(NULL,"CLUI","BottomClientMargin",0)); } } break; case IDC_BUTTON_LOAD: isLoad=1; if (HIWORD(wParam)==BN_CLICKED) { { char str[MAX_PATH]={0}; OPENFILENAMEA ofn={0}; char filter[512]={0}; int res=0; ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; ofn.hwndOwner = hwndDlg; ofn.hInstance = NULL; sprintf(filter,"%s",Translate("Miranda skin file")); memmove(filter+mir_strlen(filter)," (*.msf)\0*.MSF\0\0",sizeof(" (*.msf)\0*.MSF\0\0")); ofn.lpstrFilter = filter; ofn.lpstrFile = str; ofn.Flags = isLoad?(OFN_FILEMUSTEXIST | OFN_HIDEREADONLY) : (OFN_OVERWRITEPROMPT|OFN_HIDEREADONLY); ofn.nMaxFile = sizeof(str); ofn.nMaxFileTitle = MAX_PATH; ofn.lpstrDefExt = "msf"; { DWORD tick=GetTickCount(); res=GetOpenFileNameA(&ofn); if(!res) if (GetTickCount()-tick<100) { res=GetOpenFileNameA(&ofn); if(!res) break; } else break; } if (res) { int it=AddSkinToListFullName(hwndDlg,ofn.lpstrFile); TreeView_SelectItem(GetDlgItem(hwndDlg,IDC_TREE1),(HTREEITEM)it); //SendDlgItemMessage(hwndDlg,IDC_SKINS_LIST,LB_SETCURSEL,it,0); //SendMessage(hwndDlg,WM_COMMAND,MAKEWPARAM(IDC_SKINS_LIST,LBN_SELCHANGE),0); } } } } break; } case WM_DRAWITEM: if (wParam==IDC_PREVIEW) { //TODO:Draw hPreviewBitmap here HDC memDC, imgDC; HBITMAP hbmp,holdbmp,imgOldbmp; int mWidth, mHeight; RECT workRect={0}; HBRUSH hbr=CreateSolidBrush(GetSysColor(COLOR_3DFACE)); DRAWITEMSTRUCT *dis=(DRAWITEMSTRUCT *)lParam; mWidth=dis->rcItem.right-dis->rcItem.left; mHeight=dis->rcItem.bottom-dis->rcItem.top; memDC=CreateCompatibleDC(dis->hDC); hbmp=CreateBitmap32(mWidth,mHeight); holdbmp=SelectObject(memDC,hbmp); workRect=dis->rcItem; OffsetRect(&workRect,-workRect.left,-workRect.top); FillRect(memDC,&workRect,hbr); DeleteObject(hbr); if (hPreviewBitmap) { //variables BITMAP bmp={0}; POINT imgPos={0}; int wWidth,wHeight; int dWidth,dHeight; float xScale=1, yScale=1; //GetSize GetObject(hPreviewBitmap,sizeof(BITMAP),&bmp); wWidth=workRect.right-workRect.left; wHeight=workRect.bottom-workRect.top; if (wWidth<bmp.bmWidth) xScale=(float)wWidth/bmp.bmWidth; if (wHeight<bmp.bmHeight) yScale=(float)wHeight/bmp.bmHeight; xScale=min(xScale,yScale); yScale=xScale; dWidth=(int)(xScale*bmp.bmWidth); dHeight=(int)(yScale*bmp.bmHeight); //CalcPosition imgPos.x=workRect.left+((wWidth-dWidth)>>1); imgPos.y=workRect.top+((wHeight-dHeight)>>1); //DrawImage if (!gl_b_GDIPlusFail) //Use gdi+ engine { DrawAvatarImageWithGDIp(memDC,imgPos.x,imgPos.y,dWidth,dHeight,hPreviewBitmap,0,0,bmp.bmWidth,bmp.bmHeight,8,255); } else { BLENDFUNCTION bf={AC_SRC_OVER, 0, 255, AC_SRC_ALPHA }; imgDC=CreateCompatibleDC(dis->hDC); imgOldbmp=SelectObject(imgDC,hPreviewBitmap); mod_AlphaBlend(memDC,imgPos.x,imgPos.y,dWidth,dHeight,imgDC,0,0,bmp.bmWidth,bmp.bmHeight,bf); SelectObject(imgDC,imgOldbmp); mod_DeleteDC(imgDC); } } BitBlt(dis->hDC,dis->rcItem.left,dis->rcItem.top,mWidth,mHeight,memDC,0,0,SRCCOPY); SelectObject(memDC,holdbmp); DeleteObject(hbmp); mod_DeleteDC(memDC); } break; case WM_NOTIFY: switch (((LPNMHDR)lParam)->idFrom) { case IDC_TREE1: { NMTREEVIEWA * nmtv = (NMTREEVIEWA *) lParam; if (!nmtv) return 0; if (nmtv->hdr.code==TVN_SELCHANGEDA || nmtv->hdr.code==TVN_SELCHANGEDW) { SkinListData * sd=NULL; if (hPreviewBitmap) { DeleteObject(hPreviewBitmap); hPreviewBitmap=NULL; } if (nmtv->itemNew.lParam) { //char sdFile[MAX_PATH]={0}; sd=(SkinListData*)nmtv->itemNew.lParam; //PathCompactPathExA(sdFile,sd->File,60,0); { char buf[MAX_PATH]; CallService(MS_UTILS_PATHTORELATIVE, (WPARAM)sd->File, (LPARAM)buf); SendDlgItemMessageA(hwndDlg,IDC_EDIT_SKIN_FILENAME,WM_SETTEXT,0,(LPARAM)buf); //TODO made filepath unicode } { char prfn[MAX_PATH]={0}; char imfn[MAX_PATH]={0}; char skinfolder[MAX_PATH]={0}; GetPrivateProfileStringA("Skin_Description_Section","Preview","",imfn,sizeof(imfn),sd->File); GetSkinFolder(sd->File,skinfolder); _snprintf(prfn,sizeof(prfn),"%s\\%s",skinfolder,imfn); CallService(MS_UTILS_PATHTOABSOLUTE,(WPARAM)prfn,(LPARAM) imfn); hPreviewBitmap=skin_LoadGlyphImage(imfn); } EnableWindow(GetDlgItem(hwndDlg,IDC_BUTTON_APPLY_SKIN),TRUE); EnableWindow(GetDlgItem(hwndDlg,IDC_BUTTON_INFO),TRUE); if (hPreviewBitmap) InvalidateRect(GetDlgItem(hwndDlg,IDC_PREVIEW),NULL,TRUE); else //prepeare text { char Author[255]; char URL[MAX_PATH]; char Contact[255]; char Description[400]; char text[2000]; SkinListData* sd=NULL; HTREEITEM hti=TreeView_GetSelection(GetDlgItem(hwndDlg,IDC_TREE1)); if (hti==0) return 0; { TVITEM tvi={0}; tvi.hItem=hti; tvi.mask=TVIF_HANDLE|TVIF_PARAM; TreeView_GetItem(GetDlgItem(hwndDlg,IDC_TREE1),&tvi); sd=(SkinListData*)(tvi.lParam); } if (!sd) return 0; if(sd->File && !strchr(sd->File,'%')) { GetPrivateProfileStringA("Skin_Description_Section","Author","(unknown)",Author,sizeof(Author),sd->File); GetPrivateProfileStringA("Skin_Description_Section","URL","",URL,sizeof(URL),sd->File); GetPrivateProfileStringA("Skin_Description_Section","Contact","",Contact,sizeof(Contact),sd->File); GetPrivateProfileStringA("Skin_Description_Section","Description","",Description,sizeof(Description),sd->File); _snprintf(text,sizeof(text),Translate("Preview is not available\n\n%s\n----------------------\n\n%s\n\nAUTHOR(S):\n%s\n\nCONTACT:\n%s\n\nHOMEPAGE:\n%s"), sd->Name,Description,Author,Contact,URL); } else { _snprintf(text,sizeof(text),Translate("%s\n\n%s\n\nAUTHORS:\n%s\n\nCONTACT:\n%s\n\nWEB:\n%s\n\n\n"), "Luna v0.4", Translate("This is default Modern Contact list skin based on 'Luna' theme"), "graphics by Angeli-Ka\ntemplate by FYR", "JID: [email protected]", "modern.saopp.info" ); } ShowWindow(GetDlgItem(hwndDlg,IDC_PREVIEW),SW_HIDE); ShowWindow(GetDlgItem(hwndDlg,IDC_STATIC_INFO),SW_SHOW); SendDlgItemMessageA(hwndDlg,IDC_STATIC_INFO,WM_SETTEXT,0,(LPARAM)text); } } else { //no selected SendDlgItemMessage(hwndDlg,IDC_EDIT_SKIN_FILENAME,WM_SETTEXT,0,(LPARAM)TranslateT("Select skin from list")); EnableWindow(GetDlgItem(hwndDlg,IDC_BUTTON_APPLY_SKIN),FALSE); EnableWindow(GetDlgItem(hwndDlg,IDC_BUTTON_INFO),FALSE); SendDlgItemMessageA(hwndDlg,IDC_STATIC_INFO,WM_SETTEXT,0,(LPARAM)Translate("Please select skin to apply")); ShowWindow(GetDlgItem(hwndDlg,IDC_PREVIEW),SW_HIDE); } ShowWindow(GetDlgItem(hwndDlg,IDC_PREVIEW),hPreviewBitmap?SW_SHOW:SW_HIDE); return 0; } else if (nmtv->hdr.code==TVN_SELCHANGEDA || nmtv->hdr.code==TVN_SELCHANGEDW) { if (nmtv->itemOld.lParam) mir_free((void*)(nmtv->itemOld.lParam)); return 0; } break; } case 0: switch (((LPNMHDR)lParam)->code) { case PSN_APPLY: { { DWORD tick=GetTickCount(); { /* Text Colors */ DWORD c1,c2,c3,c4; c1=SendDlgItemMessage(hwndDlg,IDC_COLOUR_MENUNORMAL,CPM_GETCOLOUR,0,0); c2=SendDlgItemMessage(hwndDlg,IDC_COLOUR_MENUSELECTED,CPM_GETCOLOUR,0,0); c3=SendDlgItemMessage(hwndDlg,IDC_COLOUR_FRAMES,CPM_GETCOLOUR,0,0); c4=SendDlgItemMessage(hwndDlg,IDC_COLOUR_STATUSBAR,CPM_GETCOLOUR,0,0); DBWriteContactSettingDword(NULL,"Menu", "TextColour", c1); DBWriteContactSettingDword(NULL,"Menu", "SelTextColour", c2); DBWriteContactSettingDword(NULL,"FrameTitleBar", "TextColour", c3); DBWriteContactSettingDword(NULL,"StatusBar", "TextColour", c4); /* End of Text colors */ } pcli->pfnClcBroadcast( INTM_RELOADOPTIONS,0,0); NotifyEventHooks(ME_BACKGROUNDCONFIG_CHANGED,0,0); pcli->pfnClcBroadcast( INTM_INVALIDATE,0,0); RedrawWindow(GetParent(pcli->hwndContactTree),NULL,NULL,RDW_INVALIDATE|RDW_FRAME|RDW_ALLCHILDREN); } return 0; } break; } break; } }
LRESULT WindowImplBase::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { LONG styleValue = ::GetWindowLong(*this, GWL_STYLE); styleValue &= ~WS_CAPTION; ::SetWindowLong(*this, GWL_STYLE, styleValue | WS_CLIPSIBLINGS | WS_CLIPCHILDREN); RECT rcClient; ::GetClientRect(*this, &rcClient); ::SetWindowPos(*this, NULL, rcClient.left, rcClient.top, rcClient.right - rcClient.left, \ rcClient.bottom - rcClient.top, SWP_FRAMECHANGED); m_PaintManager.Init(m_hWnd); m_PaintManager.AddPreMessageFilter(this); CDialogBuilder builder; CDuiString strResourcePath=m_PaintManager.GetResourcePath(); if (strResourcePath.IsEmpty()) { strResourcePath=m_PaintManager.GetInstancePath(); strResourcePath+=GetSkinFolder().GetData(); } m_PaintManager.SetResourcePath(strResourcePath.GetData()); switch(GetResourceType()) { case UILIB_ZIP: m_PaintManager.SetResourceZip(GetZIPFileName().GetData(), true); break; case UILIB_ZIPRESOURCE: { HRSRC hResource = ::FindResource(m_PaintManager.GetResourceDll(), GetResourceID(), _T("ZIPRES")); if( hResource == NULL ) return 0L; DWORD dwSize = 0; HGLOBAL hGlobal = ::LoadResource(m_PaintManager.GetResourceDll(), hResource); if( hGlobal == NULL ) { #if defined(WIN32) && !defined(UNDER_CE) ::FreeResource(hResource); #endif return 0L; } dwSize = ::SizeofResource(m_PaintManager.GetResourceDll(), hResource); if( dwSize == 0 ) return 0L; m_lpResourceZIPBuffer = new BYTE[ dwSize ]; if (m_lpResourceZIPBuffer != NULL) { ::CopyMemory(m_lpResourceZIPBuffer, (LPBYTE)::LockResource(hGlobal), dwSize); } #if defined(WIN32) && !defined(UNDER_CE) ::FreeResource(hResource); #endif m_PaintManager.SetResourceZip(m_lpResourceZIPBuffer, dwSize); } break; } CControlUI* pRoot=NULL; if (GetResourceType()==UILIB_RESOURCE) { STRINGorID xml(_ttoi(GetSkinFile().GetData())); pRoot = builder.Create(xml, _T("xml"), this, &m_PaintManager); } else pRoot = builder.Create(GetSkinFile().GetData(), (UINT)0, this, &m_PaintManager); ASSERT(pRoot); if (pRoot==NULL) { MessageBox(NULL,_T("加载资源文件失败"),_T("Duilib"),MB_OK|MB_ICONERROR); ExitProcess(1); return 0; } m_PaintManager.AttachDialog(pRoot); m_PaintManager.AddNotifier(this); InitWindow(); return 0; }
LRESULT WindowImplBase::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { m_PaintManager.Init(m_hWnd); m_PaintManager.AddPreMessageFilter(this); CDialogBuilder builder; if (m_PaintManager.GetResourcePath().IsEmpty()) { // 允许更灵活的资源路径定义 CDuiString strResourcePath=m_PaintManager.GetInstancePath(); strResourcePath+=GetSkinFolder().GetData(); m_PaintManager.SetResourcePath(strResourcePath.GetData()); } switch(GetResourceType()) { case UILIB_ZIP: m_PaintManager.SetResourceZip(GetZIPFileName().GetData(), true); break; case UILIB_ZIPRESOURCE: { HRSRC hResource = ::FindResource(m_PaintManager.GetResourceDll(), GetResourceID(), _T("ZIPRES")); if( hResource == NULL ) return 0L; DWORD dwSize = 0; HGLOBAL hGlobal = ::LoadResource(m_PaintManager.GetResourceDll(), hResource); if( hGlobal == NULL ) { #if defined(WIN32) && !defined(UNDER_CE) ::FreeResource(hResource); #endif return 0L; } dwSize = ::SizeofResource(m_PaintManager.GetResourceDll(), hResource); if( dwSize == 0 ) return 0L; m_lpResourceZIPBuffer = new BYTE[ dwSize ]; if (m_lpResourceZIPBuffer != NULL) { ::CopyMemory(m_lpResourceZIPBuffer, (LPBYTE)::LockResource(hGlobal), dwSize); } #if defined(WIN32) && !defined(UNDER_CE) ::FreeResource(hResource); #endif m_PaintManager.SetResourceZip(m_lpResourceZIPBuffer, dwSize); } break; } CControlUI* pRoot=NULL; if (GetResourceType()==UILIB_RESOURCE) { STRINGorID xml(_ttoi(GetSkinFile().GetData())); pRoot = builder.Create(xml, _T("xml"), this, &m_PaintManager); } else pRoot = builder.Create(GetSkinFile().GetData(), (UINT)0, this, &m_PaintManager); ASSERT(pRoot); if (pRoot==NULL) { MessageBox(NULL,_T("加载资源文件失败"),_T("Duilib"),MB_OK|MB_ICONERROR); ExitProcess(1); return 0; } m_PaintManager.AttachDialog(pRoot); m_PaintManager.AddNotifier(this); m_PaintManager.SetBackgroundTransparent(TRUE); InitWindow(); return 0; }
CControlUI* IDuiWindow::CreateRoot() { CDialogBuilder builder; CDuiString strResourcePath = GetSkinPath(); strResourcePath += GetSkinFolder().GetData(); m_PaintManager.SetResourcePath(strResourcePath.GetData()); CControlUI* pRoot = NULL; switch (GetResourceType()) { case UILIB_FILE: { pRoot = builder.Create(GetSkinFile().GetData(), (UINT)0, this, &m_PaintManager); } break; case UILIB_ZIP: { m_PaintManager.SetResourceZip(GetZIPFileName().GetData(), true); pRoot = builder.Create(GetSkinFile().GetData(), (UINT)0, this, &m_PaintManager); } break; case UILIB_RESOURCE: { HINSTANCE hCurInst = CPaintManagerUI::GetResourceDll(); m_PaintManager.SetCurResInstance(hCurInst); pRoot = builder.Create(_ttoi(GetSkinFile().GetData()), _T("xml"), this, &m_PaintManager); } break; case UILIB_ZIPRESOURCE: { HINSTANCE hCurInst = m_PaintManager.GetCurResInstance(); if (!hCurInst) hCurInst = CPaintManagerUI::GetResourceDll(); m_PaintManager.SetCurResInstance(hCurInst); HRSRC hResource = ::FindResource(hCurInst, GetResourceID(), _T("ZIPRES")); if (hResource == NULL) return NULL; DWORD dwSize = 0; HGLOBAL hGlobal = ::LoadResource(hCurInst, hResource); if (hGlobal == NULL) { #if defined(WIN32) && !defined(UNDER_CE) ::FreeResource(hResource); #endif return NULL; } dwSize = ::SizeofResource(hCurInst, hResource); if (dwSize == 0) return NULL; m_lpResourceZIPBuffer = new BYTE[dwSize]; if (m_lpResourceZIPBuffer != NULL) { ::CopyMemory(m_lpResourceZIPBuffer, (LPBYTE)::LockResource(hGlobal), dwSize); } #if defined(WIN32) && !defined(UNDER_CE) ::FreeResource(hResource); #endif m_PaintManager.SetResourceZip(m_lpResourceZIPBuffer, dwSize); pRoot = builder.Create(GetSkinFile().GetData(), (UINT)0, this, &m_PaintManager); } } ASSERT(pRoot); if (pRoot == NULL) { MessageBox(NULL, _T("加载资源文件失败"), _T("Duilib"), MB_OK | MB_ICONERROR); ExitProcess(1); return NULL; } return pRoot; }
LRESULT WindowImplBase::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { // 调整窗口样式 LONG styleValue = ::GetWindowLong(*this, GWL_STYLE); styleValue &= ~WS_CAPTION; ::SetWindowLong(*this, GWL_STYLE, styleValue | WS_CLIPSIBLINGS | WS_CLIPCHILDREN); // 调整窗口尺寸 RECT rcClient; ::GetClientRect(*this, &rcClient); ::SetWindowPos(*this, NULL, rcClient.left, rcClient.top, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, SWP_FRAMECHANGED); // 关联UI管理器 m_PaintManager.Init(m_hWnd, GetManagerName()); // 注册PreMessage回调 m_PaintManager.AddPreMessageFilter(this); // 允许更灵活的资源路径定义 if (CPaintManagerUI::GetResourcePath().IsEmpty()) { CDuiString strResourcePath = CPaintManagerUI::GetInstancePath(); strResourcePath += GetSkinFolder().GetData(); CPaintManagerUI::SetResourcePath(strResourcePath.GetData()); } // 加载资源 switch(GetResourceType()) { case UILIB_ZIP: CPaintManagerUI::SetResourceZip(GetZIPFileName().GetData(), true); break; case UILIB_ZIPRESOURCE: { HRSRC hResource = ::FindResource(m_PaintManager.GetResourceDll(), GetResourceID(), _T("ZIPRES")); if( hResource == NULL ) return 0L; DWORD dwSize = 0; HGLOBAL hGlobal = ::LoadResource(m_PaintManager.GetResourceDll(), hResource); if( hGlobal == NULL ) { #if defined(WIN32) && !defined(UNDER_CE) ::FreeResource(hResource); #endif return 0L; } dwSize = ::SizeofResource(m_PaintManager.GetResourceDll(), hResource); if( dwSize == 0 ) return 0L; CPaintManagerUI::SetResourceZip((LPBYTE)::LockResource(hGlobal), dwSize); #if defined(WIN32) && !defined(UNDER_CE) ::FreeResource(hResource); #endif } break; } // 资源管理器接口 InitResource(); // 创建主窗口 CControlUI* pRoot=NULL; CDialogBuilder builder; if (GetResourceType() == UILIB_RESOURCE) { STRINGorID xml(_ttoi(GetSkinFile().GetData())); pRoot = builder.Create(xml, _T("xml"), this, &m_PaintManager); } else { pRoot = builder.Create(GetSkinFile().GetData(), (UINT)0, this, &m_PaintManager); } if (pRoot == NULL) { MessageBox(NULL,_T("加载资源文件失败"),_T("Duilib"),MB_OK|MB_ICONERROR); ExitProcess(1); return 0; } m_PaintManager.AttachDialog(pRoot); // 添加Notify事件接口 m_PaintManager.AddNotifier(this); // 窗口初始化完毕 InitWindow(); return 0; }
CControlUI* CWin::CreateRoot(STRINGorID xml, LPCTSTR type /* = NULL */, IDialogBuilderCallback* pCallback /* = NULL */, CControlUI* pParent /* = NULL */) { CDialogBuilder builder; CDuiString strResourcePath = GetSkinPath(); strResourcePath += GetSkinFolder().GetData(); _paintManager->SetResourcePath(strResourcePath.GetData()); CControlUI* pRoot = NULL; switch (GetResourceType()) { case UILIB_FILE: { pRoot = builder.Create(xml, type, pCallback, _paintManager, pParent); } break; case UILIB_ZIP: { _paintManager->SetResourceZip(GetZIPFileName().GetData(), true); pRoot = builder.Create(xml, type, pCallback, _paintManager, pParent); } break; case UILIB_RESOURCE: { HINSTANCE hCurInst = CPaintManagerUI::GetResourceDll(); _paintManager->SetCurResInstance(hCurInst); pRoot = builder.Create(xml, type, pCallback, _paintManager, pParent); } break; case UILIB_ZIPRESOURCE: { HINSTANCE hCurInst = _paintManager->GetCurResInstance(); if (!hCurInst) hCurInst = CPaintManagerUI::GetResourceDll(); _paintManager->SetCurResInstance(hCurInst); HRSRC hResource = ::FindResource(hCurInst, GetResourceID(), _T("ZIPRES")); if (hResource == NULL) return NULL; DWORD dwSize = 0; HGLOBAL hGlobal = ::LoadResource(hCurInst, hResource); if (hGlobal == NULL) { #if defined(WIN32) && !defined(UNDER_CE) ::FreeResource(hResource); #endif return NULL; } dwSize = ::SizeofResource(hCurInst, hResource); if (dwSize == 0) return NULL; m_lpResourceZIPBuffer = new BYTE[dwSize]; if (m_lpResourceZIPBuffer != NULL) { ::CopyMemory(m_lpResourceZIPBuffer, (LPBYTE)::LockResource(hGlobal), dwSize); } #if defined(WIN32) && !defined(UNDER_CE) ::FreeResource(hResource); #endif _paintManager->SetResourceZip(m_lpResourceZIPBuffer, dwSize); pRoot = builder.Create(xml, type, pCallback, _paintManager, pParent); } } ASSERT(pRoot); if (pRoot == NULL) { MessageBox(NULL, _T("加载资源文件失败"), _T("Duilib"), MB_OK | MB_ICONERROR); ExitProcess(1); return NULL; } return pRoot; }