Help with Windows combobox.

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?

My full code is to long to post here, but I will post the important parts:

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#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;



Called on WM_CREATE:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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:

1
2
3
4
case WM_CLOSE:
            DestroyWindow(hwnd);
            ImageList_Destroy(g_himl);
        break;


Related code at the top of WinMain:

1
2
3
4
5
6
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!

EDIT: Here is a pastebin of my full code in case you need it:

http://pastebin.com/NjMSWaRr
Last edited on
Topic archived. No new replies allowed.