ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
```c++ #include "stdafx.h" #include "Customer.h" #define IDB_ONE 3301 #define IDB_TWO 3302 #define IDB_THREE 3303 LPCTSTR WINDOWS_CLASS = _T("MyClass"); LPCTSTR WINDOWS_TITLE = _T("测试按钮"); LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) { static TCHAR szAppName[] = _T("HelloWin"); HWND hwnd; MSG msg; WNDCLASS wc = {};//定义窗口类信息结构体 //wc.cbSize = sizeof(WNDCLASSEX);//结构体大小 wc.style = CS_HREDRAW | CS_VREDRAW ; 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;//窗口背景色 wc.lpszMenuName = NULL;// wc.lpszClassName = szAppName;//窗口类名 if (!RegisterClass(&wc)) { MessageBox(NULL,_T("错误"),szAppName,MB_OK); return 0; } hwnd = CreateWindow(szAppName,//window class name _T("The Hello Pragram"),//window caption WS_OVERLAPPEDWINDOW,//window style CW_USEDEFAULT,//initial x position CW_USEDEFAULT,//initial y position CW_USEDEFAULT,//initial x size CW_USEDEFAULT,//initial y size NULL, //parent window handle NULL, //windwo menu handle hInstance, //program instance handle NULL); //creation parameters if (hwnd == NULL)return -1; ShowWindow(hwnd,nCmdShow); UpdateWindow(hwnd); while(GetMessage(&msg,NULL,0,0))//从消息队列中获取一个消息 { //TranslateMessage函数将虚拟键消息转换为字符消息。字符消息被发布到调用线程的消息队列,以便在线程下次调用GetMessage或PeekMessage函数时读取 TranslateMessage(&msg); //DispatchMessage函数将一个消息分派给一个窗口过程。它通常用于分派由GetMessage函数检索的消息。 DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg,WPARAM wParam,LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; RECT rect; switch(uMsg) { case WM_DESTROY: PostQuitMessage(0); return 0; case WM_CREATE: { //WS_VISIBLE创建一个最初可见的窗口 //WS_CHILD创建一个子窗口。不能与WS_POPUP样式一起使用 //BS_PUSHBUTTON创建一个命令按钮,当用户单击该按钮时,它会向所有者窗口发送BN_CLICKED通知 HWND hwnd1 = CreateWindow(_T("BUTTON"),_T("按钮一"),WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 30,60, 160,60,hwnd,(HMENU)IDB_ONE,NULL,NULL); HWND hwnd2 = CreateWindow(_T("BUTTON"),_T("按钮二"),WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 30,150, 160,60,hwnd,(HMENU)IDB_TWO,NULL,NULL); HWND hwnd3 = CreateWindow(_T("BUTTON"),_T("按钮三"),WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 30,220, 160,60,hwnd,(HMENU)IDB_THREE,NULL,NULL); if(!IsWindow(hwnd1) || !IsWindow(hwnd2) || !IsWindow(hwnd3)) { DestroyWindow(hwnd1); DestroyWindow(hwnd2); DestroyWindow(hwnd3); return 0; } //位图句柄 HBITMAP Hbmp1; //加载一幅位图 Hbmp1 = LoadBitmap(GetModuleHandle(NULL),MAKEINTRESOURCE(IDB_WOLL)); //主窗口发送一个设置位图消息并发送位图句柄 SendMessage(hwnd1, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)Hbmp1); } break; case WM_COMMAND: switch(LOWORD(wParam)) { case IDB_ONE: { //HBITMAP bmp1 = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_WOLF)); //SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) + BS_OWNERDRAW); //SendMessage(hwnd, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)bmp1); SendMessage((HWND) lParam,WM_SETTEXT,(WPARAM)NULL,(LPARAM)_T("第一个按钮已点击")); } break; case IDB_TWO: SendMessage((HWND) lParam,WM_SETTEXT,(WPARAM)NULL,(LPARAM)_T("第二个按钮已点击")); break; case IDB_THREE: SendMessage((HWND) lParam,WM_SETTEXT,(WPARAM)NULL,(LPARAM)_T("第三个按钮已点击")); break; } break; } return DefWindowProc(hwnd,uMsg,wParam,lParam); } ```