msdn有篇文章可以看看 HOWTO: Change the Mouse Pointer for a Window in MFC
DWORD SetClassLong( HWND hWnd, // handle to window int nIndex, // index of value to change LONG dwNewLong // new value );
DWORD SetClassLong( HWND hWnd, // handle to window int nIndex, // index of value to change ,here is GCL_HCURSOR LONG dwNewLong // new value ,give it your hCursor );
{
return TRUE;
//return CWnd::OnEraseBkgnd(pDC);//把系统原来的这条语句注释掉。
}3、有效的进行搽除。 搽除背景的时候,不要该搽不该搽的地方都搽。比如,你在一个窗口上放了一个很大的Edit框,几乎占了整个窗口,那么你频繁的搽除整个窗口背景将导致Edit不停重画形成剧烈的闪烁。事实上你可以CRgn创建一个需要搽除的区域,只搽除这一部分。如GetClientRect(rectClient);
rgn1.CreateRectRgnIndirect(rectClient);
rgn2.CreateRectRgnIndirect(m_rectEdit);
if(rgn1.CombineRgn(&rgn1,&rgn2,RGN_XOR) == ERROR)//处理后的rgn1只包括了Edit框之外的客户区域,这样,Edit将不会被我的背景覆盖而导致重画。
{
ASSERT(FALSE);
return ;
}
brush.CreateSolidBrush(m_clrBackgnd);
pDC->FillRgn(&rgn1,&brush);
brush.DeleteObject();注意:在使用这个方法的时候要同时使用方法二。别忘了,到时候又说虫虫的办法不灵。4、使用MemoryDC先在内存里把图画好,再复制到屏幕上。 这对于一次画图过程很长的情况比较管用。毕竟内存操作比较快,而且复制到屏幕又是一次性的,至少不会出现可以明显看出一个东东从左画到右的情况。void CMyWin::OnPaint()
{
CPaintDC dc1(this); // device context for painting
dcMemory.CreateCompatibleDC(&dc1);
CBitmap bmp;//这里的Bitmap是必须的,否则当心弄出一个大黑块哦。
bmp.CreateCompatibleBitmap(&dc1,rectClient.Width(),rectClient.Height());
dcMemory.SelectObject(&bmp); //接下来你想怎么画就怎么画吧。
//dcMemory.FillRect(rectClient,&brush); dc1.BitBlt(0,0,rectClient.Width(),rectClient.Height(),&dcMemory,0,0,SRCCOPY);
dcMemory.DeleteDC();
// Do not call CWnd::OnPaint() for painting messages
}
你可以看看他在我上面发的帖子(以下是转的)://我不是用VC的,只能给伪代码
bool xxx::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
if (pWnd的句柄==窗口句柄 && hitTest==HTCLIENT) {
if (鼠标在指定区域)
::SetCursor(LoadCursor(NULL,IDC_CROSS));
else
::SetCursor(其它的鼠标形状);
return true;
}
return (bool)DefaultProcessing();
}
BOOL CXXXView::PreCreateWindow(CREATESTRUCT& cs)
{
cs.lpszClass =
AfxRegisterWndClass(NULL,
AfxGetApp()->LoadCursor(IDC_CURSOR1),//这里加入你的光标图形
::CreateSolidBrush(RGB(0,100,255)));
return CView::PreCreateWindow(cs);
}
向windows窗口注册一个新的窗口类
在视图类的PreCreateWindow(CREATESTRUCT &s)中完成
PreCreateWindow(CREATESTRUCT &s)
{
cs.lpszClass = AfxRegisterWndClass(
CS_HREDRAW|CS_VREDRAW,
0, //使窗口不显示默认的箭头光标
(HBRUSH)::GetstockObject(WHITE_BRUSH),
0);
return CView::PreCreateWindow(cs);
}
HOWTO: Change the Mouse Pointer for a Window in MFC
HWND hWnd, // handle to window
int nIndex, // index of value to change
LONG dwNewLong // new value
);
HWND hWnd, // handle to window
int nIndex, // index of value to change ,here is GCL_HCURSOR
LONG dwNewLong // new value ,give it your hCursor
);