Using an icon on a dialog box window C++ Win32 API

Use LoadIcon and pass an icon handle to WM_SETICON.

HICON hicon = LoadImageW(GetModuleHandleW(NULL), MAKEINTRESOURCEW(IDI_ICONMAIN), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_DEFAULTSIZE);
SendMessageW(hwnd, WM_SETICON, ICON_BIG, hicon);

I had to cast the return value of LoadImageW() to HICON , to avoid the error :

" a value of type "HANDLE" cannot be assigned to an entity of type "HICON" ...."

this worked for me :

.... 
//hDlg is the handle to my dialog window
case WM_INITDIALOG:
    {
        HICON hIcon;

        hIcon = (HICON)LoadImageW(GetModuleHandleW(NULL),
            MAKEINTRESOURCEW(IDI_ICON1),
            IMAGE_ICON,
            GetSystemMetrics(SM_CXSMICON),
            GetSystemMetrics(SM_CYSMICON),
            0);
        if (hIcon)
        {
            SendMessage(hDlg, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
        }
    }
    break;

and here is the result

win32 Dialog icon

FYI: the used icon was downloaded from :

http://www.iconsdb.com/orange-icons/stackoverflow-6-icon.html

Hope that helps !