1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

CBitmapButton Problem

Discussion in 'MFC' started by KaimTazz, Jan 7, 2009.

  1. KaimTazz

    KaimTazz New Member

    Joined:
    Aug 8, 2007
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    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.
     
  3. KaimTazz

    KaimTazz New Member

    Joined:
    Aug 8, 2007
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    oh thats great.... thankyou so much for your support.
     
  4. KaimTazz

    KaimTazz New Member

    Joined:
    Aug 8, 2007
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  5. KaimTazz

    KaimTazz New Member

    Joined:
    Aug 8, 2007
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    Where are you getting the assertion?
     
  7. KaimTazz

    KaimTazz New Member

    Joined:
    Aug 8, 2007
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    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
     

Share This Page