ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[CSDN原创](https://blog.csdn.net/harvic880925/article/details/9331701/) ```c++ // LoadImageTest.cpp : 定义应用程序的入口点。 // #include "stdafx.h" #include "LoadImageTest.h" void OnPaint(HWND); void OnInitDialog(HWND); HINSTANCE g_hInst; INT_PTR CALLBACK WndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam) { switch(uMsg) { case WM_DESTROY: PostQuitMessage(0); break; case WM_CLOSE: EndDialog(hwnd,IDCANCEL); break; case WM_INITDIALOG: OnInitDialog(hwnd); break; case WM_COMMAND: switch(LOWORD(wParam)) { case IDCANCEL: EndDialog(hwnd,IDCANCEL); return TRUE; } break; case WM_PAINT: { OnPaint(hwnd); } break; } return FALSE; } void OnInitDialog(HWND hwnd) { //加载图标 //HICON hIcon = LoadIcon(g_hInst,(LPCWSTR)IDI_ICON1);(方法一) HICON hIcon = (HICON) LoadImage(g_hInst,(LPCWSTR)IDI_ICON1,IMAGE_ICON,0,0,0);//(方法二) ::SendMessageA(hwnd,WM_SETICON,FALSE,(LPARAM)hIcon); } //hInstance 资源总管,如果有资源要加载则要设置hInstance全局变量 int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) { g_hInst = hInstance; DialogBox(hInstance,(LPCWSTR)IDD_MAIN,NULL,WndProc); return FALSE; }; void OnPaint(HWND hwnd) { //加载背景图 PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd,&ps);//界面DC //HBITMAP hBitmap = (HBITMAP)LoadImage(g_hInst,(LPCWSTR)IDC_WOLL,IMAGE_BITMAP,0,0,0);//(方法一)进程外 加载位图第一个参数可以为NULL HBITMAP hBitmap = (HBITMAP)LoadBitmap(g_hInst,(LPCWSTR)IDC_WOLL);//(方法二) HDC hMemDC = CreateCompatibleDC(NULL); //创建内存DC SelectObject(hMemDC,hBitmap);//选择位图 BitBlt(hdc,0,0,280,210,hMemDC,0,0,SRCCOPY);//输出 EndPaint(hwnd,&ps); //销毁DC } ```