Re: Hide dialog at first
Thanks for your answers. I`ve changed my cstatic class according to
your recommendations.
class CImageStatic :
public CStatic
{
public:
CImageStatic(void);
virtual ~CImageStatic(void);
protected:
BITMAP bm;
HBITMAP hBitmap;
protected:
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg void OnPaint();
DECLARE_MESSAGE_MAP()
};
CImageStatic::CImageStatic(void)
{
hBitmap = (HBITMAP)LoadImage( GetModuleHandle(NULL),
MAKEINTRESOURCE(IDB_EDTBOX),
IMAGE_BITMAP,
0,
0,
LR_CREATEDIBSECTION | LR_DEFAULTCOLOR);
if( hBitmap == NULL )
return;
GetObject(hBitmap, sizeof(BITMAP), &bm );
}
One question: What are you suggesting to do if the LoadImage() method
failed for any reason, or is it sure that is always will work? Writing
a short comment into the logfile and no further information to the
user?
BOOL CImageStatic::OnEraseBkgnd(CDC* pDC)
{
return TRUE;
}
void CImageStatic::OnPaint()
{
CPaintDC dc(this); // device context for painting
CPoint size( bm.bmWidth, bm.bmHeight );
CRect rect;
GetClientRect(rect);
CBrush brush;
brush.CreateSolidBrush(RGB(0,0,0));
CDC MemDC;
MemDC.CreateCompatibleDC(&dc);
int SavedState = MemDC.SaveDC();
MemDC.SelectObject(hBitmap);
dc.FillRect(rect, &brush);
dc.BitBlt(0,0,size.x,size.y,&MemDC,0,0,SRCCOPY);
//init some default values in the constructor as well as the option
//to change these colors with some methods...
dc.SetTextColor(RGB(255,255,255));
dc.SetBkColor(RGB(0,0,0));
dc.SetBkMode(RGB(0,0,0));
dc.TextOut(0, 0, _T("test"), 5); // whatever...
MemDC.RestoreDC(SavedState);
}
How is it possible to use SetWindowText() in any OnInitDialog() method
for a member of this class, so that the text will be shown? Do I have
to use GetWindowText() in the OnPaint() method of CImageStatic class
to get the text and after that dc.Textout()?
void MyDlg::OnInitDialog()
{
//CImageStatic member
m_MyStaticImg.SetWindowText(_T("test-text"));
return TRUE;
}
best regards
Hans