能否补全这段代码,使得LoadBitmapFromFile可以载入png,jpg,jpeg等格式
不要使用任何要下载的第三方库,这很重要
要使得补全后的代码能在dev_c++编译通过,
```c++
#include <stdio.h>
#include <thread>
#include <iostream>
#include <fstream>
#include <sstream>
#include <stdlib.h>
#include <windows.h>
using namespace std;
bool gameover = false;
LRESULT WINAPI WinProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) {
switch( msg ) {
case WM_DESTROY:
gameover = true;
exit(0);
break;
}
return DefWindowProc( hWnd, msg, wParam, lParam );
}
void DrawhBitmap(HDC device, HBITMAP image, int x, int y) {
BITMAP bm;
GetObject(image, sizeof(BITMAP), &bm);
HDC hdcImage = CreateCompatibleDC(device);
SelectObject(hdcImage, image);
BitBlt(device, x, y, bm.bmWidth, bm.bmHeight, hdcImage, 0, 0, SRCCOPY);
DeleteDC(hdcImage);
}
HBITMAP LoadBitmapFromFile(string s) {
string type;
for(int i = s.size() - 1; i >= 0; i--)
if(s[i] == '.') {
type = s.substr(i + 1);
break;
}
if(type == "png") {
//载入png
}
if(type == "jpg") {
//载入jpg
}
if(type == "jpeg") {
//载入jpeg
}
if(type == "bmp") {
return (HBITMAP)LoadImage(0, s.c_str(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
}
}
// Windows entry point
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)WinProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = 0;
wc.lpszMenuName = NULL;
wc.lpszClassName = "MainWindowClass";
wc.hIconSm = NULL;
RegisterClassEx(&wc);
//create a new window
//WS_EX_TOPMOST|WS_POPUP , 0, 0,
HWND window = CreateWindow("MainWindowClass", "abc",
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
700, 500, NULL, NULL, hInstance, NULL);
if (window == 0) return 0;
//display the window
ShowWindow(window, SW_SHOW);
UpdateWindow(window);
//main message loop
HBITMAP bitmap = LoadBitmapFromFile("铲子.bmp");
DrawhBitmap(GetDC(window), bitmap, 0, 0);
MSG message;
while (!gameover) {
if (PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) {
TranslateMessage(&message);
DispatchMessage(&message);
}
Sleep(1);
}
return message.wParam;
}
```