Beispiel #1
0
LRESULT CMainWindow::OnLButtonDblClk(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	POINT pt = {GET_X_LPARAM(lParam), GET_Y_LPARAM(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)
			{
				BSTR bstrFileName = NULL;
				HRESULT hr = pImageOle->GetFileName(&bstrFileName);
				if (SUCCEEDED(hr))
					::ShellExecute(NULL, _T("open"), bstrFileName, NULL, NULL, SW_SHOWNORMAL);
				if (bstrFileName != NULL)
					::SysFreeString(bstrFileName);
			}
			if (pImageOle != NULL)
				pImageOle->Release();

			pTextServices->Release();
		}
	}
	return 0;
}
Beispiel #2
0
static bool bbCodeImageFunc(IFormattedTextDraw *ftd, CHARRANGE range, TCHAR *txt, DWORD cookie)
{
	ITextServices *ts = ftd->getTextService();
	ITextDocument *td = ftd->getTextDocument();

	long cnt;
	LRESULT lResult;
/*
	TEXTRANGE trg;
	trg.chrg = range;
	trg.lpstrText = new TCHAR[trg.chrg.cpMax - trg.chrg.cpMin + 1];
	ts->TxSendMessage(EM_GETTEXTRANGE, 0, (LPARAM)&trg, &lResult);
	MessageBox(0, txt, trg.lpstrText, MB_OK);
*/
	ts->TxSendMessage(EM_SETSEL, range.cpMin, range.cpMax, &lResult);
	IRichEditOle* RichEditOle;
	ts->TxSendMessage(EM_GETOLEINTERFACE, 0, (LPARAM)&RichEditOle, &lResult);
	td->Freeze(&cnt);
//	HDC emfdc = CreateEnhMetaFile(NULL, NULL, NULL, _T("icon"));
//	DrawIconEx(emfdc, 0, 0, (HICON)_ttol(txt), 16, 16, 0, NULL, DI_NORMAL);
//	InsertBitmap(RichEditOle, CloseEnhMetaFile(emfdc));
#ifdef _WIN64
	bool res = InsertBitmap(RichEditOle, CacheIconToEmf((HICON)_tstoi64(txt)));
#else
	bool res = InsertBitmap(RichEditOle, CacheIconToEmf((HICON)_ttoi(txt)));
#endif

	td->Unfreeze(&cnt);
	RichEditOle->Release();
	return res;
}
Beispiel #3
0
LRESULT CMainWindow::OnRButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
	CControlUI * pControl = this->paint_manager_.FindControl(pt);
	if (pControl != NULL)
	{	
		if (pControl == m_pRecvEdit)
		{
			m_ptRBtnDown = pt;

			CMenuWnd* pMenu = new CMenuWnd(m_hWnd);
			::ClientToScreen(m_hWnd, &pt);
			pMenu->Init(NULL, _T("RecvEditMenu.xml"), _T("xml"), pt, pControl);

			BOOL bSel = (m_pRecvEdit->GetSelectionType() != SEL_EMPTY);
			pMenu->EnableMenuItem(_T("Menu_Copy"), bSel);

			pMenu->CheckMenuItem(m_strCheckMenu.c_str(), TRUE);

			ITextServices * pTextServices = m_pRecvEdit->GetTextServices();

			IImageOle * pImageOle = NULL;
			BOOL bRet = RichEdit_GetImageOle(pTextServices, m_ptRBtnDown, &pImageOle);
			BOOL bSaveAs = (bRet && pImageOle != NULL);
			pMenu->EnableMenuItem(_T("Menu_SaveAs"), bSaveAs);
			if (pImageOle != NULL)
				pImageOle->Release();

			pTextServices->Release();
		}
		else if (pControl == m_pSendEdit)
		{
			m_ptRBtnDown = pt;

			CMenuWnd* pMenu = new CMenuWnd(m_hWnd);
			::ClientToScreen(m_hWnd, &pt);
			pMenu->Init(NULL, _T("SendEditMenu.xml"), _T("xml"), pt, pControl);

			BOOL bSel = (m_pSendEdit->GetSelectionType() != SEL_EMPTY);
			pMenu->EnableMenuItem(_T("Menu_Cut"), bSel);
			pMenu->EnableMenuItem(_T("Menu_Copy"), bSel);

			BOOL bPaste = m_pSendEdit->CanPaste();
			pMenu->EnableMenuItem(_T("Menu_Paste"), bPaste);

			ITextServices * pTextServices = m_pSendEdit->GetTextServices();

			IImageOle * pImageOle = NULL;
			BOOL bRet = RichEdit_GetImageOle(pTextServices, m_ptRBtnDown, &pImageOle);
			BOOL bSaveAs = (bRet && pImageOle != NULL);
			pMenu->EnableMenuItem(_T("Menu_SaveAs"), bSaveAs);
			if (pImageOle != NULL)
				pImageOle->Release();

			pTextServices->Release();
		}
	}
	return 0;
}
Beispiel #4
0
void CMainWindow::Init()
{
	tstring strPath = ZYM::CPath::GetCurDir() + _T("Face\\FaceConfig.xml");
	m_FaceList.LoadConfigFile(strPath.c_str());

	m_pMinSysBtn = static_cast<CButtonUI*>(paint_manager_.FindControl(_T("btnMinSys")));
	m_pMaxSysBtn = static_cast<CButtonUI*>(paint_manager_.FindControl(_T("btnMaxSys")));
	m_pRestoreSysBtn = static_cast<CButtonUI*>(paint_manager_.FindControl(_T("btnRestoreSys")));
	m_pCloseSysBtn = static_cast<CButtonUI*>(paint_manager_.FindControl(_T("btnCloseSys")));
	m_pFontBtn = static_cast<CButtonUI*>(paint_manager_.FindControl(_T("btnFont")));
	m_pFaceBtn = static_cast<CButtonUI*>(paint_manager_.FindControl(_T("btnFace")));
	m_pImageBtn = static_cast<CButtonUI*>(paint_manager_.FindControl(_T("btnImage")));
	m_pFontNameCombo = static_cast<CComboUI*>(paint_manager_.FindControl(_T("cboFontName")));
	m_pFontSizeCombo = static_cast<CComboUI*>(paint_manager_.FindControl(_T("cboFontSize")));
	m_pBoldBtn = static_cast<COptionUI*>(paint_manager_.FindControl(_T("btnBold")));
	m_pItalicBtn = static_cast<COptionUI*>(paint_manager_.FindControl(_T("btnItalic")));
	m_pUnderLineBtn = static_cast<COptionUI*>(paint_manager_.FindControl(_T("btnUnderLine")));
	m_pColorBtn = static_cast<CButtonUI*>(paint_manager_.FindControl(_T("btnColor")));
	m_pCloseBtn = static_cast<CButtonUI*>(paint_manager_.FindControl(_T("btnClose")));
	m_pSendBtn = static_cast<CButtonUI*>(paint_manager_.FindControl(_T("btnSend")));
	m_pSendEdit = static_cast<CRichEditUI*>(paint_manager_.FindControl(_T("richSend")));
	m_pRecvEdit = static_cast<CRichEditUI*>(paint_manager_.FindControl(_T("richRecv")));

	DragAcceptFiles(m_hWnd, true);

	IRichEditOleCallback2* pRichEditOleCallback2 = NULL;
	HRESULT hr = ::CoCreateInstance(CLSID_ImageOle, NULL, CLSCTX_INPROC_SERVER,
		__uuidof(IRichEditOleCallback2), (void**)&pRichEditOleCallback2);
	if (SUCCEEDED(hr))
	{
		pRichEditOleCallback2->SetNotifyHwnd(m_hWnd);
		ITextServices * pTextServices = m_pRecvEdit->GetTextServices();
		pRichEditOleCallback2->SetTextServices(pTextServices);
		pTextServices->Release();
		m_pRecvEdit->SetOleCallback(pRichEditOleCallback2);
		pRichEditOleCallback2->Release();
	}

	pRichEditOleCallback2 = NULL;
	hr = ::CoCreateInstance(CLSID_ImageOle, NULL, CLSCTX_INPROC_SERVER,
		__uuidof(IRichEditOleCallback2), (void**)&pRichEditOleCallback2);
	if (SUCCEEDED(hr))
	{
		pRichEditOleCallback2->SetNotifyHwnd(m_hWnd);
		ITextServices * pTextServices = m_pSendEdit->GetTextServices();
		pRichEditOleCallback2->SetTextServices(pTextServices);
		pTextServices->Release();
		m_pSendEdit->SetOleCallback(pRichEditOleCallback2);
		pRichEditOleCallback2->Release();
	}

	IDropTarget *pdt = m_pSendEdit->GetTxDropTarget();
	hr = ::RegisterDragDrop(m_hWnd, pdt);
	pdt->Release();
}
Beispiel #5
0
void CMainWindow::OnBtn_UnderLine(TNotifyUI& msg)
{
	BOOL bUnderLine = !m_pUnderLineBtn->IsSelected();
	if (m_fontInfo.m_bUnderLine != bUnderLine)
	{
		m_fontInfo.m_bUnderLine = bUnderLine;
		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_bUnderLine = m_fontInfo.m_bUnderLine;
	}
}
Beispiel #6
0
void CMainWindow::OnCbo_SelChange_FontName(TNotifyUI& msg)
{
	tstring strText = (TCHAR *)m_pFontNameCombo->GetText().GetData();
	if (m_fontInfo.m_strName != strText)
	{
		m_fontInfo.m_strName = strText;
		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_strName = m_fontInfo.m_strName;
	}
}
Beispiel #7
0
LRESULT CMainWindow::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	if (uMsg == WM_MOUSEMOVE)
		OnMouseMove(uMsg, wParam, lParam);

	if (uMsg == WM_RBUTTONDOWN)
	{
		LRESULT lRes = __super::HandleMessage(uMsg, wParam, lParam);
		OnRButtonDown(uMsg, wParam, lParam);
		return lRes;
	}

	if (uMsg == WM_LBUTTONDBLCLK)
		OnLButtonDblClk(uMsg, wParam, lParam);

 	if ((m_pSendEdit != NULL) && m_pSendEdit->IsFocused() 
 		&& (uMsg == WM_KEYDOWN) && (wParam == 'V') && (lParam & VK_CONTROL))	// 发送消息框的Ctrl+V消息
 	{
 		m_pSendEdit->PasteSpecial(CF_TEXT);
 		return TRUE;
 	}

	if (uMsg == WM_NOTIFY && EN_PASTE == ((LPNMHDR)lParam)->code)
	{
		ITextServices * pTextServices = m_pSendEdit->GetTextServices();
		if ((UINT)pTextServices == ((LPNMHDR)lParam)->idFrom)
		{
			AddMsgToSendEdit(((NMRICHEDITOLECALLBACK *)lParam)->lpszText);
		}
		if (pTextServices != NULL)
			pTextServices->Release();
	}

	if (uMsg == WM_MENU)
	{
		CControlUI * pControl = (CControlUI *)lParam;
		if (pControl != NULL)
			this->paint_manager_.SendNotify(pControl, _T("menu_msg"), wParam, lParam);
	}

	if (uMsg == FACE_CTRL_SEL)
		return OnFaceCtrlSel(uMsg, wParam, lParam);

	if (uMsg == WM_DROPFILES)
		return onDropFiles(uMsg, wParam, lParam);

	return __super::HandleMessage(uMsg, wParam, lParam);
}
Beispiel #8
0
void CMainWindow::_RichEdit_ReplaceSel(CRichEditUI * pRichEdit, LPCTSTR lpszNewText)
{
	ITextServices * pTextServices = pRichEdit->GetTextServices();
	if (pRichEdit == m_pRecvEdit)
	{
		RichEdit_ReplaceSel(pTextServices, lpszNewText, 
			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, 300);
	}
	else
	{
		RichEdit_ReplaceSel(pTextServices, lpszNewText);
	}
	pTextServices->Release();
}
Beispiel #9
0
void CMainWindow::OnBtn_Send(TNotifyUI& msg)
{
	ITextServices * pTextServices = m_pSendEdit->GetTextServices();

	tstring strText;
	RichEdit_GetText(pTextServices, strText);

	pTextServices->Release();

	if (strText.size() <= 0)
		return;

	m_pSendEdit->SetText(_T(""));
	m_pSendEdit->SetFocus();

	AddMsgToRecvEdit(strText.c_str());
}
Beispiel #10
0
static bool bbCodeSimpleFunc(IFormattedTextDraw *ftd, CHARRANGE range, TCHAR *txt, DWORD cookie)
{
	CHARFORMAT cf = {0};
	cf.cbSize = sizeof(cf);
	switch (cookie)
	{
		case BBS_BOLD_S:
			cf.dwMask = CFM_BOLD;
			cf.dwEffects = CFE_BOLD;
			break;
		case BBS_BOLD_E:
			cf.dwMask = CFM_BOLD;
			break;
		case BBS_ITALIC_S:
			cf.dwMask = CFM_ITALIC;
			cf.dwEffects = CFE_ITALIC;
			break;
		case BBS_ITALIC_E:
			cf.dwMask = CFM_ITALIC;
			break;
		case BBS_UNDERLINE_S:
			cf.dwMask = CFM_UNDERLINE;
			cf.dwEffects = CFE_UNDERLINE;
			break;
		case BBS_UNDERLINE_E:
			cf.dwMask = CFM_UNDERLINE;
			break;
		case BBS_STRIKEOUT_S:
			cf.dwMask = CFM_STRIKEOUT;
			cf.dwEffects = CFE_STRIKEOUT;
			break;
		case BBS_STRIKEOUT_E:
			cf.dwMask = CFM_STRIKEOUT;
			break;
	}

	ITextServices *ts = ftd->getTextService();

	LRESULT lResult;
	ts->TxSendMessage(EM_SETSEL, range.cpMin, -1, &lResult);
	ts->TxSendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf, &lResult);
	ts->TxSendMessage(EM_SETSEL, range.cpMin, range.cpMax, &lResult);
	ts->TxSendMessage(EM_REPLACESEL, FALSE, (LPARAM)_T(""), &lResult);

	return true;
}
Beispiel #11
0
static bool bbCodeImageFunc(IFormattedTextDraw *ftd, CHARRANGE range, TCHAR *txt, DWORD)
{
	ITextServices *ts = ftd->getTextService();
	ITextDocument *td = ftd->getTextDocument();

	long cnt;
	LRESULT lResult;
	ts->TxSendMessage(EM_SETSEL, range.cpMin, range.cpMax, &lResult);
	IRichEditOle* RichEditOle;
	ts->TxSendMessage(EM_GETOLEINTERFACE, 0, (LPARAM)&RichEditOle, &lResult);
	td->Freeze(&cnt);

#ifdef _WIN64
	bool res = InsertBitmap(RichEditOle, CacheIconToEmf((HICON)_tstoi64(txt)));
#else
	bool res = InsertBitmap(RichEditOle, CacheIconToEmf((HICON)_ttoi(txt)));
#endif

	td->Unfreeze(&cnt);
	RichEditOle->Release();
	return res;
}
Beispiel #12
0
void CMainWindow::AddMsgToRecvEdit(LPCTSTR lpText)
{
	if (NULL == lpText || NULL == *lpText)
		return;

	m_pRecvEdit->SetAutoURLDetect(true);

	tstring strTime;
	strTime = FormatTime(time(NULL), _T("%H:%M:%S"));

	ITextServices * pTextServices = m_pRecvEdit->GetTextServices();
	RichEdit_SetSel(pTextServices, -1, -1);

	TCHAR cText[2048] = {0};
	wsprintf(cText, _T("%s("), _T("倚天"));

	RichEdit_ReplaceSel(pTextServices, cText, 
		_T("宋体"), 9, RGB(0, 0, 255), FALSE, FALSE, FALSE, FALSE, 0);

	wsprintf(cText, _T("%u"), 43156150);
	RichEdit_ReplaceSel(pTextServices, cText, 
		_T("宋体"), 9, RGB(0, 114, 193), FALSE, FALSE, TRUE, TRUE, 0);

	wsprintf(cText, _T(")  %s\r\n"), strTime.c_str());
	RichEdit_ReplaceSel(pTextServices, cText, 
		_T("宋体"), 9, RGB(0, 0, 255), FALSE, FALSE, FALSE, FALSE, 0);

	//m_pRecvEdit->SetAutoURLDetect(true);

	AddMsg(m_pRecvEdit, lpText);

	RichEdit_ReplaceSel(pTextServices, _T("\r\n"));
	RichEdit_SetStartIndent(pTextServices, 0);
	m_pRecvEdit->EndDown();

	pTextServices->Release();
}
Beispiel #13
0
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;
}
Beispiel #14
0
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;
		}
	}
}
Beispiel #15
0
void bbCodeParse(IFormattedTextDraw *ftd)
{
	ITextServices *ts = ftd->getTextService();
	LRESULT lResult;

	int pos = 0;
	for (bool found = true; found;) {
		found = false;
		CHARRANGE fRange; fRange.cpMin = -1;
		TCHAR *fText = 0;
		BBCodeInfo *fBBCode = NULL;

		for (int i = 0; i < bbCodeCount; i++) {
			CHARRANGE range;

			FINDTEXTEX fte;
			fte.chrg.cpMin = pos;
			fte.chrg.cpMax = -1;

			fte.lpstrText = bbCodes[i].start;
			ts->TxSendMessage(EM_FINDTEXTEX, (WPARAM)FR_DOWN, (LPARAM)&fte, &lResult);
			if (lResult == -1)
				continue;
			range = fte.chrgText;

			if (bbCodes[i].end) {
				fte.chrg.cpMin = fte.chrgText.cpMax;
				fte.lpstrText = bbCodes[i].end;
				ts->TxSendMessage(EM_FINDTEXTEX, (WPARAM)FR_DOWN, (LPARAM)&fte, &lResult);
				if (lResult == -1)
					continue;
				range.cpMax = fte.chrgText.cpMax;
			}

			if ((fRange.cpMin == -1) || (fRange.cpMin > range.cpMin)) {
				fRange = range;
				fBBCode = bbCodes + i;
				found = true;

				if (fText)
				{
					delete[] fText;
					fText = nullptr;
				}
				if (bbCodes[i].end) {
					TEXTRANGE trg;
					trg.chrg.cpMin = fte.chrg.cpMin;
					trg.chrg.cpMax = fte.chrgText.cpMin;
					trg.lpstrText = new TCHAR[trg.chrg.cpMax - trg.chrg.cpMin + 1];
					ts->TxSendMessage(EM_GETTEXTRANGE, 0, (LPARAM)&trg, &lResult);
					fText = trg.lpstrText;
				}
			}
		}

		if (found) {
			found = fBBCode->func(ftd, fRange, fText, fBBCode->cookie);
			if (fText) delete[] fText;
		}
	}
}
Beispiel #16
0
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;
}
Beispiel #17
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();
}