Problems setting bitmaps to Static Control MFC
<p>I'm currently fighting with a dialog based GUI, while trying to customize it. I have drawn some bitmaps which I would like to use as buttons and as logos in the dlg. </p>

<p>I have written two member functions, one for setting bitmaps to <code>CButton</code>s, and one for setting bitmaps to <code>CStatic</code>s. Actually both are working, when calling them on button press. But only the member-function for setting the <code>CButton</code>s works properly during the initialisation of the dialog. My <code>CStatic</code>s are getting overwritten somehow.</p>

<p>This is working when called in <code>OnInitDialog()</code></p>

<pre><code>void CMyDlg::setBitmapAsButton(std::string file, CButton &amp;Button, int xPos, int yPos)
{
    CImage imgFromFile;
    CBitmap bitmap;
    std::wstring wfile(file.begin(), file.end());

    HRESULT ret = imgFromFile.Load(wfile.c_str());
    int width = imgFromFile.GetWidth();
    int height = imgFromFile.GetHeight();
    bitmap.Attach(imgFromFile.Detach());

    Button.Create(_T("My button"), WS_CHILD | WS_VISIBLE | BS_BITMAP,
    CRect(xPos, yPos, xPos + width, yPos + height), this, 1);
    Button.SetBitmap(bitmap);
}
</code></pre>

<p>This is NOT working when called in <code>OnInitDialog()</code>:</p>

<pre><code>void CVisTrayDlg::setBitmapAsStatic(std::string file, CStatic &amp;Static, int xPos, int yPos)
{
    CImage imgFromFile;
    CBitmap bitmap;
    std::wstring wfile(file.begin(), file.end());

    HRESULT ret = imgFromFile.Load(wfile.c_str());
    int width = imgFromFile.GetWidth();
    int height = imgFromFile.GetHeight();
    bitmap.Attach(imgFromFile.Detach());

    Static.Create(_T("My Static"), WS_CHILD | WS_VISIBLE | SS_BITMAP,
    CRect(xPos, yPos, xPos + width, yPos + height), this);
    Static.SetBitmap(bitmap);
}
</code></pre>

<p><code>CButton</code> and <code>CStatic</code> controls are declared as member of <code>CMyDlg</code>.</p>

<p>Any ideas on how I can avoid this behaviour? Or is there even a better way to place bitmaps in a dialog? (I tried <code>CImage::BitBlt()</code> which got also overwritten somehow.)</p>