Hey everyone. I am working on learning how to make some different controls with win32 and at the moment I amt trying to make a combobox with small images next to each option. However when I run my code the options are there but the images are missing. Can anyone help me out with this?

I will post the important parts of my code here and a link to a pastebin of the full code at the bottom:

define's, include's, and global variables:

#define _WIN32_WINNT 0x0600
#define _WIN32_IE 0x0900
#include <windows.h>
#include <commctrl.h>
#include <Tchar.h>

#define IDC_BUTTON_1 101
#define IDC_EDIT_1 201
#define IDC_EDIT_2 202
#define IDC_STATIC_1 301
#define IDC_STATIC_2 302
#define IDC_COMBO_BOX_1 401





const char g_ClassName[] = "WindowClass1";
HIMAGELIST g_himl;[/code]

Called on WM_CREATE:

HWND Combo1 = CreateWindowEx(
            NULL, WC_COMBOBOXEX, NULL,
            WS_BORDER | WS_VISIBLE | WS_CHILD | CBS_DROPDOWN,
            0, 0, 0, 100,
            hwnd, (HMENU)IDC_COMBO_BOX_1,
            GetModuleHandle(NULL), NULL);

            //Combo Box Items START
            COMBOBOXEXITEM cbei;
            int iCnt;

            typedef struct {
                int iImage;
                int iSelectedImage;
                int iIndent;
                LPTSTR pszText;
            } ITEMINFO, *PITEMINFO;

            ITEMINFO IInf[] = {
                {0, 3, 0, _T("first")},
                {1, 4, 1, _T("second")},
                {2, 5, 2, _T("third")},
                {0, 3, 0, _T("fourth")},
                {1, 4, 1, _T("fifth")},
                {2, 5, 2, _T("sixth")},
                {0, 3, 0, _T("seventh")},
                {1, 4, 1, _T("eighth")},
                {2, 5, 2, _T("ninth")},
                {0, 3, 0, _T("tenth")},
                {1, 4, 1, _T("eleventh")},
                {2, 5, 2, _T("twelfth")},
                {0, 3, 0, _T("thirteenth")},
                {1, 4, 1, _T("fourteenth")},
                {2, 5, 2, _T("fifteenth")},
            };

            cbei.mask = CBEIF_TEXT | CBEIF_INDENT | CBEIF_IMAGE | CBEIF_SELECTEDIMAGE;

            for(iCnt = 0; iCnt < 15; iCnt++) {
                cbei.iItem = iCnt;
                cbei.pszText = IInf[iCnt].pszText;
                cbei.cchTextMax = sizeof(IInf[iCnt].pszText);
                cbei.iImage = IInf[iCnt].iImage;
                cbei.iSelectedImage = IInf[iCnt].iSelectedImage;
                cbei.iIndent = IInf[iCnt].iIndent;

                if(SendMessage(Combo1, CBEM_INSERTITEM, 0, (LPARAM)&cbei) == -1) {
                    return FALSE;
                }
            }

            SendMessage(Combo1, CBEM_SETIMAGELIST, 0, (LPARAM)g_himl);
            SetWindowPos(Combo1, NULL, 20, 20, 250, 120, SWP_NOACTIVATE);


            //Combo Box Items END

My WM_CLOSE:

case WM_CLOSE:
            DestroyWindow(hwnd);
            ImageList_Destroy(g_himl);
        break;

Related code at the top of WinMain:

g_himl = ImageList_Create(
    20, 20, NULL, 3, 5);

    ImageList_AddIcon(g_himl, LoadIcon(GetModuleHandle(NULL), IDI_ASTERISK));
    ImageList_AddIcon(g_himl, LoadIcon(GetModuleHandle(NULL), IDI_ERROR));
    ImageList_AddIcon(g_himl, LoadIcon(GetModuleHandle(NULL), IDI_EXCLAMATION));

Any help is appreciated! Thanks!

Here is a link to a pastebin of my full code incase you would like to look at it: http://pastebin.com/NjMSWaRr

I would start by verifying that your function calls succeed. I.e., does ImageList_Create(...) succeed? How about the ImageList_AddIcon(...) calls and so on and so forth.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.