企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
```c++ #include "stdafx.h" #include "Customer.h" #include "resource.h" #define IDB_ONE 3301 #define IDB_TWO 3302 #define IDB_THREE 3303 static LONG prev_proc = NULL; LPCTSTR WINDCLASS = _T("TestClass"); LPCTSTR WINDNAME = _T("HelloWin"); LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); LRESULT CALLBACK ButtWindProc(HWND,UINT,WPARAM,LPARAM); int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) { HWND hwnd; MSG msg; WNDCLASS wc; wc.style = CS_BYTEALIGNCLIENT; //window style wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon (NULL, IDI_APPLICATION) ; wc.hCursor = LoadCursor (NULL, IDC_ARROW) ; wc.hbrBackground = (HBRUSH) COLOR_WINDOW;//window backgrount wc.lpszMenuName = NULL; wc.lpszClassName = WINDCLASS; //window class if (!RegisterClass(&wc)) { MessageBox(NULL,_T("策"),_T("HelloWin"),MB_OK); return 0; } hwnd = CreateWindow( WINDCLASS, WINDNAME, WS_OVERLAPPEDWINDOW,//Creates an overlapped window with the WS_OVERLAPPED, WS_CAPTION, WS_SYSMENU, WS_THICKFRAME, WS_MINIMIZEBOX, and WS_MAXIMIZEBOX styles CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); ShowWindow(hwnd,nCmdShow); UpdateWindow(hwnd); while(GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg);//转化为字符 DispatchMessage(&msg);//将消息发送到window消息队列里面 } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hwnd,UINT uMsg,WPARAM wPrarm,LPARAM lParam) { //RECT rect; HWND hwnd1; //HINSTANCE hInst=((LPCREATESTRUCT)lParam)->hInstance; //LPDRAWITEMSTRUCT lpDis; switch(uMsg) { case WM_DESTROY: PostQuitMessage(0); return 0; case WM_PAINT: { HBITMAP hbm; BITMAP bminfo; hbm = LoadBitmap(GetModuleHandle(NULL),MAKEINTRESOURCE(IDB_WOLF)); GetObject(hbm,sizeof(bminfo),&bminfo); PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd,&ps); HDC memdc = CreateCompatibleDC(hdc);//代入一个DC模板 SelectObject(memdc,hbm);//选择位图 BitBlt(hdc,0,0,bminfo.bmWidth,bminfo.bmHeight,memdc,0,0,SRCCOPY);//memdc来源DC 位图输出函数 DeleteDC(memdc); EndPaint(hwnd,&ps); break; } return TRUE; case WM_CREATE: { //创建一个带位图的按钮 hwnd1 = CreateWindow(_T("BUTTON"),_T("按钮一"),WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON| BS_BITMAP , 30,50,160,60,hwnd,(HMENU)IDB_ONE,NULL,NULL); //位图句柄 HBITMAP Hbmp1; //加载一幅位图 Hbmp1 = LoadBitmap(GetModuleHandle(NULL),MAKEINTRESOURCE(IDB_WOLL)); //主窗口发送一个设置位图消息并发送位图句柄 SendMessage(hwnd1, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)Hbmp1); } return TRUE; case WM_DRAWITEM: { /*BITMAP btn1_bmp; HDC hdcbtn1; HWND hbtn1; bmp1=LoadBitmap(GetModuleHandle(NULL),MAKEINTRESOURCE(IDB_WOLF));//加载位图 GetObject(bmp1,sizeof(btn1_bmp),&btn1_bmp);//获取对象 //GetObject(bmp1,sizeof(BITMAP),(LPVOID)&btn1_bmp); hbtn1=GetDlgItem(hwnd,IDB_ONE); HDC hdc=::GetDC(hbtn1);//获取按钮1 hdcbtn1=CreateCompatibleDC(hdc);//代入一个DC模板 SelectObject(hdcbtn1,bmp1); BitBlt(hdc,0,0,btn1_bmp.bmWidth,btn1_bmp.bmHeight,hdcbtn1,0,0,SRCCOPY); ReleaseDC(hbtn1,hdc); break;*/ } case WM_COMMAND: switch(LOWORD(wPrarm)) { case IDB_ONE: //HBITMAP hBmp; //hBmp = LoadBitmap(((LPCREATESTRUCT)lParam)->hInstance,MAKEINTRESOURCE(IDB_WOLF)); break; } return 0; } return DefWindowProc(hwnd,uMsg,wPrarm,lParam); } ```