BOOL CMainWindow::_RichEdit_InsertFace(CRichEditUI * pRichEdit, LPCTSTR lpszFileName, int nFaceId, int nFaceIndex) { BOOL bRet = FALSE; if (NULL == pRichEdit || NULL == lpszFileName || NULL == *lpszFileName) return FALSE; ITextServices * pTextServices = pRichEdit->GetTextServices(); ITextHost * pTextHost = pRichEdit->GetTextHost(); if (pTextServices != NULL && pTextHost != NULL) { if (pRichEdit == m_pRecvEdit) RichEdit_SetStartIndent(pTextServices, 300); bRet = RichEdit_InsertFace(pTextServices, pTextHost, lpszFileName, nFaceId, nFaceIndex, RGB(255,255,255), TRUE, 40); } if (pTextServices != NULL) pTextServices->Release(); if (pTextHost != NULL) pTextHost->Release(); return bRet; }
void CMainWindow::OnBtn_Color(TNotifyUI& msg) { static COLORREF rgbCustomColors[16] = { RGB(255, 255, 255), RGB(255, 255, 255), RGB(255, 255, 255), RGB(255, 255, 255), RGB(255, 255, 255), RGB(255, 255, 255), RGB(255, 255, 255), RGB(255, 255, 255), RGB(255, 255, 255), RGB(255, 255, 255), RGB(255, 255, 255), RGB(255, 255, 255), RGB(255, 255, 255), RGB(255, 255, 255), RGB(255, 255, 255), RGB(255, 255, 255), }; CHOOSECOLOR cc = {0}; cc.lStructSize = sizeof(cc); cc.lpCustColors = rgbCustomColors; cc.hwndOwner = m_hWnd; cc.Flags = CC_RGBINIT; BOOL bRet = ::ChooseColor(&cc); if (bRet) { COLORREF clrText = cc.rgbResult; if (m_fontInfo.m_clrText != clrText) { m_fontInfo.m_clrText = clrText; ITextServices * pTextServices = m_pSendEdit->GetTextServices(); RichEdit_SetDefFont(pTextServices, m_fontInfo.m_strName.c_str(), m_fontInfo.m_nSize, m_fontInfo.m_clrText, m_fontInfo.m_bBold, m_fontInfo.m_bItalic, m_fontInfo.m_bUnderLine, FALSE); pTextServices->Release(); g_buddyFontInfo.m_clrText = m_fontInfo.m_clrText; } } }
LRESULT CMainWindow::OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam) { IImageOle * pNewImageOle = NULL; RECT rc = {0}; POINT pt = {LOWORD(lParam), HIWORD(lParam)}; CControlUI * pControl = this->paint_manager_.FindControl(pt); if (pControl != NULL) { if (pControl == m_pSendEdit || pControl == m_pRecvEdit) { ITextServices * pTextServices = ((CRichEditUI *)pControl)->GetTextServices(); IImageOle * pImageOle = NULL; BOOL bRet = RichEdit_GetImageOle(pTextServices, pt, &pImageOle); if (bRet && pImageOle != NULL) { pNewImageOle = pImageOle; pImageOle->GetObjectRect(&rc); } if (pImageOle != NULL) pImageOle->Release(); pTextServices->Release(); } } if (m_pLastImageOle != pNewImageOle) { m_pLastImageOle = pNewImageOle; if (m_pLastImageOle != NULL) { m_ptRBtnDown = pt; if (!::IsWindow((HWND)m_PicBarDlg)) { m_PicBarDlg.Create(m_hWnd, NULL, WS_CHILD|WS_POPUP, WS_EX_TOOLWINDOW); RECT rcPos = {0}; ::GetClientRect((HWND)m_PicBarDlg, &rcPos); m_cxPicBarDlg = rcPos.right-rcPos.left; m_cyPicBarDlg = rcPos.bottom-rcPos.top; } m_PicBarDlg.SetCallBackCtrl(pControl); RECT rc2 = pControl->GetPos(); POINT pt = {rc.right, rc.bottom-m_cyPicBarDlg}; if (pt.x < rc2.left) pt.x = rc2.left; if (pt.x > rc2.right) pt.x = rc2.right; if (pt.y > rc2.bottom-m_cyPicBarDlg) pt.y = rc2.bottom-m_cyPicBarDlg; ::ClientToScreen(m_hWnd, &pt); ::SetWindowPos((HWND)m_PicBarDlg, NULL, pt.x, pt.y, m_cxPicBarDlg, m_cyPicBarDlg, SWP_NOACTIVATE|SWP_SHOWWINDOW); } else { ::ShowWindow((HWND)m_PicBarDlg, SW_HIDE); } } return 0; }
// “另存为”菜单 void CMainWindow::OnMenu_SaveAs(TNotifyUI& msg) { if (msg.pSender != m_pSendEdit && msg.pSender != m_pRecvEdit) return; ITextServices * pTextServices = ((CRichEditUI *)msg.pSender)->GetTextServices(); IImageOle * pImageOle = NULL; BOOL bRet = RichEdit_GetImageOle(pTextServices, m_ptRBtnDown, &pImageOle); pTextServices->Release(); if (!bRet || NULL == pImageOle) return; tstring strFileName; BSTR bstrFileName = NULL; HRESULT hr = pImageOle->GetFileName(&bstrFileName); if (SUCCEEDED(hr)) strFileName = bstrFileName; if (bstrFileName != NULL) ::SysFreeString(bstrFileName); LPCTSTR lpszDefExt; LPCTSTR lpszFileName = _T("未命名"); DWORD dwFlags = OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_NOCHANGEDIR|OFN_EXTENSIONDIFFERENT; LPCTSTR lpszFilter; HWND hWndParent = m_hWnd; GUID guid = {0}; hr = pImageOle->GetRawFormat(&guid); if (InlineIsEqualGUID(guid, Gdiplus::ImageFormatJPEG)) { lpszDefExt = _T(".jpg"); lpszFilter = _T("图像文件(*.jpg)\0*.jpg\0图像文件(*.bmp)\0*.bmp\0\0"); } else if (InlineIsEqualGUID(guid, Gdiplus::ImageFormatPNG)) { lpszDefExt = _T(".png"); lpszFilter = _T("图像文件(*.png)\0*.png\0\0"); } else if (InlineIsEqualGUID(guid, Gdiplus::ImageFormatGIF)) { lpszDefExt = _T(".gif"); lpszFilter = _T("图像文件(*.gif)\0*.gif\0图像文件(*.jpg)\0*.jpg\0图像文件(*.bmp)\0*.bmp\0\0"); } else { lpszDefExt = _T(".jpg"); lpszFilter = _T("图像文件(*.jpg)\0*.jpg\0图像文件(*.bmp)\0*.bmp\0\0"); } CFileDialogEx fileDlg; fileDlg.SetDefExt(lpszDefExt); fileDlg.SetFileName(lpszFileName); fileDlg.SetFlags(dwFlags); fileDlg.SetFilter(lpszFilter); fileDlg.SetParentWnd(m_hWnd); fileDlg.SetTitle(_T("保存图片")); if (fileDlg.ShowSaveFileDlg()) { tstring strSavePath = fileDlg.GetPathName(); tstring strExtName = _T(".") + ZYM::CPath::GetExtension(strSavePath.c_str()); GUID guid2 = GetFileTypeGuidByExtension(strExtName.c_str()); if (InlineIsEqualGUID(guid, guid2)) { CopyFile(strFileName.c_str(), strSavePath.c_str(), FALSE); } else { BSTR bstrSavePath = ::SysAllocString(strSavePath.c_str()); if (bstrSavePath != NULL) { pImageOle->SaveAsFile(bstrSavePath); ::SysFreeString(bstrSavePath); } } } if (pImageOle != NULL) pImageOle->Release(); }