gpt4 book ai didi

c++ - 将组合框添加到 win32 API

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:50:59 25 4
gpt4 key购买 nike

好的,首先这是家庭作业,但我们的老师鼓励我们超越他实际给我们的作业。所以我想学习如何添加通用对话框。我选择使用组合框。

问题是..我完全不知道从哪里开始。我用谷歌搜索了一下,在没有任何帮助的情况下浏览了第一页半,所以我在这里发帖 :)。任务是做一些简单的事情,比如显示我的名字和画一些椭圆,现在我想添加一个组合框..

这是我的代码。

/*------------------------------------------------------------------------
Name: Jesse Moreland
Class: CST 238 GUI
Lab 2
---------------------------------------------------------------------------*/

#include <windows.h>
#include <WinUser.h>
#include <string>

using std::string;

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR lpszCmdParam, int nCmdShow)
{
static char szAppName[] = "ErrorSample";
HWND hwnd;
HWND comboBox;
MSG msg; // Look how this struct is defined-see help/class notes NOW
WNDCLASSEX wndclass;

wndclass.cbSize = sizeof(wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);

wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = static_cast<HBRUSH>(GetStockObject (WHITE_BRUSH));
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
wndclass.hIconSm = LoadIcon(NULL, MAKEINTRESOURCE(IDI_ERROR));

RegisterClassEx (&wndclass);

// PlaySound("C:\\Windows\\winsxs\\x86_microsoft-windows-speech-userexperience_31bf3856ad364e35_6.1.7601.17514_none_1e1159f6aa0eb8c7\\Speech Off.wav",NULL, SND_FILENAME);

hwnd = CreateWindow (szAppName, // window class name
"Jesse Moreland LAB 2 - Press Left or Right Mouse Button", // 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, // window menu handle
hInstance, // program instance handle
NULL); // creation parameters

ShowWindow (hwnd, nCmdShow);

UpdateWindow (hwnd);

while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return (int) msg.wParam;
}

LRESULT CALLBACK WndProc (HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
RECT size;

char * summer = "SUMMER IS COMING SOON!";
char * leftOrRight = "Press Left or Right Mouse Button to make selection";

switch (message)
{

case WM_PAINT:
hdc = BeginPaint (hwnd, &ps);

GetClientRect (hwnd, &rect);

GetWindowRect(hwnd, &size);

HPEN hPenOld;

//Draw ellipse
HPEN hEllipsePen;
COLORREF qEllipseColor;

qEllipseColor = RGB(0, 0, 255);
hEllipsePen = CreatePen(PS_SOLID, 3, qEllipseColor);
hPenOld =(HPEN)SelectObject(hdc, hEllipsePen);

Arc(hdc, 40, 40, 160, 80, 0, 0, 0, 0);
Arc(hdc, 50, 50, 180, 60, 0, 0, 0, 0);

SelectObject(hdc, hPenOld);
DeleteObject(hEllipsePen);

TextOut(hdc, 0, 0, summer, strlen(summer));
TextOut(hdc, 0, 20, leftOrRight, strlen(leftOrRight));



EndPaint (hwnd, &ps);
return 0;

case WM_LBUTTONDOWN:
return 0;

case WM_RBUTTONDOWN:
return 0;

case WM_DESTROY:
PostQuitMessage(0);
return 0;

}

return DefWindowProc (hwnd, message, wParam, lParam);
}

我应该把命令放在哪里来制作组合框?

最佳答案

为 WM_CREATE 创建一个处理程序,例如

CASE WM_CREATE:
CreateWindowEx(WS_EX_STATICEDGE, "COMBOBOX", "MyCombo1",
CBS_DROPDOWN | WS_CHILD | WS_VISIBLE,
0, 0, 50, 20, hwnd, 100, hInstance, NULL); // 100 = ID of this control
CreateWindowEx(WS_EX_STATICEDGE, "COMBOBOX", "MyCombo2",
CBS_DROPDOWN | WS_CHILD | WS_VISIBLE,
100, 100, 50, 20, hwnd, 101, hInstance, NULL); // 101 = ID of this control
return 0;

您可以在 dlgproc 的其他地方检索窗口句柄,方法是

hEditCombo1 = GetDlgItem(hwnd, 100);

关于c++ - 将组合框添加到 win32 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15985366/

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