Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C windowsapi编程中的组合框_C_Windows_Winapi - Fatal编程技术网

C windowsapi编程中的组合框

C windowsapi编程中的组合框,c,windows,winapi,C,Windows,Winapi,我正在尝试显示一个组合框窗口,正如您所看到的,我将hWndComboBox设置为第二个窗口,并且我正在使用ShowWindow()函数,当我编译和运行代码时,它实际上没有显示任何内容?我应该补充什么 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstace, LPSTR lpCommand, int nCmdLine) { HWND window; int xpos = 100; // Ho

我正在尝试显示一个组合框窗口,正如您所看到的,我将
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;
}
int-WINAPI-WinMain(HINSTANCE-HINSTANCE、HINSTANCE-hprevinspace、LPSTR-lpCommand、int-nCmdLine)
{
HWND窗口;
int xpos=100;//窗口的水平位置。
int ypos=100;//窗口的垂直位置。
int nwidth=200;//窗口的宽度
int nheight=200;//窗的高度
HWND hwndParent=window;//父窗口的句柄
消息;
wndClass x 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_图标));
wndClass.hIconSm=(HICON)LoadImage(GetModuleHandle(NULL),MAKEINTRESOURCE(IDI_PENGUIN_图标),IMAGE_图标,LR_DEFAULTSIZE,LR_DEFAULTSIZE,0);
wndClass.hCursor=LoadCursor(空,IDC_箭头);
wndClass.hbrBackground=(HBRUSH)(颜色窗口-1);
如果(!RegisterClass(&wndClass)){
printf(“无wndclass”);
}
window=CreateWindowEx(WS_EX_CLIENTEDGE,classNoOne,“开始窗口”,WS_重叠窗口,CW_USEDEFAULT,CW_USEDEFAULT,1000500,NULL,NULL,NULL,hInstance,NULL);
//创建窗口
HWND hWndComboBox=CreateWindow(WC_组合框,“组合框的名称”,CBS|u下拉列表| CBS|u hastrings | WS|u CHILD | WS|u重叠| WS| u可见,xpos,ypos,nwidth,nheight,hwndpparent,NULL,hInstance,NULL);
TCHAR行星[9][10]={
文本(“水星”)、文本(“金星”)、文本(“大地”)、文本(“火星”)、文本(“木星”)、文本(“土星”)、文本(“天王星”)、文本(“海王星”)、文本(“冥王星”)
};
//这些是列表元素
tchara[16];
int k=0;
memset(&A,0,sizeof(A));
//分配内存
对于(k=0;k0){
if(!IsDialogMessage(dialogSmall和message)){
翻译消息(和消息);
DispatchMessage(&message);
}
}
返回message.wParam;
}

编程语言的工作原理与数学不同。在数学中你可以说x=y;然后说y=5;然后你可以推断x一定是5

然而,在编程语言中,当您说
HWND hwndParent=window
然后
hwndParent
获取赋值时
window
拥有的值,因此如果以后实际使用
window=…
初始化
window
,则不能期望
hwndParent
的值突然变得有意义。它将保持未初始化状态,因为
窗口
在分配时未初始化


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

“没有什么真正的表现”?它显示了什么?但主要是,为什么要用C编写windows gui应用程序。这是一个糟糕的选择只有控制台出现,为什么它是一个糟糕的选择?我可以用C创建窗口和对话框,但是因为我是新手,所以ComboBox有问题,你也需要检查你调用的函数是否工作。查看CreateWondwEx等的返回。调用GetLAstError当需要时我发现问题,代码必须在
LRESULT CALLBACK wnd()
函数中运行,带有
开关(消息){}
案例WM\u CREATE:
我已将
HWND hwndParent=窗口放置在窗口中语句在函数
CreateWindowEx()
下,我仍然看不到窗口,我想可能是语法有问题