gpt4 book ai didi

Windows API 编程中的组合框

转载 作者:行者123 更新时间:2023-11-30 14:55:51 25 4
gpt4 key购买 nike

我正在尝试显示一个组合框窗口,如您所见,我将 hWndComboBox 设置为我的第二个窗口,并且我正在使用 ShowWindow() 函数,但它并没有真正显示当我编译并运行代码时有什么吗?我还应该添加什么?

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstace, LPSTR lpCommand, int nCmdLine)
{
HWND window;
int xpos = 100; // Horizontal position of the window.
int ypos = 100; // Vertical position of the window.
int nwidth = 200; // Width of the window
int nheight = 200; // Height of the window
HWND hwndParent = window; // Handle to the parent window


MSG message;
WNDCLASSEX wndClass;

wndClass.cbSize = sizeof(WNDCLASSEX);
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.style = 0;
wndClass.hInstance = hInstance;
wndClass.lpfnWndProc = wndCll;
wndClass.lpszClassName = classNoOne;
wndClass.lpszMenuName = MAKEINTRESOURCE(IDR_MYMENU);
wndClass.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_PENGUIN_ICON));
wndClass.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_PENGUIN_ICON), IMAGE_ICON, LR_DEFAULTSIZE, LR_DEFAULTSIZE, 0);
wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW-1);

if(!RegisterClassEx(&wndClass)){
printf("No wndclass");
}
window = CreateWindowEx(WS_EX_CLIENTEDGE, classNoOne, "Start Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 1000, 500, NULL, NULL, hInstance, NULL);
//create the window
HWND hWndComboBox = CreateWindow(WC_COMBOBOX, "name of the combobox", CBS_DROPDOWN | CBS_HASSTRINGS | WS_CHILD | WS_OVERLAPPED | WS_VISIBLE , xpos, ypos, nwidth, nheight, hwndParent, NULL, hInstance, NULL);
TCHAR Planets[9][10] = {
TEXT("MERCURY"), TEXT("VENUS"), TEXT("Terra"), TEXT("MARS"), TEXT("JUPITER"), TEXT("SATURN"), TEXT("URANUS"), TEXT("NEPTUNE"), TEXT("PLUTO")
};
//these are the list elements
TCHAR A[16];
int k = 0;
memset(&A, 0, sizeof(A));
//allocate memory
for(k = 0; k<=8; k+=1){
strcpy(A, (TCHAR *)Planets[k]);
SendMessage(hWndComboBox,(UINT) CB_ADDSTRING,(WPARAM) 0,(LPARAM) A);
}
SendMessage(hWndComboBox, CB_SETCURSEL, (WPARAM)2, (LPARAM)0);
ShowWindow(hWndComboBox, nCmdLine);
//ShowWindow(window, nCmdLine);
if(window == NULL){
printf("window is NULL");
}

while(GetMessage(&message, NULL, 0, 0) > 0){
if(!IsDialogMessage(dialogSmall, &message)){
TranslateMessage(&message);
DispatchMessage(&message);
}
}
return message.wParam;
}

最佳答案

编程语言不像数学那样工作。在数学中,你可以说 x = y;然后说 y = 5;然后你可以推断 x 一定是 5。

然而,在编程语言中,当你说HWND hwndParent = window;时然后hwndParent取值 window 在分配时,所以如果您稍后实际初始化 windowwindow = ...您不能期望 hwndParent 的值突然变得有意义。它将保持未初始化状态,因为 window在分配时尚未初始化。

提示:如果您能够做到HWND hwndParent = window;window未初始化,这意味着您没有收到任何警告。这又意味着您没有将编译器配置为在执行此类操作时发出警告。不要在没有警告的情况下尝试编程。这样你永远不会取得多大成就。

关于Windows API 编程中的组合框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45354687/

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