CClientDC和CPaintDC有些区别,但是我不知道怎么用CPaintDC这个类,我用CClientDC类能在屏幕上显示出来,但是CPaintDC类却不能,我发现只有在更新窗口框架的时候,才能闪一下而已,请问这个CPaintDC该怎么用,什么时候用?
解决方案 »
- CButton 添加位图并在上面显示文字
- MFC 界面输入数据如何传递至自定义类的方法中
- 在线等!!!VC无标题对话框,弹出菜单不响应!急!
- VS2008在XP下的问题
- 急急急!跪求高人!MFC连接数据库错误:unhandled exception in 文件名.exe (KERNEL32.DLL):0xE06D7363:...
- 如何给一个IBaseFilter型指针分配一个DWORD_PT整数,并将它们关联起来?
- IHtmlDocument2接口获取网页中SWF动画文件的地址
- com 编的对话框调用时刷新的问题
- 请高手帮忙一下!
- 为什么我的程序会弹出这样的错误菜单
- 编程中的苦恼
- web服务器端采用什么技术与web页面上的ActiveX控件通信?
CClientDC用于对窗口客户区的绘制,在非OnPaint()中用
CClientDC 当DC只在输出到窗口的客户区时使用。
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc; switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_OPEN:
{
// get file name to open
TCHAR szFile[MAX_PATH];
ZeroMemory(szFile, MAX_PATH);
OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY;
ofn.hwndOwner = hWnd;
ofn.lpstrFilter = _T("Supported Files Types(*.bmp;*.gif;*.jpg;*.ico;*.emf;*.wmf)\0*.bmp;*.gif;*.jpg;*.ico;*.emf;*.wmf\0Bitmaps (*.bmp)\0*.bmp\0GIF Files (*.gif)\0*.gif\0JPEG Files (*.jpg)\0*.jpg\0Icons (*.ico)\0*.ico\0Enhanced Metafiles (*.emf)\0*.emf\0Windows Metafiles (*.wmf)\0*.wmf\0\0");
ofn.lpstrTitle = _T("Open Picture File");
ofn.lpstrFile = szFile;
ofn.nMaxFile = MAX_PATH;
if (IDOK == GetOpenFileName(&ofn))
// load the file
LoadPictureFile(szFile);
}
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
if (gpPicture)
{
// get width and height of picture
long hmWidth;
long hmHeight;
gpPicture->get_Width(&hmWidth);
gpPicture->get_Height(&hmHeight);
// convert himetric to pixels
int nWidth = MulDiv(hmWidth, GetDeviceCaps(hdc, LOGPIXELSX), HIMETRIC_INCH);
int nHeight = MulDiv(hmHeight, GetDeviceCaps(hdc, LOGPIXELSY), HIMETRIC_INCH);
RECT rc;
GetClientRect(hWnd, &rc);
// display picture using IPicture::Render
gpPicture->Render(hdc, 0, 0, nWidth, nHeight, 0, hmHeight, hmWidth, -hmHeight, &rc);
}
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
{
public:
BOOL InitInstance();
};class CMainWindow : public CFrameWnd
{
public:
CMainWindow();
protected:
afx_msg void OnPaint();
DECLARE_MESSAGE_MAP()
};CMyApp Myapp;CMyApp::InitInstance()
{
m_pMainWnd = new CMainWindow;
m_pMainWnd->ShowWindow (m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}BEGIN_MESSAGE_MAP(CMainWindow, CFrameWnd)
ON_WM_PAINT()
END_MESSAGE_MAP()CMainWindow::CMainWindow()
{
Create (NULL,_T("first text"));
}void CMainWindow::OnPaint()
{
CPaintDC dc (this);
CRect rect;
GetClientRect(&rect);
dc.DrawText(_T("hahahah"),-1,&rect,DT_SINGLELINE | DT_CENTER | DT_VCENTER);
}
用WM_PAINT。
把你的代码贴上来看看