CBitmapButton Problem

Go4Expert Member
7Jan2009,14:10   #1
KaimTazz's Avatar
Hi all..
I have placed button ctrl having ID = IDC_BUTTON1 over dialog and Added Bitmap having ID="BUTTON_IMPORT". I have written following code snippet in OnInitDialog():-

{
.
.
CBitmapButton MyBmpBtn;
MyBmpBtn.LoadBitmaps(_T("BUTTON_IMPORT"));

CButton *btn;
btn = reinterpret_cast<CButton *>(GetDlgItem(IDC_BUTTON1));

LONG GWLIMP = GetWindowLong(btn->m_hWnd, GWL_STYLE);
SetWindowLong(btn->m_hWnd, GWL_STYLE, GWLIMP | BS_OWNERDRAW);

MyBmpBtn.SubclassDlgItem(IDC_BUTTON1,this);
.
.
}

But Button is not visible on dialog when i execute program......
pls help me out know why button have been not displayed on screen....

thanks all
Go4Expert Founder
7Jan2009,14:35   #2
shabbir's Avatar
You should define your MyBmpBtn variable in the scope of the dialog class and not in InitDialog function as that would mean when the function ends the variable is out of scope. This is the most common mistake even I faced writing my first button though and had to learn the hard way out of assembly debugging.
Go4Expert Member
7Jan2009,16:10   #3
KaimTazz's Avatar
oh thats great.... thankyou so much for your support.
Go4Expert Member
8Jan2009,12:39   #4
KaimTazz's Avatar
Hi all,

Here i got another problem. Following is the hierarchy of class inheritance:-

class CXPropertyPage : Public CPropertyPage

class CPPage : Public CXPropertyPage

class CChild : Public CPPage

As Shabbir suggested to add CBitmapButton object in class, i tried to add it in CChild class and i found an assertion in OnInitDialog of CXPropertyPage. It occurs in CXPropertyPage::OnInitDialog() when it calls CPropertyPage::OnInitDialog() :-

BOOL CXPropertyPage::OnInitDialog()
{
CPropertyPage::OnInitDialog();

return TRUE;
}

I have no Idea why I am getting assertion/Exception !!
Pls help me to find out solution...

Thanks All
Go4Expert Member
8Jan2009,17:33   #5
KaimTazz's Avatar
Hi All.

I dont know, but, if i try to add/delete any member in CChild( pls take a look at class hierarchy in previous quote) class program gives assertion otherwise things are going well.
Go4Expert Founder
8Jan2009,18:34   #6
shabbir's Avatar
Where are you getting the assertion?
Go4Expert Member
12Jan2009,16:11   #7
KaimTazz's Avatar
Hi,
everything was fine after ur solution.. the problem was with file attributes and access rights....

Now there is no problem with CBitmapButton...
Thanks a Lot