gpt4 book ai didi

c++ - BitBlt 位图到启动画面

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:27:01 24 4
gpt4 key购买 nike

我正在为一个简单的 Direct3D 游戏制作闪屏,尽管屏幕本身已正确创建和销毁,但未显示要投影到闪屏上的 BITMAP。到目前为止我有这个:

//variable declarations
HWND splashWindow = NULL;
BITMAP bm;

//window procedure
LRESULT WINAPI SplashProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch( msg )
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(splashWindow, &ps);
HDC hdcMem = CreateCompatibleDC(hdc);
BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
DeleteDC(hdcMem);
EndPaint(splashWindow, &ps);
}
}
return DefWindowProc( hWnd, msg, wParam, lParam );
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
//initialize splash window settings
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_VREDRAW | CS_HREDRAW;
wc.lpfnWndProc = SplashProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = "Splash Window";
wc.hIconSm = NULL;
RegisterClassEx(&wc);

//create and draw the splash window
HBITMAP splashBMP = (HBITMAP)LoadImage(hInstance, "assets\\textures\\splash.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
GetObject(splashBMP, sizeof(bm), &bm);
//^-splashBMP to bm - used here so the window has proper dimensions
splashWindow = CreateWindow("Splash Window", NULL,
WS_POPUPWINDOW | WS_EX_TOPMOST, CW_USEDEFAULT, CW_USEDEFAULT,
bm.bmWidth, bm.bmHeight, NULL, NULL, hInstance, NULL);
if (splashWindow == 0) return 0;

ShowWindow(splashWindow, nCmdShow);
UpdateWindow(splashWindow);
//after the game loads the splash screen is destroyed through DestroyWindow(splashWindow);
//and splashBMP is released by calling DeleteObject(splashBMP);

实际上,唯一重要的代码是 SplashProc 处理 WM_PAINT 消息。位图 bm 加载正常,通过窗口的 900x600 尺寸显示(与 splash.bmp 相同)。然而,那个窗口只是一个黑屏,而不是 splash.bmp 中包含的 herobrine 脸 xD

最佳答案

这是其中一个,您几乎可以肯定地盯着代码看了很长时间,以至于错过了显而易见的地方。

您正在创建 hdcMem,然后立即 BitBlt 进入初始屏幕。在这些之间,您无疑需要一个 SelectObject 将您的位图选择到 hdcMem 中。

PAINTSTRUCT ps;
HDC hdc = BeginPaint(splashWindow, &ps);
HDC hdcMem = CreateCompatibleDC(hdc);

// You need to add this
HBITMAP oldBmp = SelectObject(hdcMem, splashBMP);

BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);

// ...and this
SelectObject(hdcMem, OldBmp);

DeleteDC(hdcMem);
EndPaint(splashWindow, &ps);

关于c++ - BitBlt 位图到启动画面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17762783/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com