// MBEmotionsWnd.cpp : implementation file // #include "stdafx.h" #include "MBSettingWnd.h" #define SYSATTR_FLAG_BASE 0x00000001 #define SYSATTR_FLAG_SOUND 0x00000002 #define SYSATTR_FLAG_HOTKEY 0x00000004 // CMBSettingWnd CMBSettingWnd::CMBSettingWnd() : SHostWnd(_T("LAYOUT:XML_MBSETTING")) { m_bLayoutInited = FALSE; m_pServerMgr = NULL; m_pUserLogin = NULL; m_nCurSelHotKey = -1; m_nInitFalg = 0; m_nApplyFalg = 0; } CMBSettingWnd::~CMBSettingWnd() { } BOOL CMBSettingWnd::OnInitDialog(HWND wndFocus, LPARAM lInitParam) { InitBaseAttribute(); m_bLayoutInited = TRUE; SImageButton *pImgBtn = FindChildByName2(_T("btn_apply")); if(pImgBtn) pImgBtn->EnableWindow(FALSE); return TRUE; } int CMBSettingWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) { SetMsgHandled(FALSE); return 0; } void CMBSettingWnd::OnSize(UINT nType, SOUI::CSize size) { SetMsgHandled(FALSE); if (!m_bLayoutInited) return; } void CMBSettingWnd::SetServerMgrPtr( CMBServerMgr *pMBServerMgr ) { m_pServerMgr = pMBServerMgr; m_pUserLogin = pMBServerMgr->GetUserLogin(); } void CMBSettingWnd::OnClose() { CSimpleWnd::DestroyWindow(); } void CMBSettingWnd::InitBaseAttribute() { CString strLoginName = _T(""); CString strServerID = _T(""); if(m_pServerMgr) { strLoginName = m_pServerMgr->GetUserLogin()->m_strLoginName; strServerID = m_pServerMgr->GetUserLogin()->m_strOrgServerID; } m_nInitFalg |=SYSATTR_FLAG_BASE ; CString strText; int nStartLoginTime; BOOL bCheck = CBaseCommFun::IsAutoRun(nStartLoginTime); SCheckBox *pCheckBox = FindChildByName2(L"ck_autorun"); if( pCheckBox != NULL ) pCheckBox->SetCheck(bCheck); /*strText.Format(_T("%d"),nStartLoginTime); SEdit *pEdit = FindChildByName2(L"edit_login_minute"); if( pEdit != NULL ) { pEdit->SetWindowTextW(strText); }*/ CString strMyCfgPath; strMyCfgPath = CMBUserProFun::GetMyIniFile(strLoginName, strServerID); if( CStrFileUtils::IsExist( strMyCfgPath ) ) { CString strAutoLogin,strSavePwd; CIniFile iniFile( strMyCfgPath ); iniFile.GetProfileString(MBC_LOGIN_SECTION,MBC_LOGIN_SECTION_SAVEPWD,strSavePwd); iniFile.GetProfileString(MBC_LOGIN_SECTION,MBC_LOGIN_SECTION_AUOTOLOGIN,strAutoLogin); pCheckBox = FindChildByName2(L"ck_savepwd"); if(pCheckBox) { if( strSavePwd == _T("1") ){ pCheckBox->SetCheck( TRUE ); }else{ pCheckBox->SetCheck( FALSE ); } } pCheckBox = FindChildByName2(L"ck_autologin"); if(pCheckBox) { if( strAutoLogin == _T("1") ){ pCheckBox->SetCheck( TRUE ); }else{ pCheckBox->SetCheck( FALSE ); } } } CString strDownloadPath = m_pUserLogin->m_strDownloadPath;; //CMBUserProFun::LoadDefaultDwonloadPath(strDownloadPath, strLoginName,strServerID); SEdit *pEdit = FindChildByName2(L"edit_downloaddir"); if( pEdit != NULL ) { pEdit->SetReadOnly(TRUE); pEdit->SetWindowTextW(strDownloadPath); } } void CMBSettingWnd::InitHotKeyAttribute() { CString strLoginName = _T(""); CString strServerID = _T(""); if(m_pServerMgr) { strLoginName = m_pServerMgr->GetUserLogin()->m_strLoginName; strServerID = m_pServerMgr->GetUserLogin()->m_strOrgServerID; } m_nInitFalg |=SYSATTR_FLAG_HOTKEY ; BOOL bIsNoHintClose; BOOL bIsCloseIdExit; CMBUserProFun::GetCloseHint(bIsNoHintClose, bIsCloseIdExit, strLoginName,strServerID ); SCheckBox *pCheckBox = FindChildByName2(L"ck_closehint"); if( pCheckBox != NULL ) pCheckBox->SetCheck(bIsNoHintClose); SRadioBox *pRadioBoxExit = FindChildByName2(L"rd_exit"); SRadioBox *pRadioBoxTray = FindChildByName2(L"rd_tray"); if(bIsCloseIdExit) { if( pRadioBoxExit != NULL ) pRadioBoxExit->SetCheck(true); } else { if( pRadioBoxTray != NULL ) pRadioBoxTray->SetCheck(true); } BOOL bCheck = FALSE; CMBUserProFun::LoadQuickKey(bCheck, strLoginName,strServerID ); pCheckBox = FindChildByName2(L"ck_sethotkeyInfo"); if( pCheckBox != NULL ) pCheckBox->SetCheck( !bCheck); m_arHotKey.RemoveAll(); m_arHotKey.Copy( m_pServerMgr->GetUserLogin()->GetUserPro()->m_arHotKey ); m_pCbxHotKeyView = FindChildByName2(L"cbx_hotkey_type"); if(m_pCbxHotKeyView) { SListView* pListview = m_pCbxHotKeyView->GetListView(); SASSERT(pListview); CObjectAdapter *pAdapter = new CObjectAdapter(this); pListview->SetAdapter(pAdapter); HOTKEYITEM item; int nCount = m_arHotKey.GetSize(); for ( int nIndex = 0; nIndex < nCount; nIndex++ ) { item = m_arHotKey.GetAt( nIndex ); pAdapter->AddText((SStringT)item.strName ); } pAdapter->Release(); m_pCbxHotKeyView->SetCurSel(0); OnClickCBItem(_T("cbx_hotkey_type"),0,_T("")); } pCheckBox = FindChildByName2(L"ck_sethotkeyInfo"); if( pCheckBox != NULL ) bCheck = pCheckBox->IsChecked(); SWindow *pWindow = FindChildByName2(L"wnd_hotkey"); if(pWindow) { if( bCheck) pWindow->SetAttribute(_T("visible"),_T("1")); else pWindow->SetAttribute(_T("visible"),_T("0")); } } void CMBSettingWnd::OnOK() { if( ApplyDataSet()) PostMessage(WM_CLOSE); } void CMBSettingWnd::OnApply() { ApplyDataSet(); SImageButton *pImgBtn = FindChildByName2(_T("btn_apply")); if(pImgBtn) pImgBtn->EnableWindow(FALSE); } BOOL CMBSettingWnd::ApplyDataSet() { if(!m_bLayoutInited) { return FALSE; } BOOL bRet = TRUE; if( !m_nApplyFalg) return TRUE; if( m_nApplyFalg & SYSATTR_FLAG_BASE) bRet |= SaveBaseAttribute(); if( m_nApplyFalg & SYSATTR_FLAG_HOTKEY) bRet |= SaveHotKeyAttribute(); return bRet; } BOOL CMBSettingWnd::SaveBaseAttribute() { if(!m_bLayoutInited) { return FALSE; } CString strLoginName = _T(""); CString strServerID = _T(""); if(m_pServerMgr) { strLoginName = m_pServerMgr->GetUserLogin()->m_strLoginName; strServerID = m_pServerMgr->GetUserLogin()->m_strOrgServerID; } CString strText = _T(""); BOOL bCheck =FALSE; CMBUserProFun::LoadCanHideLogin(bCheck,strLoginName,strServerID); SCheckBox *pCheckBox = FindChildByName2(L"ck_autorun"); if( pCheckBox != NULL ) bCheck = pCheckBox->IsChecked(); int nStartLoginTime = 30; /*SEdit *pEdit = FindChildByName2(L"edit_login_minute"); if( pEdit != NULL ) { strText = pEdit->GetWindowTextW(); } nStartLoginTime = _tstol(strText);*/ CBaseCommFun::SetAutoRun(bCheck,nStartLoginTime); CString strMyCfgPath; strMyCfgPath = CMBUserProFun::GetMyIniFile(strLoginName, strServerID); CString strAutoLogin,strSavePwd; CIniFile iniFile( strMyCfgPath ); bCheck = FALSE; pCheckBox = FindChildByName2(L"ck_savepwd"); if( pCheckBox != NULL ) { bCheck = pCheckBox->IsChecked(); if(bCheck) strSavePwd = _T("1"); else strSavePwd = _T("0"); iniFile.SetProfileString(MBC_LOGIN_SECTION,MBC_LOGIN_SECTION_SAVEPWD,strSavePwd); } bCheck = FALSE; pCheckBox = FindChildByName2(L"ck_autologin"); if( pCheckBox != NULL ) { bCheck = pCheckBox->IsChecked(); if(bCheck) strAutoLogin = _T("1"); else strAutoLogin = _T("0"); iniFile.SetProfileString(MBC_LOGIN_SECTION,MBC_LOGIN_SECTION_AUOTOLOGIN,strAutoLogin); } CString strDownloadPath; SEdit *pEdit = FindChildByName2(L"edit_downloaddir"); if( pEdit != NULL ) strDownloadPath = pEdit->GetWindowTextW(); CMBUserProFun::SaveDefaultDwonloadPath(strDownloadPath, strLoginName,strServerID); if(m_pServerMgr) { m_pUserLogin->m_strDownloadPath = strDownloadPath; } BOOL bIsNoHintClose = FALSE; BOOL bIsCloseIdExit = FALSE; pCheckBox = FindChildByName2(L"ck_closehint"); if( pCheckBox != NULL ) bIsNoHintClose = pCheckBox->IsChecked(); SRadioBox *pRadioBox = FindChildByName2(L"rd_exit"); if( pRadioBox != NULL ) bIsCloseIdExit = pRadioBox->IsChecked(); CMBUserProFun::SetCloseHint(bIsNoHintClose, bIsCloseIdExit, strLoginName,strServerID ); m_nApplyFalg &= ~SYSATTR_FLAG_BASE; return TRUE; } BOOL CMBSettingWnd::SaveHotKeyAttribute() { if(!m_bLayoutInited) { return FALSE; } CString strLoginName = _T(""); CString strServerID = _T(""); if(m_pServerMgr) { strLoginName = m_pServerMgr->GetUserLogin()->m_strLoginName; strServerID = m_pServerMgr->GetUserLogin()->m_strOrgServerID; } if ( !m_pCbxHotKeyView ) return FALSE; int nCurSel = m_pCbxHotKeyView->GetCurSel(); if ( nCurSel == CB_ERR ) return FALSE; SRadioBox *pRadioBoxCustom = FindChildByName2(L"rd_customhotkey"); SRadioBox *pRadioBoxDefault = FindChildByName2(L"rd_defaulthotkey"); SHotKeyCtrl *pHotKeyCtrl = FindChildByName2(L"hotkey_custom"); SStatic *pStatic = FindChildByName2(L"text_defaulthotkey"); // ±£´æÊý¾Ýµ½¶ÔÏó HOTKEYITEM item; if (GetHotKeyItem( nCurSel, item ) ) { if(pRadioBoxDefault) item.bDefault = pRadioBoxDefault->IsChecked(); if(pHotKeyCtrl) pHotKeyCtrl->GetHotKey( item.wVirtualKeyCode, item.wModifiers ); m_arHotKey.SetAt( nCurSel, item ); } // ¼ì²éÈȼüÊÇ·ñÓгåÍ» INT_PTR nIndex, nCount; INT_PTR nIndexBegin; HOTKEYITEM itemNext; UINT nID = 0; WORD dwVirtualKeyCode, dwModifiers; WORD dwVirtualKeyCodeNext, dwModifiersNext; BOOL bReturn, bItemReturn; CString strItem, strInfo, strCaption; bReturn = true; bItemReturn = true; nCount = m_arHotKey.GetSize( ); for ( nIndex = 0; nIndex < nCount; nIndex++ ) { item = m_arHotKey.GetAt( nIndex ); if ( item.bDefault ) { dwVirtualKeyCode = item.wDefVirtualKeyCode; dwModifiers = item.wDefModifiers; } else { dwVirtualKeyCode = item.wVirtualKeyCode; dwModifiers = item.wModifiers; } for ( nIndexBegin = nIndex + 1; nIndexBegin < nCount; nIndexBegin++ ) { itemNext = m_arHotKey.GetAt( nIndexBegin ); if ( itemNext.bDefault ) { dwVirtualKeyCodeNext = itemNext.wDefVirtualKeyCode; dwModifiersNext = itemNext.wDefModifiers; } else { dwVirtualKeyCodeNext = itemNext.wVirtualKeyCode; dwModifiersNext = itemNext.wModifiers; } // ½øÐÐ±È½Ï if ( dwVirtualKeyCode != 0 && dwModifiers != 0 && dwVirtualKeyCode == dwVirtualKeyCodeNext && dwModifiers == dwModifiersNext ) { strInfo.Format( _T( "ÒÔÏÂÁ½¸öÀàÐÍʹÓÃÏàͬµÄÈȼü\r\n%s£¬%s"), item.strName, itemNext.strName ); strCaption = _T("Ìáʾ"); MessageBox(m_hWnd,strInfo, strCaption, MB_OK | MB_ICONWARNING ); return FALSE; } } } BOOL bCloseQuickKey = false; SCheckBox *pCheckBox = FindChildByName2(L"ck_sethotkeyInfo"); if( pCheckBox != NULL ) bCloseQuickKey = !pCheckBox->IsChecked(); CMBUserProFun::SaveQuickKey( bCloseQuickKey, strLoginName ,strServerID ); // ¼ì²éÊý¾ÝÊÇ·ñÓиüРif ( !CheckModifyHotKey( ) ) { if(m_pUserLogin->GetUserPro()->m_bCloseQuickKey != bCloseQuickKey) { m_pUserLogin->GetUserPro()->m_bCloseQuickKey = bCloseQuickKey; if(bCloseQuickKey) { m_pUserLogin->GetUserPro()->DoRegisterHotKey( ); } else { m_pUserLogin->GetUserPro()->DoRegisterHotKey( ); } } m_nApplyFalg &= ~SYSATTR_FLAG_HOTKEY; return TRUE; // Êý¾Ýδ¸üР} // ±£´æÊý¾Ý CMBUserProFun::SaveHotKeyInfo( m_arHotKey,strLoginName ,strServerID ); m_pUserLogin->GetUserPro()->m_arHotKey.RemoveAll( ); m_pUserLogin->GetUserPro()->m_arHotKey.Copy( m_arHotKey ); m_pUserLogin->GetUserPro()->m_bCloseQuickKey = bCloseQuickKey; // ÖØÐ¶¨Òå¿ì½Ý¼ü m_pUserLogin->GetUserPro()->DoUnRegisterHotKey( ); m_pUserLogin->GetUserPro()->DoRegisterHotKey( ); m_nApplyFalg &= ~SYSATTR_FLAG_HOTKEY; return TRUE; } void CMBSettingWnd::OnTabPageRadioSwitch(int nID) { if(m_bLayoutInited) { STabCtrl *pTab = FindChildByName2(L"tab_setting"); if(pTab) { switch (nID){ case 10000: if( !(m_nInitFalg & SYSATTR_FLAG_BASE)) InitBaseAttribute(); pTab->SetCurSel(0); break; case 10001: if( !(m_nInitFalg & SYSATTR_FLAG_HOTKEY)) InitHotKeyAttribute(); pTab->SetCurSel(1); break; } } } } void CMBSettingWnd::OnClickCBItem(CString strCtrlName,int nIndex,CString strText) { HOTKEYITEM item; BOOL bCustomHotKey = FALSE; SRadioBox *pRadioBoxCustom = FindChildByName2(L"rd_customhotkey"); SRadioBox *pRadioBoxDefault = FindChildByName2(L"rd_defaulthotkey"); SHotKeyCtrl *pHotKeyCtrl = FindChildByName2(L"hotkey_custom"); SStatic *pStatic = FindChildByName2(L"text_defaulthotkey"); if(m_nCurSelHotKey >= 0) { bCustomHotKey = FALSE; item = m_arHotKey.GetAt( m_nCurSelHotKey ); if( pRadioBoxCustom != NULL ) bCustomHotKey = pRadioBoxCustom->IsChecked(); item.bDefault = true; if(bCustomHotKey) { item.bDefault = false; if( pHotKeyCtrl != NULL ) { pHotKeyCtrl->GetHotKey(item.wVirtualKeyCode, item.wModifiers); } } m_arHotKey.SetAt( m_nCurSelHotKey, item ); } if ( nIndex < 0 || nIndex >= m_arHotKey.GetSize( ) ) return; item = m_arHotKey.GetAt( nIndex ); if(pStatic) pStatic->SetWindowText(GetHotKeyName( item.wDefVirtualKeyCode, item.wDefModifiers )); if(item.bDefault) { if(pRadioBoxDefault) pRadioBoxDefault->SetCheck(TRUE); if( pHotKeyCtrl != NULL ) { pHotKeyCtrl->EnableWindow(FALSE); if (item.wVirtualKeyCode != 0 || item.wModifiers != 0) { pHotKeyCtrl->SetHotKey(item.wVirtualKeyCode, item.wModifiers); } else { pHotKeyCtrl->SetHotKey(item.wDefVirtualKeyCode, item.wDefModifiers); } } } else { if(pRadioBoxCustom) pRadioBoxCustom->SetCheck(TRUE); if( pHotKeyCtrl != NULL ) { pHotKeyCtrl->SetHotKey(item.wVirtualKeyCode, item.wModifiers); pHotKeyCtrl->SetFocus(); } } } void CMBSettingWnd::OnSetBaseAttribute() { SetApplyFlag( m_nApplyFalg | SYSATTR_FLAG_BASE); } void CMBSettingWnd::OnSelDownloadDir() { CString strTitle; CString strDownloadPath; if ( !CBaseCommFun::SelExplorerDir( _T( "ÉèÖñ£´æÄ¿Â¼"), strDownloadPath, m_hWnd ) ) return ; SEdit *pEdit = FindChildByName2(L"edit_downloaddir"); if( pEdit != NULL ) pEdit->SetWindowTextW(strDownloadPath); SetApplyFlag( m_nApplyFalg | SYSATTR_FLAG_BASE); } CString CMBSettingWnd::GetKeyName(UINT vk, BOOL fExtended) { LONG lScan = MapVirtualKey(vk, 0) << 16; // if it's an extended key, add the extended flag if (fExtended) lScan |= 0x01000000L; CString str; int nBufferLen = 64; int nLen; do { nBufferLen *= 2; LPTSTR psz = str.GetBufferSetLength(nBufferLen); nLen = ::GetKeyNameText(lScan, psz, nBufferLen + 1); str.ReleaseBuffer(nLen); } while (nLen == nBufferLen); return str; } CString CMBSettingWnd::GetHotKeyName( WORD dwVirtualKeyCode, WORD dwModifiers ) { CString strKeyName; if (dwVirtualKeyCode != 0 || dwModifiers != 0) { if (dwModifiers & MOD_CONTROL) { strKeyName += GetKeyName(VK_CONTROL, FALSE); strKeyName += _T("+"); } if (dwModifiers & MOD_SHIFT) { strKeyName += GetKeyName(VK_SHIFT, FALSE); strKeyName += _T("+"); } if (dwModifiers & MOD_ALT) { strKeyName += GetKeyName(VK_MENU, FALSE); strKeyName += _T("+"); } strKeyName += GetKeyName(dwVirtualKeyCode, FALSE); } return strKeyName; } bool CMBSettingWnd::GetHotKeyItem( int nCurSel, HOTKEYITEM &item ) { if ( nCurSel < 0 || nCurSel >= m_arHotKey.GetSize() ) return false; item = m_arHotKey.GetAt( nCurSel ); return true; } bool CMBSettingWnd::CheckModifyHotKey( ) { HOTKEYITEM item, itemKey; INT_PTR nIndex, nCount; CHotKeyItemArray *pArHotKey; if ( !m_pServerMgr ) return false; pArHotKey = &m_pServerMgr->GetUserLogin()->GetUserPro()->m_arHotKey; nCount = m_arHotKey.GetSize( ); if ( nCount != pArHotKey->GetSize( ) ) return true; for ( nIndex = 0; nIndex < nCount; nIndex++ ) { item = m_arHotKey.GetAt( nIndex ); itemKey = pArHotKey->GetAt( nIndex ); if ( !(item.bDefault == itemKey.bDefault && item.strName == itemKey.strName && item.wDefModifiers == itemKey.wDefModifiers && item.wDefVirtualKeyCode == item.wDefVirtualKeyCode && item.wModifiers == itemKey.wModifiers && item.wVirtualKeyCode == itemKey.wVirtualKeyCode) ) { return true; } } return false; } void CMBSettingWnd::OnDefaultHotKey() { SHotKeyCtrl *pHotKeyCtrl = FindChildByName2(L"hotkey_custom"); if(pHotKeyCtrl) { pHotKeyCtrl->EnableWindow(false); } SetApplyFlag( m_nApplyFalg | SYSATTR_FLAG_HOTKEY); } void CMBSettingWnd::OnCustomHotKey() { SHotKeyCtrl *pHotKeyCtrl = FindChildByName2(L"hotkey_custom"); if(pHotKeyCtrl) { pHotKeyCtrl->EnableWindow(true); pHotKeyCtrl->SetFocus(); } SetApplyFlag( m_nApplyFalg | SYSATTR_FLAG_HOTKEY); } void CMBSettingWnd::OnSetHotKeyInfo() { BOOL bSetQuickKey = false; SCheckBox *pCheckBox = FindChildByName2(L"ck_sethotkeyInfo"); if( pCheckBox != NULL ) bSetQuickKey = pCheckBox->IsChecked(); SWindow *pWindow = FindChildByName2(L"wnd_hotkey"); if(pWindow) { if( bSetQuickKey) pWindow->SetAttribute(_T("visible"),_T("1")); else pWindow->SetAttribute(_T("visible"),_T("0")); } SetApplyFlag( m_nApplyFalg | SYSATTR_FLAG_HOTKEY); } void CMBSettingWnd::SetApplyFlag(int nFlag) { if( nFlag) { SImageButton *pImgBtn = FindChildByName2(_T("btn_apply")); if(pImgBtn) pImgBtn->EnableWindow(TRUE,TRUE); } m_nApplyFalg = nFlag; }