bool main_frame::OnWeiboContentNotify( void *param ) { TNotifyUI *pNotify = (TNotifyUI *)param; if (_tcsicmp(pNotify->pSender->GetName() , _T("weiboContent")) == 0) { CRichEditUI *pRichEdit = static_cast<CRichEditUI*>(pNotify->pSender); if (pRichEdit && (_tcsicmp(pNotify->sType,_T("richEditTxViewChanged")) == 0)) { CDuiString strText = pRichEdit->GetText(); int length = strText.GetLength(); if (length < 140) { CDuiString strLimit; strLimit.Format(_T("%d"),140-length); CLabelUI *pLabel = static_cast<CLabelUI*>(m_PaintManager.FindControl(_T("limitTextLength"))); if (pLabel) { pLabel->SetText(strLimit); } } } } return true; }
void CMainWindow::OnClick(TNotifyUI& msg) { if(msg.pSender->IsName(sysbtn::kCloseBtn)) { OnExit(msg); } else if (msg.pSender->IsName(sysbtn::kMaxBtn)) { SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, 0); return; } else if (msg.pSender->IsName(sysbtn::kRestoreBtn)) { SendMessage(WM_SYSCOMMAND, SC_RESTORE, 0); return; } else if (msg.pSender->IsName(sysbtn::kMinBtn)) { SendMessage(WM_SYSCOMMAND, SC_MINIMIZE, 0); return; } else if (msg.pSender->IsName(toppage::kSignatureBtn)) { msg.pSender->SetVisible(false); CRichEditUI* signature = static_cast<CRichEditUI*>(GetPaintMgr()->FindControl(toppage::kSignature)); if (signature != NULL) { signature->SetText(msg.pSender->GetText()); signature->SetVisible(true); signature->SetFocus(); signature->SetSelAll(); } } }
int ChatDialog::SetInputEditImg(CDuiString strimg) { CRichEditUI* pRichEdit = static_cast<CRichEditUI*>(paint_manager_.FindControl(kInputRichEditControlName)); if( pRichEdit == NULL ) return -1; pRichEdit->SetFocus(); //pRichEdit->InsertGif(strimg); //pRichEdit->SetBkColor() return 0; }
void CMainWindow::OnReturn(TNotifyUI& msg) { if (_tcsicmp(msg.pSender->GetName(), toppage::kSignature) == 0) { msg.pSender->SetVisible(false); CControlUI* signature_tip = GetPaintMgr()->FindControl(toppage::kSignatureBtn); if (signature_tip != NULL) { CRichEditUI* signature = static_cast<CRichEditUI*>(msg.pSender); if (signature != NULL) signature_tip->SetText(signature->GetText()); signature_tip->SetVisible(true); } } }
void main_frame::OnPrepare( TNotifyUI& msg ) { m_weiboManage.StartUp(); m_layoutManage.SetPaintManage(&m_PaintManager); //m_weiboManage.m_pLayoutManage = &m_layoutManage; m_weiboManage.UpdateUserProfile = std::tr1::bind(&CLayoutManage::UpdateUserProfile,&m_layoutManage,_1,_2,_3); m_weiboManage.UpdateUnread = std::tr1::bind(&CLayoutManage::UpdateUnread,&m_layoutManage,_1); m_weiboManage.UpdateTimelineList = std::tr1::bind(&CLayoutManage::UpdateTimelineList,&m_layoutManage,_1,_2,_3,_4,_5); CRichEditUI *pWeiboCotent = static_cast<CRichEditUI*>(m_PaintManager.FindControl(_T("weiboContent"))); if (pWeiboCotent) { pWeiboCotent->OnEvent += MakeDelegate(this,&main_frame::OnWeiboContentEvent); pWeiboCotent->OnNotify += MakeDelegate(this,&main_frame::OnWeiboContentNotify); pWeiboCotent->SetAutoURLDetect(); } CWebBrowserUI *pLoginWeb = static_cast<CWebBrowserUI*>(m_PaintManager.FindControl(_T("loginWnd"))); if (m_weiboManage.CheckExistUser()) { m_weiboManage.InitWeibo(); pLoginWeb->SetVisible(false); } else { CWebBrowserUI *pLoginWeb = static_cast<CWebBrowserUI*>(m_PaintManager.FindControl(_T("loginWnd"))); if (pLoginWeb) { m_pWebBrowserEventHander = new CMagiccWebBrowserEventHandler; m_pWebBrowserEventHander->SetMainFrame(this); pLoginWeb->SetWebBrowserEventHandler(m_pWebBrowserEventHander); pLoginWeb->NavigateUrl(_T("https://api.weibo.com/oauth2/authorize?client_id=397065771&response_type=code&redirect_uri=www.baidu.com")); } } CLabelUI *pUnreadTimeline = static_cast<CLabelUI*>(m_PaintManager.FindControl(_T("unreadTimelineCount"))); if (pUnreadTimeline) { pUnreadTimeline->OnEvent += MakeDelegate(this,&main_frame::OnRefreshUnReadTimeline); m_PaintManager.SetTimer(pUnreadTimeline,1,1000*10); } }
void Notify(TNotifyUI& msg) { if( msg.sType == _T("windowinit") ) OnPrepare(); else if( msg.sType == _T("click") ) { if( msg.pSender->GetName() == _T("insertimagebtn") ) { CRichEditUI* pRich = static_cast<CRichEditUI*>(m_pm.FindControl(_T("testrichedit"))); if( pRich ) { pRich->RemoveAll(); } } else if( msg.pSender->GetName() == _T("changeskinbtn") ) { if( CPaintManagerUI::GetResourcePath() == CPaintManagerUI::GetInstancePath() ) CPaintManagerUI::SetResourcePath(CPaintManagerUI::GetInstancePath() + _T("skin\\FlashRes")); else CPaintManagerUI::SetResourcePath(CPaintManagerUI::GetInstancePath()); CPaintManagerUI::ReloadSkin(); } } }
void main_frame::Notify( TNotifyUI& msg ) { if( msg.sType == _T("windowinit") ) OnPrepare(msg); else if (_tcsicmp(msg.sType,_T("click")) == 0) { if (_tcsicmp(msg.pSender->GetName(),_T("closebtn")) == 0 ) { Close(); } else if (_tcsicmp(msg.pSender->GetName(),_T("minbtn")) == 0) { SendMessage(WM_SYSCOMMAND, SC_MINIMIZE, 0); } else if (_tcsicmp(msg.pSender->GetName(),_T("maxbtn")) == 0) { SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, 0); } else if (_tcsicmp(msg.pSender->GetName(),_T("tagBtn")) == 0) { CRichEditUI *pRichEdit = static_cast<CRichEditUI*>(m_PaintManager.FindControl(_T("weiboContent"))); if (pRichEdit) { CDuiString strText = _T("#²åÈëÄãµÄ»°Ìâ#"); pRichEdit->SetText(strText); pRichEdit->SetSel(1,7); pRichEdit->SetFocus(); CLabelUI *plabel = static_cast<CLabelUI*>(m_PaintManager.FindControl(_T("defaultShowText"))); if (plabel) { plabel->SetVisible(false); } } } else if (_tcsicmp(msg.pSender->GetName(),_T("sendWeiboBtn")) == 0) { CRichEditUI *pRichEdit = static_cast<CRichEditUI*>(m_PaintManager.FindControl(_T("weiboContent"))); if (pRichEdit) { CDuiString strWeibo = pRichEdit->GetText(); if (strWeibo.GetLength() > 0) { DWORD dwNum = WideCharToMultiByte(CP_UTF8,NULL,strWeibo,-1,NULL,0,NULL,FALSE); char *psText; psText = new char[dwNum]; if(!psText) { delete []psText; } WideCharToMultiByte (CP_UTF8,NULL,strWeibo,-1,psText,dwNum,NULL,FALSE); m_weiboManage.PostNewWeibo(psText); delete []psText; pRichEdit->SetText(_T("")); } } } else if (_tcsicmp(msg.pSender->GetName(),_T("refreshBtn")) == 0) { m_weiboManage.RefreshTimeline(); } } }
bool main_frame::OnWeiboContentEvent( void *param ) { TEventUI *pEvent = (TEventUI*)param; if (pEvent->Type == UIEVENT_SETFOCUS ) { CHorizontalLayoutUI *pWeiboCotentContainer = static_cast<CHorizontalLayoutUI*>(m_PaintManager.FindControl(_T("weiboContentContainer"))); if (pWeiboCotentContainer) { pWeiboCotentContainer->SetBorderColor(RGB(0,0,255)); } CRichEditUI *pRichEdit = static_cast<CRichEditUI*>(pEvent->pSender); if (pRichEdit) { CDuiString strText = pRichEdit->GetText(); if (strText.GetLength() == 0) { CLabelUI *plabel = static_cast<CLabelUI*>(m_PaintManager.FindControl(_T("defaultShowText"))); if (plabel) { plabel->SetVisible(false); } } } } else if (pEvent->Type == UIEVENT_KILLFOCUS ) { CHorizontalLayoutUI *pWeiboCotentContainer = static_cast<CHorizontalLayoutUI*>(m_PaintManager.FindControl(_T("weiboContentContainer"))); if (pWeiboCotentContainer) { pWeiboCotentContainer->SetBorderColor(RGB(204,204,204)); } CRichEditUI *pRichEdit = static_cast<CRichEditUI*>(m_PaintManager.FindControl(_T("weiboContent"))); if (pRichEdit) { CDuiString strText = pRichEdit->GetText(); if (strText.GetLength() == 0) { CLabelUI *plabel = static_cast<CLabelUI*>(m_PaintManager.FindControl(_T("defaultShowText"))); if (plabel) { plabel->SetVisible(true); } } } } else if (pEvent->Type == UIEVENT_MOUSELEAVE) { CRichEditUI *pRichEdit = static_cast<CRichEditUI*>(m_PaintManager.FindControl(_T("weiboContent"))); if (pRichEdit) { if (!pRichEdit->IsFocused()) { CHorizontalLayoutUI *pWeiboCotentContainer = static_cast<CHorizontalLayoutUI*>(m_PaintManager.FindControl(_T("weiboContentContainer"))); if (pWeiboCotentContainer) { pWeiboCotentContainer->SetBorderColor(RGB(204,204,204)); } } } } else if (pEvent->Type == UIEVENT_MOUSEENTER) { CRichEditUI *pRichEdit = static_cast<CRichEditUI*>(m_PaintManager.FindControl(_T("weiboContent"))); if (pRichEdit) { if (!pRichEdit->IsFocused()) { CHorizontalLayoutUI *pWeiboCotentContainer = static_cast<CHorizontalLayoutUI*>(m_PaintManager.FindControl(_T("weiboContentContainer"))); if (pWeiboCotentContainer) { pWeiboCotentContainer->SetBorderColor(RGB(0,0,255)); } } } } return true; }
void MainFrame::Notify(TNotifyUI& msg) { if (_tcsicmp(msg.sType, _T("windowinit")) == 0) { OnPrepare(msg); } else if (_tcsicmp(msg.sType, _T("killfocus")) == 0) { if (_tcsicmp(msg.pSender->GetName(), kSignatureControlName) == 0) { msg.pSender->SetVisible(false); CControlUI* signature_tip = paint_manager_.FindControl(kSignatureTipsControlName); if (signature_tip != NULL) { CRichEditUI* signature = static_cast<CRichEditUI*>(msg.pSender); if (signature != NULL) signature_tip->SetText(signature->GetText()); signature_tip->SetVisible(true); } } else if (_tcsicmp(msg.pSender->GetName(), kSearchEditControlName) == 0) { msg.pSender->SetVisible(false); CControlUI* search_tip = static_cast<CRichEditUI*>(paint_manager_.FindControl(kSearchEditTipControlName)); if (search_tip != NULL) { CRichEditUI* search_edit = static_cast<CRichEditUI*>(msg.pSender); if (search_edit != NULL) search_tip->SetText(search_edit->GetText()); search_tip->SetVisible(true); } } } else if (_tcsicmp(msg.sType, _T("click")) == 0) { if (_tcsicmp(msg.pSender->GetName(), kCloseButtonControlName) == 0) { OnExit(msg); } else if (_tcsicmp(msg.pSender->GetName(), kMinButtonControlName) == 0) { #if defined(UNDER_CE) ::ShowWindow(m_hWnd, SW_MINIMIZE); #else SendMessage(WM_SYSCOMMAND, SC_MINIMIZE, 0); #endif } else if (_tcsicmp(msg.pSender->GetName(), kMaxButtonControlName) == 0) { #if defined(UNDER_CE) ::ShowWindow(m_hWnd, SW_MAXIMIZE); CControlUI* pControl = static_cast<CControlUI*>(paint_manager_.FindControl(kMaxButtonControlName)); if( pControl ) pControl->SetVisible(false); pControl = static_cast<CControlUI*>(paint_manager_.FindControl(kRestoreButtonControlName)); if( pControl ) pControl->SetVisible(true); #else SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, 0); #endif } else if (_tcsicmp(msg.pSender->GetName(), kRestoreButtonControlName) == 0) { #if defined(UNDER_CE) ::ShowWindow(m_hWnd, SW_RESTORE); CControlUI* pControl = static_cast<CControlUI*>(paint_manager_.FindControl(kMaxButtonControlName)); if( pControl ) pControl->SetVisible(true); pControl = static_cast<CControlUI*>(paint_manager_.FindControl(kRestoreButtonControlName)); if( pControl ) pControl->SetVisible(false); #else SendMessage(WM_SYSCOMMAND, SC_RESTORE, 0); #endif } else if (_tcsicmp(msg.pSender->GetName(), kHideLeftMainPannelControlName) == 0) { CControlUI* left_main_pannel = paint_manager_.FindControl(kLeftMainPannelControlName); CControlUI* hide_left_main_pannel = paint_manager_.FindControl(kHideLeftMainPannelControlName); CControlUI* show_left_main_pannel = paint_manager_.FindControl(kShowLeftMainPannelControlName); if ((left_main_pannel != NULL) && (show_left_main_pannel != NULL) && (hide_left_main_pannel != NULL)) { hide_left_main_pannel->SetVisible(false); left_main_pannel->SetVisible(false); show_left_main_pannel->SetVisible(true); } } else if (_tcsicmp(msg.pSender->GetName(), kShowLeftMainPannelControlName) == 0) { CControlUI* left_main_pannel = paint_manager_.FindControl(kLeftMainPannelControlName); CControlUI* hide_left_main_pannel = paint_manager_.FindControl(kHideLeftMainPannelControlName); CControlUI* show_left_main_pannel = paint_manager_.FindControl(kShowLeftMainPannelControlName); if ((left_main_pannel != NULL) && (show_left_main_pannel != NULL) && (hide_left_main_pannel != NULL)) { hide_left_main_pannel->SetVisible(true); left_main_pannel->SetVisible(true); show_left_main_pannel->SetVisible(false); } } else if (_tcsicmp(msg.pSender->GetName(), kSignatureTipsControlName) == 0) { msg.pSender->SetVisible(false); CRichEditUI* signature = static_cast<CRichEditUI*>(paint_manager_.FindControl(kSignatureControlName)); if (signature != NULL) { signature->SetText(msg.pSender->GetText()); signature->SetVisible(true); } } else if (_tcsicmp(msg.pSender->GetName(), kSearchEditTipControlName) == 0) { msg.pSender->SetVisible(false); CRichEditUI* search_edit = static_cast<CRichEditUI*>(paint_manager_.FindControl(kSearchEditControlName)); if (search_edit != NULL) { search_edit->SetText(msg.pSender->GetText()); search_edit->SetVisible(true); } } else if (_tcsicmp(msg.pSender->GetName(), kChangeBkSkinControlName) == 0) { CControlUI* background = paint_manager_.FindControl(kBackgroundControlName); if (background != NULL) { TCHAR szBuf[MAX_PATH] = {0}; ++bk_image_index_; if (kBackgroundSkinImageCount < bk_image_index_) bk_image_index_ = 0; #if defined(UNDER_WINCE) _stprintf(szBuf, _T("file='bg%d.png' corner='600,200,1,1'"), bk_image_index_); #else _stprintf_s(szBuf, MAX_PATH - 1, _T("file='bg%d.png' corner='600,200,1,1'"), bk_image_index_); #endif background->SetBkImage(szBuf); SkinChangedParam param; CControlUI* background = paint_manager_.FindControl(kBackgroundControlName); if (background != NULL) { param.bkcolor = background->GetBkColor(); if (_tcslen(background->GetBkImage()) > 0) { #if defined(UNDER_WINCE) _stprintf(szBuf, _T("bg%d.png"), bk_image_index_); #else _stprintf_s(szBuf, MAX_PATH - 1, _T("bg%d.png"), bk_image_index_); #endif } param.bgimage = szBuf; } skin_changed_observer_.Broadcast(param); } } else if (_tcsicmp(msg.pSender->GetName(), kChangeColorSkinControlName) == 0) { CDuiRect rcWindow; GetWindowRect(m_hWnd, &rcWindow); rcWindow.top = rcWindow.top + msg.pSender->GetPos().bottom; new ColorSkinWindow(this, rcWindow); } } else if (_tcsicmp(msg.sType, _T("timer")) == 0) { return OnTimer(msg); } else if (_tcsicmp(msg.sType, _T("selectchanged")) == 0) { CTabLayoutUI* pTabControl = static_cast<CTabLayoutUI*>(paint_manager_.FindControl(kTabControlName)); if (_tcsicmp(msg.pSender->GetName(), kFriendButtonControlName) == 0) { if (pTabControl && pTabControl->GetCurSel() != 0) { pTabControl->SelectItem(0); UpdateFriendsList(); } } else if (_tcsicmp(msg.pSender->GetName(), kGroupButtonControlName) == 0) { if (pTabControl && pTabControl->GetCurSel() != 1) { pTabControl->SelectItem(1); UpdateGroupsList(); } } else if (_tcsicmp(msg.pSender->GetName(), kMicroBlogButtonControlName) == 0) { if (pTabControl && pTabControl->GetCurSel() != 2) { pTabControl->SelectItem(2); UpdateMicroBlogList(); } } } else if (_tcsicmp(msg.sType, _T("itemactivate")) == 0) { CTabLayoutUI* pTabControl = static_cast<CTabLayoutUI*>(paint_manager_.FindControl(kTabControlName)); if (pTabControl != NULL) { if (pTabControl->GetCurSel() == 0) { CFriendsUI* pFriendsList = static_cast<CFriendsUI*>(paint_manager_.FindControl(kFriendsListControlName)); if ((pFriendsList != NULL) && pFriendsList->GetItemIndex(msg.pSender) != -1) { if (_tcsicmp(msg.pSender->GetClass(), _T("ListContainerElementUI")) == 0) { Node* node = (Node*)msg.pSender->GetTag(); CControlUI* background = paint_manager_.FindControl(kBackgroundControlName); if (!pFriendsList->CanExpand(node) && (background != NULL)) { FriendListItemInfo friend_info; for (std::vector<FriendListItemInfo>::const_iterator citer = friends_.begin(); citer != friends_.end(); ++citer) { if (_tcsicmp(citer->id.c_str(), node->data().value.c_str()) == 0) { friend_info = *citer; break; } } TCHAR szBuf[MAX_PATH] = {0}; if (_tcslen(background->GetBkImage()) > 0) { #if defined(UNDER_WINCE) _stprintf(szBuf, _T("bg%d.png"), bk_image_index_); #else _stprintf_s(szBuf, MAX_PATH - 1, _T("bg%d.png"), bk_image_index_); #endif } ChatDialog* pChatDialog = new ChatDialog(szBuf, background->GetBkColor(), myself_info_, friend_info); if( pChatDialog == NULL ) return; #if defined(WIN32) && !defined(UNDER_CE) pChatDialog->Create(NULL, _T("ChatDialog"), UI_WNDSTYLE_FRAME | WS_POPUP, NULL, 0, 0, 0, 0); #else pChatDialog->Create(NULL, _T("ChatDialog"), UI_WNDSTYLE_FRAME | WS_POPUP, NULL, 0, 0, 0, 0); #endif skin_changed_observer_.AddReceiver(pChatDialog); pChatDialog->CenterWindow(); ::ShowWindow(*pChatDialog, SW_SHOW); } } } } } } else if (_tcsicmp(msg.sType, _T("itemclick")) == 0) { CTabLayoutUI* pTabControl = static_cast<CTabLayoutUI*>(paint_manager_.FindControl(kTabControlName)); if (pTabControl != NULL) { if (pTabControl->GetCurSel() == 0) { CFriendsUI* pFriendsList = static_cast<CFriendsUI*>(paint_manager_.FindControl(kFriendsListControlName)); if ((pFriendsList != NULL) && pFriendsList->GetItemIndex(msg.pSender) != -1) { if (_tcsicmp(msg.pSender->GetClass(), _T("ListContainerElementUI")) == 0) { Node* node = (Node*)msg.pSender->GetTag(); if (pFriendsList->CanExpand(node)) { pFriendsList->SetChildVisible(node, !node->data().child_visible_); } } } } else if (pTabControl->GetCurSel() == 1) { CGroupsUI* pGroupsList = static_cast<CGroupsUI*>(paint_manager_.FindControl(kGroupsListControlName)); if ((pGroupsList != NULL) && pGroupsList->GetItemIndex(msg.pSender) != -1) { if (_tcsicmp(msg.pSender->GetClass(), _T("ListContainerElementUI")) == 0) { Node* node = (Node*)msg.pSender->GetTag(); if (pGroupsList->CanExpand(node)) { pGroupsList->SetChildVisible(node, !node->data().child_visible_); } } } } } } }
void ChatDialog::SendMsg() { CRichEditUI* pRichEdit = static_cast<CRichEditUI*>(m_PaintManager.FindControl(kInputRichEditControlName)); if( pRichEdit == NULL ) return; pRichEdit->SetFocus(); CDuiString sText = pRichEdit->GetTextRange(0, pRichEdit->GetTextLength()); if( sText.IsEmpty() ) return; pRichEdit->SetText(_T("")); pRichEdit = static_cast<CRichEditUI*>(m_PaintManager.FindControl(kViewRichEditControlName)); if( pRichEdit == NULL ) return; long lSelBegin = 0, lSelEnd = 0; CHARFORMAT2 cf; ZeroMemory(&cf, sizeof(CHARFORMAT2)); cf.cbSize = sizeof(cf); cf.dwReserved = 0; cf.dwMask = CFM_COLOR | CFM_LINK | CFM_UNDERLINE | CFM_UNDERLINETYPE; cf.dwEffects = CFE_LINK; cf.bUnderlineType = CFU_UNDERLINE; cf.crTextColor = RGB(220, 0, 0); lSelEnd = lSelBegin = pRichEdit->GetTextLength(); pRichEdit->SetSel(lSelEnd, lSelEnd); pRichEdit->ReplaceSel(_T("某人"), false); lSelEnd = pRichEdit->GetTextLength(); pRichEdit->SetSel(lSelBegin, lSelEnd); pRichEdit->SetSelectionCharFormat(cf); lSelEnd = lSelBegin = pRichEdit->GetTextLength(); pRichEdit->SetSel(lSelEnd, lSelEnd); pRichEdit->ReplaceSel(_T("说:\t2011-07-30 08:30:12\n"), false); cf.dwMask = CFM_COLOR; cf.crTextColor = RGB(0, 0, 0); cf.dwEffects = 0; lSelEnd = pRichEdit->GetTextLength(); pRichEdit->SetSel(lSelBegin, lSelEnd); pRichEdit->SetSelectionCharFormat(cf); PARAFORMAT2 pf; ZeroMemory(&pf, sizeof(PARAFORMAT2)); pf.cbSize = sizeof(pf); pf.dwMask = PFM_STARTINDENT; pf.dxStartIndent = 0; pRichEdit->SetParaFormat(pf); lSelEnd = lSelBegin = pRichEdit->GetTextLength(); pRichEdit->SetSel(-1, -1); pRichEdit->ReplaceSel(sText.GetData(), false); pRichEdit->SetSel(-1, -1); pRichEdit->ReplaceSel(_T("\n"), false); cf.crTextColor = RGB(0, 0, 0); lSelEnd = pRichEdit->GetTextLength(); pRichEdit->SetSel(lSelBegin, lSelEnd); pRichEdit->SetSelectionCharFormat(cf); ZeroMemory(&pf, sizeof(PARAFORMAT2)); pf.cbSize = sizeof(pf); pf.dwMask = PFM_STARTINDENT; pf.dxStartIndent = 220; pRichEdit->SetParaFormat(pf); pRichEdit->EndDown(); }
NSDUILIB_API void ShowLicense(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra) { TCHAR controlName[MAX_PATH]; TCHAR fileName[MAX_PATH]; FILE* infile=NULL; TCHAR *ptchlicense=NULL; char *pLicense = NULL; char *pptr=NULL; int leftsize = 0; size_t ret; BOOL bret; EXDLL_INIT(); ZeroMemory(controlName, MAX_PATH*sizeof(TCHAR)); ZeroMemory(fileName, MAX_PATH*sizeof(TCHAR)); popstring( controlName,sizeof(controlName) ); popstring( fileName,sizeof(fileName)); CDuiString finalFileName = fileName; CRichEditUI* pRichEditControl = static_cast<CRichEditUI*>(g_pFrame->GetPaintManager().FindControl( controlName )); if( pRichEditControl == NULL ) { goto fail; } // 读许可协议文件,append到richedit中 USES_CONVERSION; infile = fopen( T2A(finalFileName.GetData()), "r+b" ); if (infile == NULL) { goto fail; } fseek( infile, 0, SEEK_END ); int nSize = ftell(infile); fseek(infile, 0, SEEK_SET); pLicense = new char[nSize+1]; ptchlicense = new TCHAR[nSize+2]; if (pLicense == NULL || ptchlicense == NULL) { if (pLicense) { delete []pLicense; } pLicense = NULL; if (ptchlicense) { delete []ptchlicense; } ptchlicense = NULL; fclose(infile); return; } ZeroMemory(pLicense, sizeof(char) * (nSize+1)); ZeroMemory(ptchlicense,sizeof(TCHAR)* (nSize + 1)); pptr = pLicense; leftsize = nSize; DEBUG_INFO("openfile 0x%p size %d\n",infile,nSize); while (leftsize > 0) { ret = fread_s(pptr, leftsize, sizeof(char), leftsize, infile); if (ret < 0) { DEBUG_INFO("ret = %d\n",ret); goto fail; } DEBUG_INFO("ret = %d\n",ret); pptr += ret* sizeof(char); leftsize -= (ret * sizeof(char)); } /*now we change the text*/ //mbstowcs(ptchlicense,pLicense,nSize+1); #ifdef _UNICODE DEBUG_INFO("\n"); pLicense[nSize] = 0x0; bret = MultiByteToWideChar(CP_ACP,0,pLicense,nSize,ptchlicense,(nSize + 1)); if (!bret) { DEBUG_INFO("change license error %d\n",GetLastError()); goto fail; } #else memcpy(ptchlicense,pLicense,nSize); #endif pRichEditControl->AppendText( ptchlicense); if (pLicense != NULL) { delete []pLicense; pLicense = NULL; } if (ptchlicense != NULL) { delete []ptchlicense; ptchlicense = NULL; } fclose( infile ); pushint(0); return ; fail: if (pLicense != NULL) { delete []pLicense; pLicense = NULL; } if (ptchlicense != NULL) { delete []ptchlicense; ptchlicense = NULL; } if (infile) { fclose( infile ); infile = NULL; } pushint(-1); return; }
void ChatDialog::Notify(TNotifyUI& msg) { if (_tcsicmp(msg.sType, _T("windowinit")) == 0) { OnPrepare(msg); } else if (_tcsicmp(msg.sType, _T("killfocus")) == 0) { } else if (_tcsicmp(msg.sType, _T("click")) == 0) { if (_tcsicmp(msg.pSender->GetName(), kCloseButtonControlName) == 0) { OnExit(msg); } else if (_tcsicmp(msg.pSender->GetName(), kMinButtonControlName) == 0) { SendMessage(WM_SYSCOMMAND, SC_MINIMIZE, 0); } else if (_tcsicmp(msg.pSender->GetName(), kMaxButtonControlName) == 0) { SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, 0); } else if (_tcsicmp(msg.pSender->GetName(), kRestoreButtonControlName) == 0) { SendMessage(WM_SYSCOMMAND, SC_RESTORE, 0); } else if (_tcsicmp(msg.pSender->GetName(), kFontButtonControlName) == 0) { CContainerUI* pFontbar = static_cast<CContainerUI*>(paint_manager_.FindControl(kFontbarControlName)); if (pFontbar != NULL) pFontbar->SetVisible(!pFontbar->IsVisible()); } else if (_tcsicmp(msg.pSender->GetName(), kEmotionButtonControlName) == 0) { POINT pt = {0}; CDuiRect rcEmotionBtn = msg.pSender->GetPos(); CDuiRect rcWindow; GetWindowRect(m_hWnd, &rcWindow); pt.y = rcWindow.top + rcEmotionBtn.top; pt.x = rcWindow.left + rcEmotionBtn.left; //emotion_list_window_.SelectEmotion(pt); new CEmotion(this,pt); } else if (_tcsicmp(msg.pSender->GetName(), kSendButtonControlName) == 0) { CRichEditUI* pRichEdit = static_cast<CRichEditUI*>(paint_manager_.FindControl(kInputRichEditControlName)); CRichEditUI* pViewEdit = static_cast<CRichEditUI*>(paint_manager_.FindControl(kViewRichEditControlName)); if( pRichEdit == NULL ) return; pRichEdit->SetFocus(); CDuiString sText = pRichEdit->GetTextRange(0, pRichEdit->GetTextLength()); //CDuiString sText=pRichEdit->GetEditGifStr(); if( sText.IsEmpty() ) return; int textlen = sText.GetLength(); if (textlen > 512) { pViewEdit->SetTextColor(RGB(255,0,0)); pViewEdit->SetText(_T("错误!发送数据的长度不能超过512字节。")); } else { int imNum = friend_.id; TCHAR sendmesg[513] = {0}; _stprintf_s(sendmesg,512,_T("%s"),sText.GetData()); int len = strlen(sendmesg); if (len !=textlen) { pViewEdit->SetTextColor(RGB(255,0,0)); pViewEdit->SetText(_T("警告!发送数据的长度和计算的不同。")); } frame_wnd_->m_pTcpCommunication->SendMsg(MSG_TYPE_FRIEND,imNum,sendmesg,textlen); //显示在 SendMsg(g_myself_info.nick_name,sText); pRichEdit->SetText(_T("")); //test //CDuiString strbmp; //strbmp.Format("c:\\1.gif"); //pRichEdit->InsertGif(strbmp); } } } else if( _tcsicmp(msg.sType, _T("return")) == 0 ) { if (_tcsicmp(msg.pSender->GetName(), kInputRichEditControlName) == 0) { CRichEditUI* pRichEdit = static_cast<CRichEditUI*>(paint_manager_.FindControl(kInputRichEditControlName)); CRichEditUI* pViewEdit = static_cast<CRichEditUI*>(paint_manager_.FindControl(kViewRichEditControlName)); if( pRichEdit == NULL ) return; pRichEdit->SetFocus(); CDuiString sText = pRichEdit->GetTextRange(0, pRichEdit->GetTextLength()); if( sText.IsEmpty() ) return; int textlen = sText.GetLength(); if (textlen > 512) { pViewEdit->SetTextColor(RGB(255,0,0)); pViewEdit->SetText(_T("错误!发送数据的长度不能超过512字节。")); } else { int imNum = friend_.id; TCHAR sendmesg[513] = {0}; _stprintf_s(sendmesg,512,_T("%s"),sText.GetData()); int len = strlen(sendmesg); if (len !=textlen) { pViewEdit->SetTextColor(RGB(255,0,0)); pViewEdit->SetText(_T("警告!发送数据的长度和计算的不同。")); } frame_wnd_->m_pTcpCommunication->SendMsg(MSG_TYPE_FRIEND,imNum,sendmesg,textlen); //显示在 SendMsg(g_myself_info.nick_name,sText); pRichEdit->SetText(_T("")); } } } else if (_tcsicmp(msg.sType, _T("timer")) == 0) { return OnTimer(msg); } else if (_tcsicmp(msg.sType, _T("selectchanged")) == 0) { if (_tcsicmp(msg.pSender->GetName(), kColorButtonControlName) == 0) { CContainerUI* pFontbar = static_cast<CContainerUI*>(paint_manager_.FindControl(kFontbarControlName)); if (pFontbar != NULL) { POINT pt = {0}; CDuiRect rcFontbar = pFontbar->GetPos(); CDuiRect rcColorBtn = msg.pSender->GetPos(); CDuiRect rcWindow; GetWindowRect(m_hWnd, &rcWindow); pt.y = rcWindow.top + rcFontbar.top; pt.x = rcWindow.left + rcColorBtn.left + static_cast<LONG>(rcColorBtn.right - rcColorBtn.left / 2); new CColorPicker((ChatDialog*)this, pt); } } else if (_tcsicmp(msg.pSender->GetName(), kBoldButtonControlName) == 0) { COptionUI* bold_button = static_cast<COptionUI*>(msg.pSender); if (bold_button != NULL) { bold_ = bold_button->IsSelected(); FontStyleChanged(); } } else if (_tcsicmp(msg.pSender->GetName(), kItalicButtonControlName) == 0) { COptionUI* italic_button = static_cast<COptionUI*>(msg.pSender); if (italic_button != NULL) { italic_ = italic_button->IsSelected(); FontStyleChanged(); } } else if (_tcsicmp(msg.pSender->GetName(), KUnderlineButtonControlName) == 0) { COptionUI* underline_button = static_cast<COptionUI*>(msg.pSender); if (underline_button != NULL) { underline_ = underline_button->IsSelected(); FontStyleChanged(); } } } else if (_tcsicmp(msg.sType, _T("itemselect")) == 0) { if (_tcsicmp(msg.pSender->GetName(), kFontTypeControlName) == 0) { CComboUI* font_type = static_cast<CComboUI*>(msg.pSender); if (font_type != NULL) { font_face_name_ = font_type->GetText(); FontStyleChanged(); } } else if (_tcsicmp(msg.pSender->GetName(), kFontSizeControlName) == 0) { CComboUI* font_size = static_cast<CComboUI*>(msg.pSender); if (font_size != NULL) { font_size_ = _ttoi(font_size->GetText()); FontStyleChanged(); } } } }
//name 显示的名字,sText内容 int ChatDialog::SendMsg(CDuiString name,CDuiString sText) { CRichEditUI* pRichEdit = static_cast<CRichEditUI*>(paint_manager_.FindControl(kViewRichEditControlName)); if( pRichEdit == NULL ) { DbgPrint("can not find kViewRichEditControlName\n"); return -1; } CDuiString strFolder=CPaintManagerUI::GetInstancePath(); long lSelBegin = 0, lSelEnd = 0; CHARFORMAT2 cf; ZeroMemory(&cf, sizeof(CHARFORMAT2)); cf.cbSize = sizeof(cf); cf.dwReserved = 0; cf.dwMask = CFM_COLOR | CFM_LINK | CFM_UNDERLINE | CFM_UNDERLINETYPE; cf.dwEffects = CFE_LINK; cf.bUnderlineType = CFU_UNDERLINE; cf.crTextColor = RGB(220, 0, 0); lSelEnd = lSelBegin = pRichEdit->GetTextLength(); pRichEdit->SetSel(lSelEnd, lSelEnd); pRichEdit->ReplaceSel((LPCTSTR)name, false); lSelEnd = pRichEdit->GetTextLength(); pRichEdit->SetSel(lSelBegin, lSelEnd); pRichEdit->SetSelectionCharFormat(cf); lSelEnd = lSelBegin = pRichEdit->GetTextLength(); pRichEdit->SetSel(lSelEnd, lSelEnd); CTime time = CTime::GetCurrentTime(); CDuiString sendTime = time.Format(_T("%H:%M:%S")); CDuiString sendtimestr; sendtimestr.Format(_T("说:\t%s\n"),sendTime); pRichEdit->ReplaceSel(sendtimestr, false); //pRichEdit->ReplaceSel(_T("说:\t2011-07-30 08:30:12\n"), false); cf.dwMask = CFM_COLOR; cf.crTextColor = RGB(0, 0, 0); cf.dwEffects = 0; lSelEnd = pRichEdit->GetTextLength(); pRichEdit->SetSel(lSelBegin, lSelEnd); pRichEdit->SetSelectionCharFormat(cf); PARAFORMAT2 pf; ZeroMemory(&pf, sizeof(PARAFORMAT2)); pf.cbSize = sizeof(pf); pf.dwMask = PFM_STARTINDENT; pf.dxStartIndent = 0; pRichEdit->SetParaFormat(pf); lSelEnd = lSelBegin = pRichEdit->GetTextLength(); //插入字符串,需转移表情 //pRichEdit->SetSel(-1, -1); //pRichEdit->ReplaceSel(sText.GetData(), false); pRichEdit->SetSel(-1,-1); int m,begin; begin=0; CDuiString temp; char buff[2]; while(1) { m=sText.Find(_T("#"),begin); if(-1!=m) { temp=sText.Mid(begin,m-begin); pRichEdit->ReplaceSel(temp.GetData(),false); int n=sText.Find(_T(".gif"),m); //find .gif if (n!=-1) { temp = sText.Mid(m+1,n-m+3); if (frame_wnd_) { CDuiString strfacefolder,strface; strfacefolder.Format(_T("%s\\skin\\Faces\\"),strFolder.GetData()); strface.Format(_T("%s\\skin\\Faces\\%s"),strFolder.GetData(),temp.GetData()); if (0==frame_wnd_->find_gif_in_folder(temp,strfacefolder)) { // pRichEdit->InsertGif(strface); } begin=n+4; m=n+4; } else { return 0; } } else { pRichEdit->ReplaceSel(temp,false); begin=n+1; } } else { temp=sText.Mid(begin); pRichEdit->SetSel(-1, -1); pRichEdit->ReplaceSel(temp,false); //pRichEdit->PostMessage(WM_VSCROLL, SB_BOTTOM, 0);//滚动条自动到最后一行 break; } } pRichEdit->SetSel(-1, -1); pRichEdit->ReplaceSel(_T("\n"), false); cf.crTextColor = RGB(0, 0, 0); lSelEnd = pRichEdit->GetTextLength(); // pRichEdit->SetSel(lSelBegin, lSelEnd); pRichEdit->SetSelectionCharFormat(cf); ZeroMemory(&pf, sizeof(PARAFORMAT2)); pf.cbSize = sizeof(pf); pf.dwMask = PFM_STARTINDENT; pf.dxStartIndent = 220; pRichEdit->SetParaFormat(pf); pRichEdit->EndDown(); return 0; }