WinAPI: Displaying an image on a button - common way doesn't work
<p>This causes me a headache: <strong>I can't use a given bitmap to be shown on a button - Windows says it's an "Invalid parameter"</strong>.</p>

<p>Here's my code:</p>

<pre><code>// creating the button
const HWND hButton=::CreateWindow("button","text",WS_CHILD|VS_VISIBLE,0,0,100,100,hParent,0,editor.m_hInstance,NULL);
// loading the bitmap to be shown on a button
const HBITMAP hBmp=(HBITMAP)::LoadImage(editor.m_hInstance,MAKEINTRESOURCE(ID_MYBITMAP),IMAGE_BITMAP,0,0,LR_LOADTRANSPARENT);
// associating the bitmap with a button that lacks the BS_BITMAP style (I want both image and text to be shown)
::SendMessage( hButton, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBmp );
// getting the error
const int err=::GetLastError(); // returns 0x56, "Invalid parameter"
</code></pre>

<p>Note that I <em>can</em> display the loaded image on the form's canvas, so the image is really correctly loaded.</p>

<p>I tried various resolutions of the bitmap (4 bits per pixel, 8 bits per pixel, standard pallete, true colour, 32 bits per pixel) - nothing worked. I read through tons of previous questions on this topic, all of which claim that the <code>::LoadImage</code> / <code>BM_SETIMAGE</code> combination is the ultimate solution - no result so far.</p>

<p>So my two questions:</p>

<p>1) Are there any requirements that an image has to fulfil to be shown on a button?</p>

<p>2) If not, then what am I actually doing wrong?</p>

<p>Many thanks in advance for a reply.</p>

<p>Tomas</p>