其实这个更简单,只是把上一编文章的半透明化的代码去掉就可以啦

还是原来那张图片:


//全局变量
HBITMAP bg, girl;
HDC mdc;
//起始坐标
const int xstart = 50;
const int ystart = 20;


//--------------------------------------------InitInstance() 函数----------------------------------------------
//加载资源
//-------------------------------------------------------------------------------------------------------------
BOOL InitInstance(HINSTANCE hInstance, int nShowCmd)
{
HWND hwnd;
HDC hdc, bufdc;
HBITMAP bmp;
BITMAP bm1;

//创建窗口第三步:正式创建窗口
//创建窗口函数
hwnd = CreateWindow("GameClass", WINDOW_TITLE, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hwnd)
{
return FALSE;
}
//创建窗口第四步:窗口的移动,显示和更新
MoveWindow(hwnd, 250, 80, WINDOW_WIDTH, WINDOW_HEIGHT, true);//调整窗口显示时的位置及窗口的大小
ShowWindow(hwnd, nShowCmd);//设定显示窗口时的状态
UpdateWindow(hwnd);//将窗口绘制于显示设备上

//加载图像
bg = (HBITMAP)LoadImage(NULL, "bg.bmp", IMAGE_BITMAP, 600, 450, LR_LOADFROMFILE);
bmp = (HBITMAP)LoadImage(NULL, "girlmask.bmp", IMAGE_BITMAP, 596, 329, LR_LOADFROMFILE);


hdc = GetDC(hwnd);//获得窗口DC
//建立与窗口兼容的位图DC
mdc = CreateCompatibleDC(hdc);
bufdc = CreateCompatibleDC(hdc);
girl = CreateCompatibleBitmap(hdc, 298, 329);

SelectObject(mdc, girl);

//在mdc上进行透明处理
SelectObject(bufdc, bg);
BitBlt(mdc, 0, 0, 298, 329, bufdc, xstart, ystart, SRCCOPY);
SelectObject(bufdc, bmp);
BitBlt(mdc, 0, 0, 298, 329, bufdc, 298, 0, SRCAND);
BitBlt(mdc, 0, 0, 298, 329, bufdc, 0, 0, SRCPAINT);

MyPaint(hdc);
//释放DC及内存
ReleaseDC(hwnd, hdc);
DeleteDC(bufdc);
DeleteObject(bmp);

return TRUE;
}

//--------------------------------------------MyPaint() 函数---------------------------------------------------
//绘制图形
//-------------------------------------------------------------------------------------------------------------
void MyPaint(HDC hdc)
{
//贴上背景图
SelectObject(mdc, bg);
BitBlt(hdc, 0, 0, 800, 600, mdc, 0, 0, SRCCOPY);

//贴上处理过的半透明图
SelectObject(mdc, girl);
BitBlt(hdc, xstart, ystart, 298, 329, mdc, 0, 0, SRCCOPY);
}


//--------------------------------------------Game_CleanUp() 函数----------------------------------------------
//资源清理函数,在此函数中进行退出前的资源的清理工作
//-------------------------------------------------------------------------------------------------------------
BOOL Game_CleanUp(HWND hwnd)
{
DeleteDC(mdc);
DeleteObject(bg);
DeleteObject(girl);
return TRUE;
}

 

 

如需整体运行框架,请点击: 游戏框架

游戏开发的梦想

梦开始的地方

posted on 2015-11-21 23:32  zishen  阅读(657)  评论(0编辑  收藏  举报