void CInformationBarSettingsDialog::UpdateSelectedItem() { LRESULT Sel=::SendDlgItemMessage(m_hDlg,IDC_SETTINGS_INFORMATION_BAR_ITEM_LIST,LB_GETCURSEL,0,0); if (Sel>=0) { RECT rc; ::SendDlgItemMessage(m_hDlg,IDC_SETTINGS_INFORMATION_BAR_ITEM_LIST, LB_GETITEMRECT,Sel,reinterpret_cast<LPARAM>(&rc)); ::InvalidateRect(GetItemHandle(IDC_SETTINGS_INFORMATION_BAR_ITEM_LIST),&rc,TRUE); } }
///////////////////////////////////////////////////////////////////////////// // 分析单个行 // 语法规则: // 1.可以有若干个设置项,用";"隔开 // 2.添加列: ADDCOLUMN name,width,format // 3.删除列: DELCOLUMN nCol|all // 4.删除行: DELITEM nItem|all // 5.设置分割符: SEPARATOR=??? // 6.设置所有行的颜色: SETROWCOLORS cText cTextBk // 7.设置颜色表的某个颜色: SETCOLORTABLE index color // 8.修改控件风格: MODIFYSTYLE ADD|REMOVE style // 9.从注册表读取列信息: READPROFILE Section, Entry // 10.向注册表写入列信息: WRITEPROFILE Section, Entry // 11.设置窗口关闭时执行的脚本: SETCLOSESCRIPT script // 12.设置字体: SETFONT font size ///////////////////////////////////////////////////////////////////////////// void CTreeOutCtrl::ParseALine(CString strLine) { CString strSet = strLine; strSet.MakeUpper(); int pos; if((pos = strSet.Find("ADDCOLUMN ")) == 0) // 添加列 { CString strColName; CString strFormat = _T("LEFT"); strSet = strLine.Right(strLine.GetLength()-10); int nPos = strSet.Find(","); strColName = strSet.Left(nPos); strSet = strSet.Right(strSet.GetLength()-nPos-1); // 解析列宽度 nPos = strSet.Find(","); if(nPos != -1) { strFormat = strSet.Right(strSet.GetLength()-nPos-1); strFormat.MakeUpper(); strSet = strSet.Left(nPos); } int nWidth = atoi(strSet); RVSUBITEM rvs; rvs.nFormat = RVCF_TEXT|RVCF_EX_TOOLTIP|RVCF_EX_PERSISTENT; if(strFormat == _T("CENTER")) { rvs.nFormat |= RVCF_CENTER; } else if(strFormat == _T("RIGHT")) { rvs.nFormat |= RVCF_RIGHT; } rvs.lpszText = strColName.GetBuffer(strColName.GetLength()+1); rvs.iWidth = nWidth; int nSubItem = GetActiveSubItemCount(); DefineSubItem(nSubItem, &rvs, TRUE); ActivateSubItem(nSubItem, nSubItem); strColName.ReleaseBuffer(); } else if((pos = strSet.Find("DELCOLUMN ")) == 0) // 删除列 { strSet = strSet.Right(strSet.GetLength()-10); if(strSet == _T("ALL")) { UndefineAllSubItems(); m_asItemScript.RemoveAll(); } else { int nCol = atoi(strSet); UndefineSubItem(nCol); if(GetActiveSubItemCount() == 0) { m_asItemScript.RemoveAll(); } } } else if((pos = strSet.Find("DELITEM ")) == 0) // 删除行 { strSet = strSet.Right(strSet.GetLength()-8); if(strSet == _T("ALL")) { DeleteAllItems(); m_asItemScript.RemoveAll(); } else { int nItem = atoi(strSet); HTREEITEM hItem = GetItemHandle(nItem); DeleteItem(hItem); if(GetItemCount() == 0) { m_asItemScript.RemoveAll(); } } } else if((pos = strSet.Find("SEPARATOR=")) == 0) // 设置分割符 { m_strSeparator = strLine.Right(strLine.GetLength()-10); } else if((pos = strSet.Find("SETROWCOLORS ")) == 0) // 设置所有行颜色 { strSet = strSet.Right(strSet.GetLength()-13); CString strBkColor = _T(""); int nPos = strSet.Find(" "); if(nPos != -1) { strBkColor = strSet.Right(strSet.GetLength()-nPos-1); strSet = strSet.Left(nPos); } COLORREF cText = RGB(0,0,0); COLORREF cTextBk = RGB(255,255,255); int nPos1; if((nPos1 = strSet.Find("RGB(")) == 0) { strSet = strSet.Right(strSet.GetLength()-pos-4); strSet.Delete(strSet.GetLength()-1, 1); nPos1 = strSet.Find(","); CString strTmp = strSet.Left(nPos1); int nr = atoi(strTmp); strSet = strSet.Mid(nPos1 + 1, strSet.GetLength() - nPos1 -1); nPos1 = strSet.Find(","); strTmp = strSet.Left(nPos1); int ng = atoi(strTmp); strTmp = strSet.Mid(nPos1 + 1, strSet.GetLength() - nPos1 -1); int nb = atoi(strTmp); cText = RGB(nr, ng, nb); } strSet = strBkColor; if((nPos1 = strSet.Find("RGB(")) == 0) { strSet = strSet.Right(strSet.GetLength()-pos-4); strSet.Delete(strSet.GetLength()-1, 1); nPos1 = strSet.Find(","); CString strTmp = strSet.Left(nPos1); int nr = atoi(strTmp); strSet = strSet.Mid(nPos1 + 1, strSet.GetLength() - nPos1 -1); nPos1 = strSet.Find(","); strTmp = strSet.Left(nPos1); int ng = atoi(strTmp); strTmp = strSet.Mid(nPos1 + 1, strSet.GetLength() - nPos1 -1); int nb = atoi(strTmp); cTextBk = RGB(nr, ng, nb); } SetRowColors(cText, cTextBk); } else if((pos = strSet.Find("SETCOLORTABLE ")) == 0) // 设置颜色表的某个颜色 { strSet = strSet.Right(strSet.GetLength()-14); int nIndex = 0; int nPos = strSet.Find(" "); if(nPos != -1) { CString strIndex = strSet.Left(nPos); nIndex = atoi(strIndex); if(nIndex<0 || nIndex>9) return; strSet.Delete(0, nPos+1); } if(strSet.Find("RGB(") == 0) { strSet = strSet.Right(strSet.GetLength()-pos-4); strSet.Delete(strSet.GetLength()-1, 1); int nPos1 = strSet.Find(","); CString strTmp = strSet.Left(nPos1); int nr = atoi(strTmp); strSet = strSet.Mid(nPos1 + 1, strSet.GetLength() - nPos1 -1); nPos1 = strSet.Find(","); strTmp = strSet.Left(nPos1); int ng = atoi(strTmp); strTmp = strSet.Mid(nPos1 + 1, strSet.GetLength() - nPos1 -1); int nb = atoi(strTmp); COLORREF cColor = RGB(nr, ng, nb); SetColor(nIndex, cColor); } } else if((pos = strSet.Find("MODIFYSTYLE ")) == 0) // 修改控件风格 { strSet = strSet.Right(strSet.GetLength()-12); BOOL bAdd = TRUE; if(strSet.Find("REMOVE(") == 0) { bAdd = FALSE; strSet.Delete(0, 7); } else { strSet.Delete(0, 4); } int nPos = strSet.Find(")"); if(nPos != -1) { strSet = strSet.Left(nPos); } int nStyle = 0; while((nPos=strSet.Find("|")) != -1) { CString strStyle = strSet.Left(nPos); nStyle |= ParseStyle(strStyle); strSet.Delete(0, nPos+1); } nStyle |= ParseStyle(strSet); ModifyStyle(bAdd ? 0 : nStyle, bAdd ? nStyle : 0); } else if(strSet.Find("READPROFILE ") == 0) // 从注册表读取列信息 { strLine = strLine.Right(strLine.GetLength()-12); int nPos = strLine.Find(","); if(nPos != -1) { CString strSection = strLine.Left(nPos); CString strEntry = strLine.Right(strLine.GetLength()-nPos-1); GetProfile(strSection, strEntry); } } else if(strSet.Find("WRITEPROFILE ") == 0) // 向注册表写入列信息 { strLine = strLine.Right(strLine.GetLength()-13); int nPos = strLine.Find(","); if(nPos != -1) { CString strSection = strLine.Left(nPos); CString strEntry = strLine.Right(strLine.GetLength()-nPos-1); WriteProfile(strSection, strEntry); } } else if(strSet.Find("SETCLOSESCRIPT ") == 0) // 设置窗口关闭时执行的脚本 { m_strScriptClose = strLine.Right(strLine.GetLength()-15); } else if(strSet.Find("SETFONT ") == 0) // 设置字体 { strLine = strLine.Right(strLine.GetLength()-8); CString strFont = strLine; int nSize = 0; int nPos = strLine.Find(","); if(nPos != -1) { strFont = strLine.Left(nPos); CString strSize = strLine.Right(strLine.GetLength()-nPos-1); nSize = atoi(strSize); } SetSelfFont(strFont, nSize); } }
INT_PTR CAboutDialog::DlgProc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam) { switch (uMsg) { case WM_INITDIALOG: { SetItemText(IDC_ABOUT_VERSION, APP_NAME_W L" ver." APP_VERSION_TEXT_W L" (" APP_PLATFORM_W L")"); m_pLogoImage=m_Core.GetGraphicSystem().CreateImage(); m_pLogoImage->LoadFromResource(m_hinst,MAKEINTRESOURCE(ID_PNG_LOGO),L"PNG"); m_fTransparentLogo=false; BOOL fCompositionEnabled; if (::DwmIsCompositionEnabled(&fCompositionEnabled)==S_OK && fCompositionEnabled) { HWND hwndLogo=GetItemHandle(IDC_ABOUT_LOGO); RECT rc; ::GetWindowRect(hwndLogo,&rc); MARGINS Margins={rc.right-rc.left,0,0,0}; if (::DwmExtendFrameIntoClientArea(hDlg,&Margins)==S_OK) m_fTransparentLogo=true; } AdjustPos(); } return TRUE; case WM_PAINT: { PAINTSTRUCT ps; RECT rcLogo,rcClient; ::BeginPaint(hDlg,&ps); Graphics::CCanvas *pCanvas=m_Core.GetGraphicSystem().CreateCanvas(ps.hdc); if (m_fTransparentLogo) pCanvas->Clear(Graphics::Color(0,0,0,0)); ::GetWindowRect(::GetDlgItem(hDlg,IDC_ABOUT_LOGO),&rcLogo); ::OffsetRect(&rcLogo,-rcLogo.left,-rcLogo.top); ::GetClientRect(hDlg,&rcClient); rcClient.left=rcLogo.right; pCanvas->FillRect(rcClient,Graphics::Color(::GetSysColor(COLOR_3DFACE))); if (!m_fTransparentLogo) pCanvas->FillRect(rcLogo,Graphics::Color(255,255,255)); if (m_pLogoImage!=nullptr) { pCanvas->DrawImage((rcLogo.right-m_pLogoImage->GetWidth())/2, (rcLogo.bottom-m_pLogoImage->GetHeight())/2, m_pLogoImage); } delete pCanvas; ::EndPaint(hDlg,&ps); } return TRUE; case WM_DWMCOMPOSITIONCHANGED: m_fTransparentLogo=false; return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: case IDCANCEL: //::EndDialog(hDlg,LOWORD(wParam)); Destroy(); return TRUE; } return TRUE; case WM_DESTROY: TSTask::SafeDelete(m_pLogoImage); m_Core.RemoveModelessDialog(this); return TRUE; } return FALSE; }
INT_PTR CInformationBarSettingsDialog::DlgProc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam) { switch (uMsg) { case WM_INITDIALOG: { const CTSTaskCentreSettings &Settings=m_Core.GetSettings(); Settings.MainBoard.GetInformationBarFont(&m_CurrentFont); m_InformationBar.SetItemMargin(m_Core.ScaleDPI(m_InformationBar.GetDefaultItemMargin())); m_InformationBar.SetFont(m_CurrentFont); m_InformationBar.Create(hDlg); m_ItemMargin=MapDialogUnitX(2); ::SendDlgItemMessage(hDlg,IDC_SETTINGS_INFORMATION_BAR_ITEM_LIST, LB_SETITEMHEIGHT,0,m_InformationBar.GetHeight()+m_ItemMargin*2); CMainBoardSettings::InformationBarItemList ItemList; Settings.MainBoard.GetInformationBarItemList(&ItemList); for (size_t i=0;i<ItemList.size();i++) { CMainBoardSettings::InformationBarItemInfo *pItemInfo= new CMainBoardSettings::InformationBarItemInfo(ItemList[i]); ::SendDlgItemMessage(hDlg,IDC_SETTINGS_INFORMATION_BAR_ITEM_LIST, LB_ADDSTRING,0,reinterpret_cast<LPARAM>(pItemInfo)); InformationBarItems::CCustomInformationItem *pItem= new InformationBarItems::CCustomInformationItem(0); pItem->SetFormat(pItemInfo->Format.c_str()); m_InformationBar.AddItem(pItem); } static const LPCTSTR TextAlignList[] = { TEXT("����"),TEXT("�E��"),TEXT("����"), }; for (int i=0;i<_countof(TextAlignList);i++) { ::SendDlgItemMessage(hDlg,IDC_SETTINGS_INFORMATION_BAR_TEXT_ALIGN, CB_ADDSTRING,0,reinterpret_cast<LPARAM>(TextAlignList[i])); } ::SendDlgItemMessage(hDlg,IDC_SETTINGS_INFORMATION_BAR_ITEM_WIDTH_SPIN, UDM_SETRANGE32,0,10000); SetItemInfo(); SetFontInfo(hDlg,IDC_SETTINGS_INFORMATION_BAR_FONT_INFO,m_CurrentFont); SetTimeComboBox(hDlg,IDC_SETTINGS_INFORMATION_BAR_UPDATE_INTERVAL, 1,10,Settings.MainBoard.GetInformationBarUpdateInterval()); CheckItem(IDC_SETTINGS_INFORMATION_BAR_SHOW_ERROR, Settings.MainBoard.GetInformationBarShowError()); SetTimeComboBox(hDlg,IDC_SETTINGS_INFORMATION_BAR_ERROR_DURATION, 1,10,Settings.MainBoard.GetInformationBarErrorDuration()); EnableItems(IDC_SETTINGS_INFORMATION_BAR_ERROR_DURATION_LABEL, IDC_SETTINGS_INFORMATION_BAR_ERROR_DURATION, Settings.MainBoard.GetInformationBarShowError()); } return TRUE; case WM_DRAWITEM: { LPDRAWITEMSTRUCT pdis=reinterpret_cast<LPDRAWITEMSTRUCT>(lParam); if (wParam==IDC_SETTINGS_INFORMATION_BAR_ITEM_LIST) { switch (pdis->itemAction) { case ODA_DRAWENTIRE: case ODA_SELECT: { const bool fSelected=(pdis->itemState & ODS_SELECTED)!=0; ::FillRect(pdis->hDC,&pdis->rcItem, reinterpret_cast<HBRUSH>( static_cast<INT_PTR>((fSelected?COLOR_HIGHLIGHT:COLOR_WINDOW)+1))); if ((int)pdis->itemID>=0) { const CMainBoardSettings::InformationBarItemInfo *pItemInfo= reinterpret_cast<const CMainBoardSettings::InformationBarItemInfo*>(pdis->itemData); InformationBarItems::CCustomInformationItem *pItem= static_cast<InformationBarItems::CCustomInformationItem*>(m_InformationBar.GetItem(pdis->itemID)); if (pItem==nullptr) break; pItem->SetTextAlign(CInformationBar::CItem::TextAlign(pItemInfo->TextAlign)); RECT rcItem=pdis->rcItem; ::InflateRect(&rcItem,-m_ItemMargin,-m_ItemMargin); RECT rcMargin=m_InformationBar.GetItemMargin(); rcItem.right=rcItem.left+ (pItemInfo->Width<0?CInformationBar::CItem::DEFAULT_WIDTH:pItemInfo->Width)+ rcMargin.left+rcMargin.right; m_InformationBar.DrawItemPreview(pItem,pdis->hDC,rcItem); } } if ((pdis->itemState & ODS_FOCUS)==0) break; case ODA_FOCUS: if ((pdis->itemState & ODS_NOFOCUSRECT)==0) ::DrawFocusRect(pdis->hDC,&pdis->rcItem); break; } } } return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_SETTINGS_INFORMATION_BAR_ITEM_LIST: if (HIWORD(wParam)==LBN_SELCHANGE) { SetItemInfo(); } return TRUE; case IDC_SETTINGS_INFORMATION_BAR_NEW_ITEM: { CMainBoardSettings::InformationBarItemInfo *pItemInfo= new CMainBoardSettings::InformationBarItemInfo; pItemInfo->TextAlign=0; LRESULT Index=::SendDlgItemMessage(hDlg,IDC_SETTINGS_INFORMATION_BAR_ITEM_LIST, LB_ADDSTRING,0,reinterpret_cast<LPARAM>(pItemInfo)); ::SendDlgItemMessage(hDlg,IDC_SETTINGS_INFORMATION_BAR_ITEM_LIST, LB_SETCURSEL,Index,0); InformationBarItems::CCustomInformationItem *pItem= new InformationBarItems::CCustomInformationItem(0); m_InformationBar.AddItem(pItem); SetItemInfo(); } return TRUE; case IDC_SETTINGS_INFORMATION_BAR_DELETE_ITEM: { LRESULT Sel=::SendDlgItemMessage(hDlg,IDC_SETTINGS_INFORMATION_BAR_ITEM_LIST,LB_GETCURSEL,0,0); if (Sel>=0) { delete reinterpret_cast<CMainBoardSettings::InformationBarItemInfo*>( ::SendDlgItemMessage(hDlg,IDC_SETTINGS_INFORMATION_BAR_ITEM_LIST,LB_GETITEMDATA,Sel,0)); ::SendDlgItemMessage(hDlg,IDC_SETTINGS_INFORMATION_BAR_ITEM_LIST,LB_DELETESTRING,Sel,0); m_InformationBar.DeleteItem(Sel); SetItemInfo(); } } return TRUE; case IDC_SETTINGS_INFORMATION_BAR_MOVE_UP_ITEM: case IDC_SETTINGS_INFORMATION_BAR_MOVE_DOWN_ITEM: { HWND hwndList=GetItemHandle(IDC_SETTINGS_INFORMATION_BAR_ITEM_LIST); bool fUp=LOWORD(wParam)==IDC_SETTINGS_INFORMATION_BAR_MOVE_UP_ITEM; LRESULT Sel=::SendMessage(hwndList,LB_GETCURSEL,0,0); LRESULT To; if (fUp) { if (Sel<1) return TRUE; To=Sel-1; } else { if (Sel<0 || Sel+1>=::SendMessage(hwndList,LB_GETCOUNT,0,0)) return TRUE; To=Sel+1; } ::SendMessage(hwndList,WM_SETREDRAW,FALSE,0); LRESULT ItemData=::SendMessage(hwndList,LB_GETITEMDATA,Sel,0); ::SendMessage(hwndList,LB_DELETESTRING,Sel,0); ::SendMessage(hwndList,LB_INSERTSTRING,To,ItemData); ::SendMessage(hwndList,LB_SETCURSEL,To,0); UpdateItemFormat(int(Sel)); UpdateItemFormat(int(To)); ::SendMessage(hwndList,WM_SETREDRAW,TRUE,0); ::InvalidateRect(hwndList,nullptr,TRUE); SetItemInfo(); } return TRUE; case IDC_SETTINGS_INFORMATION_BAR_FORMAT: if (HIWORD(wParam)==EN_CHANGE) { CMainBoardSettings::InformationBarItemInfo *pItem=GetSelectedItem(); if (pItem!=nullptr) { GetItemString(IDC_SETTINGS_INFORMATION_BAR_FORMAT,&pItem->Format); UpdateItemFormat((int)::SendDlgItemMessage(hDlg,IDC_SETTINGS_INFORMATION_BAR_ITEM_LIST,LB_GETCURSEL,0,0)); UpdateSelectedItem(); } } return TRUE; case IDC_SETTINGS_INFORMATION_BAR_FORMAT_MENU: { HMENU hmenu=::CreatePopupMenu(); InformationBarItems::CCustomInformationItem::ParameterInfo Info; for (int i=0;InformationBarItems::CCustomInformationItem::GetParameterInfo(i,&Info);i++) { WCHAR szText[128]; TSTask::FormatString(szText,_countof(szText),L"%s\t%s", Info.pszParameter,Info.pszText); ::AppendMenu(hmenu,MF_STRING | MF_ENABLED,i+1,szText); } RECT rc; ::GetWindowRect(GetItemHandle(IDC_SETTINGS_INFORMATION_BAR_FORMAT_MENU),&rc); int Result=::TrackPopupMenu(hmenu,TPM_RETURNCMD,rc.left,rc.bottom,0,hDlg,nullptr); ::DestroyMenu(hmenu); if (Result>0 && InformationBarItems::CCustomInformationItem::GetParameterInfo(Result-1,&Info)) { HWND hwndEdit=GetItemHandle(IDC_SETTINGS_INFORMATION_BAR_FORMAT); DWORD Start,End; ::SetFocus(hwndEdit); ::SendMessage(hwndEdit,EM_GETSEL, reinterpret_cast<WPARAM>(&Start),reinterpret_cast<LPARAM>(&End)); ::SendMessage(hwndEdit,EM_REPLACESEL, TRUE,reinterpret_cast<LPARAM>(Info.pszParameter)); if (End<Start) Start=End; ::SendMessage(hwndEdit,EM_SETSEL, Start,Start+::lstrlen(Info.pszParameter)); } } return TRUE; case IDC_SETTINGS_INFORMATION_BAR_TEXT_ALIGN: if (HIWORD(wParam)==CBN_SELCHANGE) { CMainBoardSettings::InformationBarItemInfo *pItem=GetSelectedItem(); if (pItem!=nullptr) { pItem->TextAlign= (int)::SendDlgItemMessage(hDlg,IDC_SETTINGS_INFORMATION_BAR_TEXT_ALIGN,CB_GETCURSEL,0,0); UpdateSelectedItem(); } } return TRUE; case IDC_SETTINGS_INFORMATION_BAR_ITEM_WIDTH: if (HIWORD(wParam)==EN_CHANGE) { CMainBoardSettings::InformationBarItemInfo *pItem=GetSelectedItem(); if (pItem!=nullptr) { pItem->Width=GetItemInt(IDC_SETTINGS_INFORMATION_BAR_ITEM_WIDTH); UpdateSelectedItem(); } } return TRUE; case IDC_SETTINGS_INFORMATION_BAR_CHOOSE_FONT: if (ChooseFontDialog(hDlg,&m_CurrentFont)) { SetFontInfo(hDlg,IDC_SETTINGS_INFORMATION_BAR_FONT_INFO,m_CurrentFont); m_InformationBar.SetFont(m_CurrentFont); ::SendDlgItemMessage(hDlg,IDC_SETTINGS_INFORMATION_BAR_ITEM_LIST, LB_SETITEMHEIGHT,0,m_InformationBar.GetHeight()+m_ItemMargin*2); ::InvalidateRect(GetItemHandle(IDC_SETTINGS_INFORMATION_BAR_ITEM_LIST),nullptr,TRUE); } return TRUE; case IDC_SETTINGS_INFORMATION_BAR_SHOW_ERROR: EnableItems(IDC_SETTINGS_INFORMATION_BAR_ERROR_DURATION_LABEL, IDC_SETTINGS_INFORMATION_BAR_ERROR_DURATION, IsItemChecked(IDC_SETTINGS_INFORMATION_BAR_SHOW_ERROR)); } return TRUE; case WM_DESTROY: { int ItemCount=(int)::SendDlgItemMessage(hDlg,IDC_SETTINGS_INFORMATION_BAR_ITEM_LIST,LB_GETCOUNT,0,0); for (int i=0;i<ItemCount;i++) { delete reinterpret_cast<CMainBoardSettings::InformationBarItemInfo*>( ::SendDlgItemMessage(hDlg,IDC_SETTINGS_INFORMATION_BAR_ITEM_LIST,LB_GETITEMDATA,i,0)); } ::SendDlgItemMessage(hDlg,IDC_SETTINGS_INFORMATION_BAR_ITEM_LIST,LB_RESETCONTENT,0,0); m_InformationBar.DeleteAllItems(); } return TRUE; } return FALSE; }