void SProgress::OnPaint(IRenderTarget *pRT) { SPainter painter; BeforePaint(pRT, painter); SASSERT(m_pSkinBg && m_pSkinPos); CRect rcClient; GetClientRect(&rcClient); m_pSkinBg->Draw(pRT, rcClient, WndState_Normal); CRect rcValue=rcClient; if(IsVertical()) { rcValue.bottom=rcValue.top+(int)(((__int64)rcValue.Height())*(m_nValue-m_nMinValue)/(__int64)(m_nMaxValue-m_nMinValue)); } else { rcValue.right=rcValue.left+(int)(((__int64)rcValue.Width())*(m_nValue-m_nMinValue)/(__int64)(m_nMaxValue-m_nMinValue)); } if(m_nValue>m_nMinValue) { m_pSkinPos->Draw(pRT, rcValue, WndState_Normal); } if (m_bShowPercent && !IsVertical()) { SStringT strPercent; strPercent.Format(_T("%d%%"), (int)((m_nValue-m_nMinValue) * 100/(m_nMaxValue-m_nMinValue))); pRT->DrawText(strPercent, strPercent.GetLength(), GetWindowRect(), DT_SINGLELINE | DT_CENTER | DT_VCENTER); } AfterPaint(pRT, painter); }
int Search(const SStringT & strKey,SStudentSearchAdapter *pSearchAdapter) { if(strKey.IsEmpty()) return 0; for(UINT i=0;i<m_stuCurrent.GetCount();i++) { SStringT str = SStringT().Format(_T("%s(%u)"),m_stuCurrent[i].strNick,m_stuCurrent[i].imid); if(str.Find(strKey)!=-1) { SStudentSearchAdapter::StudentInfo2 info; info.strText = str; info.bExpired = FALSE; info.nPos = i; pSearchAdapter->m_searchResult.Add(info); } } for(UINT i=0;i<m_stuExpired.GetCount();i++) { SStringT str = SStringT().Format(_T("%s(%u)"),m_stuExpired[i].strNick,m_stuExpired[i].imid); if(str.Find(strKey)!=-1) { SStudentSearchAdapter::StudentInfo2 info; info.strText = str; info.bExpired = TRUE; info.nPos = i; pSearchAdapter->m_searchResult.Add(info); } } return pSearchAdapter->m_searchResult.GetCount(); }
BOOL SMaskEdit::CopyToClipboard(const SStringT& strText) { if (!OpenClipboard(NULL)) return FALSE; ::EmptyClipboard(); int nLen = (strText.GetLength() + 1) * sizeof(TCHAR); HGLOBAL hglbCopy = ::GlobalAlloc(GMEM_MOVEABLE, nLen); if (hglbCopy == NULL) { ::CloseClipboard(); return FALSE; } LPTSTR lptstrCopy = (TCHAR*)GlobalLock(hglbCopy); _tcscpy_s(lptstrCopy, strText.GetLength() + 1, (LPCTSTR)strText); GlobalUnlock(hglbCopy); #ifndef _UNICODE ::SetClipboardData(CF_TEXT, hglbCopy); #else ::SetClipboardData(CF_UNICODETEXT, hglbCopy); #endif if (!::CloseClipboard()) return FALSE; return TRUE; }
SStringT CMainDlg::GetImageSrcFile( const SStringT & strSrcName ) { SListCtrl * pListFile=FindChildByName2<SListCtrl >(L"prj_list_file"); if(pListFile) { SStringTList lstName ; int nSegs = SplitString(strSrcName,_T(':'),lstName); for(int j=0;j<lstName.GetCount();j++) lstName[j].MakeLower(); for(int i=0;i<pListFile->GetItemCount();i++) { SStringT strType = pListFile->GetSubItemText(i,0); SStringT strName = pListFile->GetSubItemText(i,1); strType.MakeLower(); strName.MakeLower(); if((nSegs == 2 && lstName[0]==strType && lstName[1]==strName) || nSegs == 1 && lstName[0]==strName) { return pListFile->GetSubItemText(i,2); } } } return _T(""); }
void SPropertyItemColor::DrawItem( IRenderTarget *pRT,CRect rc ) { CRect rcColor = rc; rcColor.right = rcColor.left + KColorWidth; rcColor.DeflateRect(2,2); //画一个代表透明的网格背景 pRT->PushClipRect(&rcColor); bool bDrawY=true; for(int y=rcColor.top;y<rcColor.bottom;y+=KTransGridSize) { bool bDraw= bDrawY; for(int x=rcColor.left;x<rcColor.right;x+=KTransGridSize) { if(bDraw) pRT->FillSolidRect(CRect(CPoint(x,y),CSize(KTransGridSize,KTransGridSize)),RGBA(0xcc,0xcc,0xcc,0xff)); bDraw=!bDraw; } bDrawY=!bDrawY; } pRT->PopClip(); pRT->FillSolidRect(&rcColor,m_crValue); pRT->DrawRectangle(&rcColor); CRect rcValue = rc; rcValue.left += KColorWidth; SStringT strValue = GetString(); pRT->DrawText(strValue,strValue.GetLength(),&rcValue,DT_SINGLELINE|DT_VCENTER); }
void CMainDlg::OnListBoxExEvent( EventArgs *pEvt ) { EventOfPanel *pEvtOfPanel = (EventOfPanel*)pEvt; if(pEvtOfPanel->pOrgEvt->GetID() == EventCmd::EventID && pEvtOfPanel->pOrgEvt->sender->IsClass(SButton::GetClassName())) { int iItem = pEvtOfPanel->pPanel->GetItemIndex(); SStringT strMsg; strMsg.Format(_T("收到列表项:%d中的name为%s的窗口点击事件"),iItem,S_CW2T(pEvtOfPanel->pOrgEvt->nameFrom)); SMessageBox(m_hWnd,strMsg,_T("EVENTOFPANEL"),MB_OK|MB_ICONEXCLAMATION); } }
void CMainDlg::OnTreeBoxEvent( EventArgs *pEvt ) { EventOfPanel *pEvtOfPanel = (EventOfPanel*)pEvt; if(pEvtOfPanel->pOrgEvt->GetID() == EventCmd::EventID && pEvtOfPanel->pOrgEvt->sender->IsClass(SButton::GetClassName())) { HSTREEITEM hItem = (HSTREEITEM)pEvtOfPanel->pPanel->GetItemIndex(); SStringT strMsg; strMsg.Format(_T("收到treebox item:0x%08x中的name为%s的窗口点击事件"),hItem,S_CW2T(pEvtOfPanel->pOrgEvt->nameFrom)); SMessageBox(m_hWnd,strMsg,_T("EVENTOFPANEL"),MB_OK|MB_ICONEXCLAMATION); } if(pEvtOfPanel->pOrgEvt->GetID() >= EVT_ITEMPANEL_CLICK && pEvtOfPanel->pOrgEvt->GetID() <= EVT_ITEMPANEL_RCLICK) { HSTREEITEM hItem = (HSTREEITEM)pEvtOfPanel->pPanel->GetItemIndex(); STRACE(_T("OnTreeBoxEvent: EVT_ITEMPANEL_X, itemid=0x%08x,evtid=%d"),hItem,pEvtOfPanel->pOrgEvt->GetID()); } }
//定义唯一的一个R,UIRES对象,ROBJ_IN_CPP是resource.h中定义的宏。 ROBJ_IN_CPP int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int /*nCmdShow*/) { HRESULT hRes = OleInitialize(NULL); SASSERT(SUCCEEDED(hRes)); int nRet = 0; SComMgr *pComMgr = new SComMgr; HMODULE hSci = LoadLibrary(_T("SciLexer.dll")); if(!hSci){ MessageBox(GetActiveWindow(),_T("Load SciLexer.dll failed! \nCopying third-part/SciLexer/bin/SciLexer.dll to the running folder should resolve the problem!!"),_T("error"),MB_OK|MB_ICONSTOP); return -1; } //将程序的运行路径修改到项目所在目录所在的目录 TCHAR szCurrentDir[MAX_PATH] = { 0 }; GetModuleFileName(NULL, szCurrentDir, sizeof(szCurrentDir)); LPTSTR lpInsertPos = _tcsrchr(szCurrentDir, _T('\\')); _tcscpy(lpInsertPos + 1, _T("..\\demos\\uieditor\\")); SetCurrentDirectory(szCurrentDir); { BOOL bLoaded=FALSE; CAutoRefPtr<SOUI::IImgDecoderFactory> pImgDecoderFactory; CAutoRefPtr<SOUI::IRenderFactory> pRenderFactory; bLoaded = pComMgr->CreateRender_GDI((IObjRef**)&pRenderFactory); //SRenderFactory_GDI SASSERT_FMT(bLoaded,_T("load interface [render] failed!")); bLoaded=pComMgr->CreateImgDecoder((IObjRef**)&pImgDecoderFactory);//SImgDecoderFactory_GDIP SASSERT_FMT(bLoaded,_T("load interface [%s] failed!"),_T("imgdecoder")); pRenderFactory->SetImgDecoderFactory(pImgDecoderFactory);//SImgDecoderFactory_GDIP SApplication *theApp = new SApplication(pRenderFactory, hInstance); //向app注册自定义类 theApp->RegisterWndFactory(TplSWindowFactory<SMyButton>()); theApp->RegisterWndFactory(TplSWindowFactory<SMoveWnd>()); theApp->RegisterWndFactory(TplSWindowFactory<SFreeMoveWindow>()); theApp->RegisterWndFactory(TplSWindowFactory<SToolbox>()); theApp->RegisterWndFactory(TplSWindowFactory<STurn3dView>()); // extened controls theApp->RegisterWndFactory(TplSWindowFactory<SChromeTabCtrl>());//注册ChromeTabCtrl theApp->RegisterWndFactory(TplSWindowFactory<SImageMaskWnd>());//注册SImageMaskWnd theApp->RegisterWndFactory(TplSWindowFactory<SButtonEx>()); theApp->RegisterWndFactory(TplSWindowFactory<SWindowEx>()); theApp->RegisterWndFactory(TplSWindowFactory<SImRichEdit>()); theApp->RegisterWndFactory(TplSWindowFactory<SImagePlayer>()); theApp->RegisterWndFactory(TplSWindowFactory<SText>()); theApp->RegisterWndFactory(TplSWindowFactory<SImageEx>()); theApp->RegisterWndFactory(TplSWindowFactory<SSplitBar>()); theApp->RegisterWndFactory(TplSWindowFactory<SImageSwitcher>()); theApp->RegisterWndFactory(TplSWindowFactory<STabPage2>());//注册STabPage2 theApp->RegisterWndFactory(TplSWindowFactory<STabCtrl2>());//注册STabCtrl2 theApp->RegisterWndFactory(TplSWindowFactory<SAnimImg>());//注册SAnimImg theApp->RegisterWndFactory(TplSWindowFactory<SGifPlayer>());//注册gif theApp->RegisterWindowClass<SListBoxDrop>(); theApp->RegisterWindowClass<CDropWnd>(); theApp->RegisterWndFactory(TplSWindowFactory<SPropertyGrid>());//注册属性表控件 theApp->RegisterWndFactory(TplSWindowFactory<SScrollText>()); theApp->RegisterWndFactory(TplSWindowFactory<SRotateWindow>()); //extened skins theApp->RegisterSkinFactory(TplSkinFactory<SColorMask>()); theApp->RegisterSkinFactory(TplSkinFactory<SSkinMutiFrameImg>()); theApp->RegisterSkinFactory(TplSkinFactory<SSkinVScrollbar>()); theApp->RegisterSkinFactory(TplSkinFactory<SSkinNewScrollbar>()); theApp->RegisterSkinFactory(TplSkinFactory<SSkinGif>()); theApp->RegisterSkinFactory(TplSkinFactory<SSkinAPNG>()); { #ifdef _DEBUG HMODULE hSysRes = LoadLibrary(_T("soui-sys-resourced.dll")); #else HMODULE hSysRes = LoadLibrary(_T("soui-sys-resource.dll")); #endif CAutoRefPtr<IResProvider> sysResProvider; CreateResProvider(RES_PE, (IObjRef**)&sysResProvider); sysResProvider->Init((WPARAM)hSysRes, 0); theApp->LoadSystemNamedResource(sysResProvider); FreeLibrary(hSysRes); } CAutoRefPtr<IResProvider> pResProvider; #if (RES_TYPE == 0) CreateResProvider(RES_FILE, (IObjRef**)&pResProvider); if (!pResProvider->Init((LPARAM)_T("uires"), 0)) { SASSERT(0); return 1; } #else CreateResProvider(RES_PE, (IObjRef**)&pResProvider); pResProvider->Init((WPARAM)hInstance, 0); #endif //如果需要在代码中使用R::id::namedid这种方式来使用控件必须要这一行代码:2016年2月2日,R::id::namedXmlID是由uiresbuilder 增加-h .\res\resource.h idtable 这3个参数后生成的。 //theApp->InitXmlNamedID(namedXmlID,ARRAYSIZE(namedXmlID),TRUE); //theApp->Init(_T("XML_INIT")); //这一句不在需要了 在AddResProvider时自动执行初始化 theApp->AddResProvider(pResProvider, L"uidef:UIDESIGNER_XML_INIT"); // theApp->AddResProvider(pResProvider, L"uidef:xml_init"); //设置真窗口处理接口 CSouiRealWndHandler * pRealWndHandler = new CSouiRealWndHandler(); theApp->SetRealWndHandler(pRealWndHandler); pRealWndHandler->Release(); ////加载LUA脚本模块。 //CAutoRefPtr<IScriptModule> pScriptLua; //bLoaded=pComMgr->CreateScrpit_Lua((IObjRef**)&pScriptLua); //SASSERT_FMT(bLoaded,_T("load interface [%s] failed!"),_T("script_lua")); ////加载多语言翻译模块。 //CAutoRefPtr<ITranslatorMgr> trans; //bLoaded=pComMgr->CreateTranslator((IObjRef**)&trans); //SASSERT_FMT(bLoaded,_T("load interface [%s] failed!"),_T("translator")); //if(trans) //{//加载语言翻译包 // theApp->SetTranslator(trans); // pugi::xml_document xmlLang; // if(theApp->LoadXmlDocment(xmlLang,_T("lang_cn"),_T("translator"))) // { // CAutoRefPtr<ITranslator> langCN; // trans->CreateTranslator(&langCN); // langCN->Load(&xmlLang.child(L"language"),1);//1=LD_XML // trans->InstallTranslator(langCN); // } //} // BLOCK: Run application { CMainDlg dlgMain; dlgMain.Create(GetActiveWindow()); dlgMain.SendMessage(WM_INITDIALOG); dlgMain.CenterWindow(dlgMain.m_hWnd); dlgMain.ShowWindow(SW_SHOWNORMAL); SStringT uideffile = lpstrCmdLine; if (!uideffile.IsEmpty()) { uideffile.Trim(_T('\"')); uideffile += _T("uires.idx"); #ifdef _DEBUG SMessageBox(NULL, uideffile, NULL, MB_OK); #endif if(FileIsExist(uideffile)) dlgMain.OpenProject(uideffile); } nRet = theApp->Run(dlgMain.m_hWnd); } delete theApp; } FreeLibrary(hSci); delete pComMgr; OleUninitialize(); return nRet; }
SStringT CAccelerator::GetKeyName( WORD vk ) { SStringT str; switch(vk) { case VK_ESCAPE: str=_T("ESC"); break; case VK_RETURN: str=_T("Enter"); break; case VK_UP: str=_T("Up"); break; case VK_DOWN: str=_T("Down"); break; case VK_LEFT: str=_T("Left"); break; case VK_RIGHT: str=_T("Right"); break; case VK_HOME: str=_T("Home"); break; case VK_END: str=_T("End"); break; case VK_PRIOR: str=_T("PageUp"); break; case VK_NEXT: str=_T("PageDown"); break; case VK_INSERT: str=_T("Insert"); break; case VK_SPACE: str = _T("Space"); break; case VK_DELETE: str = _T("Delete"); break; case VK_PRINT: str = _T("Print"); break; default: if((vk>='0' && vk<='9')||(vk>='A' && vk<='Z')) str=(TCHAR)vk; else if(vk>=VK_NUMPAD0 && vk<=VK_NUMPAD9) str.Format(_T("Num %d"),vk-VK_NUMPAD0); else if(vk==VK_MULTIPLY) str=_T("Num *"); else if(vk==VK_ADD) str=_T("Num +"); else if(vk==VK_DECIMAL) str=_T("Num Del"); else if(vk>=VK_F1 && vk<=VK_F12) str.Format(_T("F%d"),vk-VK_F1+1); else { char c=MapVirtualKeyA(vk,2); switch(c) { case '-': case '=': case '[': case ']': case '\\': case ';': case '\'': case ',': case '.': case '/': case '`': str+=TCHAR(c); break; } } break; } return str; }
BOOL SMaskEdit::IsPromptPos(const SStringT& strLiteral, int nPos) const { return (nPos >= 0 && nPos < strLiteral.GetLength()) && (strLiteral[nPos] == m_chPrompt); }
BOOL SMessageBoxImpl::OnInitDialog( HWND wnd, LPARAM lInitParam ) { pugi::xml_node uiRoot=s_xmlMsgTemplate.child(L"SOUI"); InitFromXml(uiRoot); UINT uType = s_MsgBoxInfo.uType&0x0F; STabCtrl *pBtnSwitch= FindChildByName2<STabCtrl>(NAME_MSGBOX_BTNSWITCH); SASSERT(pBtnSwitch); pBtnSwitch->SetCurSel(g_msgBtnText[uType].nBtns-1); SWindow *pBtnPanel=pBtnSwitch->GetItem(g_msgBtnText[uType].nBtns-1); SASSERT(pBtnPanel); pugi::xml_node nodeBtnTxt = s_xmlMsgTemplate.child(L"SOUI").child(L"buttonText"); for(int i=0; i<g_msgBtnText[uType].nBtns; i++) { SWindow *pBtn=pBtnPanel->FindChildByName(g_wcsNameOfBtns[i]); int nID = g_msgBtnText[uType].btnInfo[i].uBtnID; pBtn->SetID(nID); SStringT strText = OnGetButtonText(nID); if(strText.IsEmpty()) { const wchar_t *pBtnText = g_msgBtnText[uType].btnInfo[i].szText; //先从模板中的buttonText节点里查按钮的文字 pugi::xml_node nodeTxt = nodeBtnTxt.child(pBtnText); if(nodeTxt) pBtnText=nodeTxt.text().get(); //从翻译引擎中翻译 strText = S_CW2T(TR(pBtnText,GetTranslatorContext())); } pBtn->SetWindowText(strText); } const wchar_t *pszFrameAttr=uiRoot.attribute(L"frameSize").value(); CRect rcFrame; swscanf(pszFrameAttr,L"%d,%d,%d,%d",&rcFrame.left,&rcFrame.top,&rcFrame.right,&rcFrame.bottom); CSize szMin; const wchar_t *pszMinAttr=uiRoot.attribute(L"minSize").value(); swscanf(pszMinAttr,L"%d,%d",&szMin.cx,&szMin.cy); SWindow * pTitle= FindChildByName(NAME_MSGBOX_TITLE); SASSERT(pTitle); pTitle->SetWindowText(S_CW2T(TR(s_MsgBoxInfo.pszCaption?S_CT2W(s_MsgBoxInfo.pszCaption):L"prompt",GetTranslatorContext()))); SWindow * pMsg= FindChildByName(NAME_MSGBOX_TEXT); SASSERT(pMsg); pMsg->SetWindowText(S_CW2T(TR(S_CT2W(s_MsgBoxInfo.pszText),GetTranslatorContext()))); OnSetIcon(s_MsgBoxInfo.uType); pMsg->GetRoot()->UpdateLayout(); CSize szText = pMsg->GetDesiredSize(NULL); CRect rcText = pMsg->GetWindowRect();//获取msg的左边位置 CSize szWnd; szWnd.cx=max(szMin.cx,rcText.left + szText.cx + rcFrame.right); szWnd.cy=max(szMin.cy,rcFrame.top + szText.cy + rcFrame.bottom); SetWindowPos(0,0,0,szWnd.cx,szWnd.cy,SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER); pMsg->GetRoot()->UpdateLayout(); //将msg text的上下位置设置成和parent相同。 rcText = pMsg->GetWindowRect(); CRect rcTextParent = pMsg->GetParent()->GetWindowRect(); rcText.top = rcTextParent.top; rcText.bottom = rcTextParent.bottom; pMsg->Move(rcText); CenterWindow(); return 0; }