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.
I have written two member functions, one for setting bitmaps to CButtons, and one for setting bitmaps to CStatics. Actually both are working, when calling them on button press. But only the member-function for setting the CButtons works properly during the initialisation of the dialog. My CStatics are getting overwritten somehow.
This is working when called in OnInitDialog()
void CMyDlg::setBitmapAsButton(std::string file, CButton &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);
}
This is NOT working when called in OnInitDialog():
void CVisTrayDlg::setBitmapAsStatic(std::string file, CStatic &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);
}
CButton and CStatic controls are declared as member of CMyDlg.
Any ideas on how I can avoid this behaviour? Or is there even a better way to place bitmaps in a dialog? (I tried CImage::BitBlt() which got also overwritten somehow.)