Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    [C/API di Windows] Inserire elementi in un combobox

    codice:
    /* per GetConsoleWindow */
    #define _WIN32_WINNT 0x0500
    
    #include <stdio.h>
    #include <windows.h>
    
    #define COMBO_PROF   1201
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
    int RegisterDefaultClass(HINSTANCE hInstance);
    void ClientResize(HWND hWnd, int nWidth, int nHeight);
    
    HWND window, combo_prof;
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
        MSG Msg;
    
        if (!(RegisterDefaultClass(hInstance)))
        {
            return 1;
        }
    
        //
        // CREO LA FINESTRA
        //
        window = CreateWindow (
                                    "defaultClass",
                                    "Firefox Search Engine Fixer",
                                    WS_OVERLAPPEDWINDOW,
                                    CW_USEDEFAULT,
                                    0,
                                    CW_USEDEFAULT,
                                    0,
                                    (HWND) NULL,
                                    (HMENU) NULL,
                                    hInstance,
                                    NULL
                                 );
    
        if (!window)
        {
            return 1;
        }
    
        ClientResize(window, 340, 340);
    
        //
        // COMBO BOX
        //
    
        combo_prof = CreateWindow (
                                "COMBOBOX",
                                "",
                                WS_CHILD|
                                WS_VISIBLE|
                                CBS_DROPDOWNLIST|
                                CBS_HASSTRINGS,
                                10,
                                30,
                                320,
                                20,
                                window,
                                COMBO_PROF,
                                hInstance,
                                NULL
                            );
    
        if (!combo_prof)
        {
            return COMBO_PROF;
        }
    
        SendMessage(combo_prof, CB_ADDSTRING, 0, "test");
        SendMessage(combo_prof, CB_ADDSTRING, 0, "test2");
    
        ShowWindow(window, nCmdShow);
        UpdateWindow(window);
    
        while(GetMessage(&Msg, NULL, 0, 0) > 0)
        {
            TranslateMessage(&Msg);
            DispatchMessage(&Msg);
        }
        return Msg.wParam;
    }
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
        switch(msg)
        {
            case WM_CLOSE:
                DestroyWindow(hwnd);
            break;
            case WM_DESTROY:
                PostQuitMessage(0);
            break;
            //case WM_COMMAND:
            //    switch(LOWORD(wParam))
            //    {
            //        case default
            //            printf("");
            //        break;
            //    }
            //break;
            default:
                return DefWindowProc(hwnd, msg, wParam, lParam);
        }
        return 0;
    }
    
    int RegisterDefaultClass(HINSTANCE hInstance)
    {
        const char g_szClassName[] = "defaultClass";
        WNDCLASSEX wc;
    
        wc.cbSize        = sizeof(WNDCLASSEX);
        wc.style         = 0;
        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 = g_szClassName;
        wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
    
        if(!(RegisterClassEx(&wc)))
        {
            return 0;
        }
        return 1;
    }
    
    void ClientResize(HWND hWnd, int nWidth, int nHeight)
    {
        RECT rcClient, rcWindow;
        POINT ptDiff;
        GetClientRect(hWnd, &rcClient);
        GetWindowRect(hWnd, &rcWindow);
        ptDiff.x = (rcWindow.right - rcWindow.left) - rcClient.right;
        ptDiff.y = (rcWindow.bottom - rcWindow.top) - rcClient.bottom;
        MoveWindow(hWnd,rcWindow.left, rcWindow.top, nWidth + ptDiff.x, nHeight + ptDiff.y, TRUE);
    }
    Ho provato con questo codice, ma senza risultati. Il combobox (drop down list) rimane vuoto.

  2. #2
    Utente di HTML.it L'avatar di linoma
    Registrato dal
    Mar 2010
    Messaggi
    1,346
    Hai provato ad aumentare la lunghezza del combo? Mi pare tu abbia solo 20.
    Per gli Spartani e Sparta usa spartan Il mio github

  3. #3
    Ops, grazie.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.