我有点不明白这 selectobject 是什么用的?假设 DC 对象有个Object句柄属性,那么这 SelectObject 的参数是画刷,那么就把画刷选进 Object句柄。假设是蓝色画刷,那么就可以用这画刷来刷蓝色背景那么如果选位图,也就能用位图来贴背景。看MSDN 后我是这么理解的,但我用的书也是说SelectObject 是选空间。若真这样的话,那选画刷要怎么解释? SelectObject The SelectObject function selects an object into the specified device context (DC). The new object replaces the previous object of the same type.
-_-! CreateCompatibleDC A memory device context is a device context that exists only in memory. When the memory device context is created, its display surface is exactly one monochrome pixel wide and one monochrome pixel high. Before an application can use a memory device context for drawing operations, it must select a bitmap of the correct width and height into the device context. This may be done by using CreateCompatibleBitmap specifying the height, width, and color organization required in the function call. DC需要一个BITMAP与其相关联,它才能在BITMAP指定的空间绘制。SelectObject可以选多种DC对象,它自动分别DC对象的类型。!-_-! 对不起,我更正我的口头语,是选对象,选择了BITMAP,也就关联了BITMAP的空间。
那你的代码: 先 hb1 = CreateBitmap(1024, 768, 1, 32, bits); bufferDC = CreateCompatibleDC (NULL); SelectObject(bufferDC, hb1);之后又有 SelectObject(bufferDC,hbrushWall); 按 MSDN 说法: The new object replaces the previous object of the same type.都替换掉了,应该还是那hbrushWall 空间,只够一张hbrushWall关联的位图
The new object replaces the previous object of the same type ----------------------------------------------------------- 同一种只有一个
资源文件就 IDB_BITMAP_WALL 是砖块
IDB_BITMAP2_SCORE 是记分板
IDI_MAIN 是ico图标
void DrawGame()
{
HDC windowDC = GetDC(NULL);
bufferDC=CreateCompatibleDC(windowDC);
DrawBackGround(bufferDC); BitBlt(windowDC,0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),
bufferDC,0,0,SRCCOPY);
}
{
HDC windowDC = GetDC(NULL);
DrawBackGround(windowDC);
//bufferDC=CreateCompatibleDC(windowDC);
//DrawBackGround(bufferDC); //BitBlt(windowDC,0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),
// bufferDC,0,0,SRCCOPY);
}用上面的代替 DrawGame() 是可以的,那可以证明 DrawBackGround()函数没问题,那剩下的就是CreateCompatibleDC() 和 BitBlt() ,这两个有问题吗?
//内存绘图
CBitmap memBitmap;
CBitmap* pOldBmp = NULL;
//创建内存绘图设备
memDC.CreateCompatibleDC(pDC); //创建与屏幕dc兼容的内存dc
memBitmap.CreateCompatibleBitmap(pDC,rect.right,rect.bottom);
pOldBmp = memDC.SelectObject(&memBitmap);
memDC.BitBlt(rect.left,rect.top,rect.right,rect.bottom,pDC,0,0,SRCCOPY);
//自定义绘图函数,详细见源程序
DrawWave(&memDC);
//把内存绘图拷贝到屏幕
pDC->BitBlt(rect.left,rect.top,rect.right,rect.bottom,&memDC,0,0,SRCCOPY);
memDC.SelectObject(pOldBmp);
memDC.DeleteDC();
memBitmap.DeleteObject();
BYTE bits[1024*768*4];
HBITMAP hb1;
void StartGame()
{
hb1 = CreateBitmap(1024, 768, 1, 32, bits);
bufferDC = CreateCompatibleDC (NULL);
SelectObject(bufferDC, hb1); SetTimer(hWnd,500,1000,NULL);
}void EndGame()
{
KillTimer(hWnd,500);
DeleteObject(hb1);
DeleteDC(bufferDC);}其它不用动,在exit(0);之前EndGame();
{
HDC windowDC = GetDC(NULL);
bufferDC=CreateCompatibleDC(windowDC);
DrawBackGround(bufferDC); BitBlt(windowDC,0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),
bufferDC,0,0,SRCCOPY);
}
建出来的内存DC一定要选一个位图才行,要不没有空间
里有 SelectObject(bufferDC,hbrushWall);
这是选空间吗?
这也算,但这个空间太小了,只够一张hbrushWall关联的位图
这次就不用缓冲DC了,但同样还是SelectObject(bufferDC,hbrushWall);
这里的 bufferDC 是参数传进来的 windowDC 。
为什么这次又可以?
void DrawGame()
{
HDC windowDC = GetDC(NULL);
DrawBackGround(windowDC);
//bufferDC=CreateCompatibleDC(windowDC);
//DrawBackGround(bufferDC); //BitBlt(windowDC,0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),
// bufferDC,0,0,SRCCOPY);
}
SelectObject
The SelectObject function selects an object into the specified device context (DC). The new object replaces the previous object of the same type.
黑 客 群:18605156
VC 群:18607590
ASP群:48490599
嵌 入 式 群:33956012加入请写名原因。
LINUX 群:18788803
经济、军事群:3685785
市场经济论坛(朋友的):48696408
CreateCompatibleDC
A memory device context is a device context that exists only in memory. When the memory device context is created, its display surface is exactly one monochrome pixel wide and one monochrome pixel high. Before an application can use a memory device context for drawing operations, it must select a bitmap of the correct width and height into the device context. This may be done by using CreateCompatibleBitmap specifying the height, width, and color organization required in the function call. DC需要一个BITMAP与其相关联,它才能在BITMAP指定的空间绘制。SelectObject可以选多种DC对象,它自动分别DC对象的类型。!-_-!
对不起,我更正我的口头语,是选对象,选择了BITMAP,也就关联了BITMAP的空间。
先
hb1 = CreateBitmap(1024, 768, 1, 32, bits);
bufferDC = CreateCompatibleDC (NULL);
SelectObject(bufferDC, hb1);之后又有
SelectObject(bufferDC,hbrushWall); 按 MSDN 说法:
The new object replaces the previous object of the same type.都替换掉了,应该还是那hbrushWall 空间,只够一张hbrushWall关联的位图
-----------------------------------------------------------
同一种只有一个