C++ TransparentBlt 问题
我使用的是DEV-C++,使用TransparentBlt函数时就编译错误了,求大神帮忙!以下是源代码:#include<windows.h>#include<cstdi...
我使用的是DEV-C++ ,使用TransparentBlt函数时就编译错误了,求大神帮忙!
以下是源代码:
#include <windows.h>
#include <cstdio>
#include <ctime>
#pragma comment(lib,"Msimg32.lib")
HDC g_hdc;
HDC m_hdc;
HDC mm_hdc;
HBITMAP bg;
HBITMAP flying[3];
HFONT hfont;
int x=0;
void game_Init(HWND hwnd)
{
char s[20];
srand(time(NULL)); sprintf(s,"BK%d",rand()%2);
HINSTANCE hInstance;
g_hdc = GetDC(hwnd);
m_hdc = CreateCompatibleDC(g_hdc);
mm_hdc = CreateCompatibleDC(m_hdc);
bg= LoadBitmap(hInstance,s);
flying[0]=LoadBitmap(hInstance,"BIRD00");
flying[1]=LoadBitmap(hInstance,"BIRD01");
flying[2]=LoadBitmap(hInstance,"BIRD02");
}
void game_Paint(HWND hwnd)
{
SelectObject(m_hdc,bg);
BitBlt(g_hdc,0,0,800,600,m_hdc,0,0,SRCCOPY);
SelectObject(m_hdc,flying[x]); x++; if(x>2) x=0;
TransparentBlt(m_hdc,115,200,50,50,mm_hdc,0,0,50,50,RGB(0,0,0));//ÕâÀïÓÐÎÊÌâ
BitBlt(g_hdc,115,200,50,50,m_hdc,0,0,SRCCOPY);
}
void game_Clear(HWND hwnd)
{
ReleaseDC(hwnd,g_hdc);
DeleteObject(hfont);
DeleteObject(bg);
DeleteObject(m_hdc);
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
switch(Message) {
case WM_PAINT:
ValidateRect(hwnd,NULL);
break;
case WM_DESTROY: {
game_Clear(hwnd);
PostQuitMessage(0);
break;
}
default:
return DefWindowProc(hwnd, Message, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
WNDCLASSEX wc; HWND hwnd;
MSG msg;
memset(&wc,0,sizeof(wc));
wc.cbSize = sizeof(WNDCLASSEX);
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
wc.lpszClassName = "WindowClass";
wc.hIcon = LoadIcon(hInstance,"DICO");
wc.hIconSm = LoadIcon(hInstance,"DICO");
if(!RegisterClassEx(&wc)) {
MessageBox(NULL, "Window Registration Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
return 0;
}
hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,"WindowClass","Flappy Bird",WS_VISIBLE|WS_OVERLAPPEDWINDOW,
370, 100, 297, 540, NULL,NULL,hInstance,NULL);
if(hwnd == NULL) {
MessageBox(NULL, "Window Creation Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
return 0;
}
game_Init(hwnd);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while (msg.message != WM_QUIT) {
if (PeekMessage(&msg,0,0,0,PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
game_Paint(hwnd);
Sleep(400);
}
}
return msg.wParam;
} 展开
以下是源代码:
#include <windows.h>
#include <cstdio>
#include <ctime>
#pragma comment(lib,"Msimg32.lib")
HDC g_hdc;
HDC m_hdc;
HDC mm_hdc;
HBITMAP bg;
HBITMAP flying[3];
HFONT hfont;
int x=0;
void game_Init(HWND hwnd)
{
char s[20];
srand(time(NULL)); sprintf(s,"BK%d",rand()%2);
HINSTANCE hInstance;
g_hdc = GetDC(hwnd);
m_hdc = CreateCompatibleDC(g_hdc);
mm_hdc = CreateCompatibleDC(m_hdc);
bg= LoadBitmap(hInstance,s);
flying[0]=LoadBitmap(hInstance,"BIRD00");
flying[1]=LoadBitmap(hInstance,"BIRD01");
flying[2]=LoadBitmap(hInstance,"BIRD02");
}
void game_Paint(HWND hwnd)
{
SelectObject(m_hdc,bg);
BitBlt(g_hdc,0,0,800,600,m_hdc,0,0,SRCCOPY);
SelectObject(m_hdc,flying[x]); x++; if(x>2) x=0;
TransparentBlt(m_hdc,115,200,50,50,mm_hdc,0,0,50,50,RGB(0,0,0));//ÕâÀïÓÐÎÊÌâ
BitBlt(g_hdc,115,200,50,50,m_hdc,0,0,SRCCOPY);
}
void game_Clear(HWND hwnd)
{
ReleaseDC(hwnd,g_hdc);
DeleteObject(hfont);
DeleteObject(bg);
DeleteObject(m_hdc);
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
switch(Message) {
case WM_PAINT:
ValidateRect(hwnd,NULL);
break;
case WM_DESTROY: {
game_Clear(hwnd);
PostQuitMessage(0);
break;
}
default:
return DefWindowProc(hwnd, Message, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
WNDCLASSEX wc; HWND hwnd;
MSG msg;
memset(&wc,0,sizeof(wc));
wc.cbSize = sizeof(WNDCLASSEX);
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
wc.lpszClassName = "WindowClass";
wc.hIcon = LoadIcon(hInstance,"DICO");
wc.hIconSm = LoadIcon(hInstance,"DICO");
if(!RegisterClassEx(&wc)) {
MessageBox(NULL, "Window Registration Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
return 0;
}
hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,"WindowClass","Flappy Bird",WS_VISIBLE|WS_OVERLAPPEDWINDOW,
370, 100, 297, 540, NULL,NULL,hInstance,NULL);
if(hwnd == NULL) {
MessageBox(NULL, "Window Creation Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
return 0;
}
game_Init(hwnd);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while (msg.message != WM_QUIT) {
if (PeekMessage(&msg,0,0,0,PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
game_Paint(hwnd);
Sleep(400);
}
}
return msg.wParam;
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询