0

I have a button.

HWND button = CreateWindow("button", "test_text", WS_VISIBLE | WS_CHILD, 0, 0, 500, 500, window, NULL, NULL, NULL);

"window" is my HWND variable of my window.

How can I add icon like this HBITMAP hBitmap = (HBITMAP)LoadImage(NULL, TEXT("1.png"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION); to my "button" variable?

I serched information about my problem in the Inthernet, but I can't find anything, that can work.

3
  • 2
    The documentation covers this. See Button Control Overviews. Commented Dec 6, 2023 at 18:07
  • 1
    There is a C++ answer here if that points you the right way. Commented Dec 6, 2023 at 18:07
  • Could you please check Remy Lebeau‘s answer? You could try to use LoadImage to load an icon or bitmap.You couldn't load .png via LoadImage directly. And then use BM_SETIMAGE message to associate a new image (icon or bitmap) with the button. Commented Dec 18, 2023 at 1:36

1 Answer 1

1

First off, you can't use LoadImage() to load a .png file as an HBITMAP. See questions like How would I load a PNG image using Win32/GDI (no GDI+ if possible)? and How would I draw a PNG image using LoadImage and StretchDIBits? for alternatives.

Second, once you do have your image loaded as an HBITMAP (or HICON), you can assign it to the button using the BM_SETIMAGE message.

Not the answer you're looking for? Browse other questions tagged or ask your own question.