#include <Windows.h>
HDC g_hdc = NULL,g_mdc = NULL;
HBITMAP g_hitmap = NULL;
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
BOOL Game_Init(HWND hwnd);
VOID Game_Paint(HWND hwnd);
BOOL Game_CleanUp(HWND hwnd);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdline, int nCmdShow){
static TCHAR CAIQM[] = L"Caiqm";
WNDCLASS ws;
PlaySound(L"nit.wav", 0, SND_FILENAME | SND_ASYNC);
ws.style = CS_HREDRAW | CS_VREDRAW;
ws.hInstance = hInstance;
ws.cbClsExtra = 0;
ws.cbWndExtra = 0;
ws.hIcon = (HICON)::LoadImage(NULL, L"icon.ico", IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE);
ws.hCursor = LoadCursor(NULL, IDC_ARROW);
ws.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
ws.lpszClassName = CAIQM;
ws.lpszMenuName = NULL;
ws.lpfnWndProc = WndProc;
if (!RegisterClass(&ws)) return -1;
HWND hwnd = CreateWindow(CAIQM, CAIQM, WS_OVERLAPPEDWINDOW, 100, 100, 800, 600, NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
if (!Game_Init(hwnd)){
MessageBox(hwnd, L"初始化失败", L"消息框", 0);
}
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){
PAINTSTRUCT paintstruct;
switch (msg){
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_KEYDOWN:
if (wParam == VK_ESCAPE){
DestroyWindow(hwnd);
}
break;
case WM_PAINT:
g_hdc = BeginPaint(hwnd,&paintstruct);
Game_Paint(hwnd);
Game_CleanUp(hwnd);
ValidateRect(hwnd,NULL);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
BOOL Game_Init(HWND hwnd){
g_hdc = GetDC(hwnd);
g_hitmap = (HBITMAP)LoadImage(NULL, L"Naruto.bmp", IMAGE_BITMAP, 800, 600, LR_LOADFROMFILE);
g_mdc = CreateCompatibleDC(g_hdc);
Game_Paint(hwnd);
ReleaseDC(hwnd, g_hdc);
return true;
}
VOID Game_Paint(HWND hwnd){
SelectObject(g_mdc,g_hitmap);
BitBlt(g_hdc, 0, 0, 800, 600, g_mdc, 0, 0, SRCCOPY);
}
BOOL Game_CleanUp(HWND hwnd){
DeleteObject(g_hitmap);
DeleteDC(g_mdc);
return true;
}
window窗口输出图片
最新推荐文章于 2022-12-12 23:05:19 发布