Setting .ico file as custom icon for button

I tried using BS_OWNERDRAW as button style and then in WM_DRAWITEM, I tried using DrawIcon() to draw .ico file
was my plan wrong and should I use some other function or I did sth wrong in syntax?
any help?
Are you using Microsoft Visual Studio?
yes and i tried using code::blocks

I created button like this:
1
2
3
4
5
6
7
        case WM_CREATE:
            {
                CreateWindow   (L"button",L"",WS_CHILD| WS_VISIBLE| BS_PUSHBUTTON| BS_OWNERDRAW,
                                75,75,16,16//icon has 16x16 dimensions
,hwnd,(HMENU)IDC_BUTTON,GetModuleHandle(NULL),NULL);
            }
            break;



Next I handled WM_DRAWITEM message

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
        case WM_DRAWITEM:
            {
                switch((UINT)wParam)
                {
                    case IDC_BUTTON:
                        DRAWITEMSTRUCT *pdis = (DRAWITEMSTRUCT*)lParam;
                        LPTSTR text =TEXT("Failed to Load Icon");
                        HICON hIcon = (HICON) LoadIcon(GetmoduleHandle(NULL),TEXT("icon.ico"));
                        if(!DrawIcon(pdis->hDC,pdis->rcItem.top,pdis->rcItem.left, hIcon))
                        {
                            MessageBox(NULL,text,L"error",MB_OK);
                        }
                        if(pdis->itemState & ODS_SELECTED)
                            DrawEdge(pdis->hDC,&pdis->rcItem, EDGE_SUNKEN,BF_RECT);
                        else
                            DrawEdge(pdis->hDC,&pdis->rcItem, EDGE_RAISED,BF_RECT);
                        break;
                }
            }



i've put "icon.ico" file (ofc without quotes) into debug directory and in directory where are normal files
Last edited on
Topic archived. No new replies allowed.