CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Jun 2014
    Posts
    6

    [RESOLVED] BS_PUSHBUTTON starts disabled on creation

    Hi,
    I am trying to create a button on a panel. On creation however it starts off disabled and I can't find out why.

    In my class:
    Code:
    CButton				   m_ZoomIncrease;
    On creation of the panel:
    Code:
    m_ZoomIncrease.Create(CString((LPCTSTR)IDS_ZOOM_INCREASE),WS_CHILD|WS_VISIBLE|BS_RADIOBUTTON,CRect(0,0,20,20),this,IDC_INCREASEZOOM);
    If I change BS_PUSHBUTTON to either BS_AUTO3STATE or BS_AUTOCHECKBOX it works fine. If I change it to BS_RADIOBUTTON however it still doesn't work.

    Any help would be greatly appreciated.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: BS_PUSHBUTTON starts disabled on creation

    I used this code:
    Code:
    	CButton myButton2;
    ...
    	// Create a radio button.
    	myButton2.Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_RADIOBUTTON, 
    				CRect(10,40,100,70), this, 2);
    And it works:Name:  radio.jpg
Views: 624
Size:  5.6 KB
    Victor Nijegorodov

  3. #3
    Join Date
    Jun 2014
    Posts
    6

    Re: BS_PUSHBUTTON starts disabled on creation

    Here is what I get with my code.
    Name:  buttons.PNG
Views: 505
Size:  1.5 KB

    Copied your code just in case and I get the same result. So something somewhere else in the code is disabling it?
    Name:  buttons2.PNG
Views: 498
Size:  1.3 KB

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: BS_PUSHBUTTON starts disabled on creation

    Code you post a small project that can reproduce this behaviour?
    Zip it up (not including .ncb, .aps, .sdf files nor Debug. Release, ipch folders) and we will try to test it.
    Victor Nijegorodov

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: BS_PUSHBUTTON starts disabled on creation

    Create a button handler for it.

  6. #6
    Join Date
    Jun 2014
    Posts
    6

    Re: BS_PUSHBUTTON starts disabled on creation

    I have identified the problem however I don't understand why it occurs.

    In my OnPaint() function I call CPaintDC dc(this) which is what causes the buttons to become disabled. Anyone know why this may be?

    Code:
    void MxScopePanel::OnPaint()
    {
      DWORD          ix, inc;
      int            y;
      DWORD          col;
      DWORD          grpix, strmix;
      MxScopeGroup  *pGroup;
      MxScopeStream *pStream;
      CRect          clientarea, area;
      MxScopeManager *pScope = MxScopeManager::GetDefault();
      CString tempHeight = MxGlobals().CurrentDigital.Get();
      DWORD Heighti = MXUtils::ConvertMetricVal(tempHeight);
    
    
      //Fill the background with the doc's background
      CPaintDC dc(this); // device context for painting
      
      // Get the colour here
      col = dc.GetBkColor();
    	
      dc.SetBkMode(TRANSPARENT);
      this->GetClientRect(clientarea);

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: BS_PUSHBUTTON starts disabled on creation

    1. What is MxScopePanel?
    2. What are you going to paint in ints OnPaint method? What for?
    3. BTW, you whole pane (post#3) looks like disabled. Is it by design?
    Victor Nijegorodov

  8. #8
    Join Date
    Jun 2014
    Posts
    6

    Re: BS_PUSHBUTTON starts disabled on creation

    MxScopePanel is my class which is used to produce a data scope panel.
    This is what gets created through OnPaint.
    Name:  Datascope.jpg
Views: 684
Size:  26.9 KB
    What I am currently working with produces the data scope and draws it through OnPaint. What I have added is the + and - button and the slider.
    The slider works fine so that isn't disabled. If I comment out the CPaintDC dc(this) along with all the dc parts within the rest of OnPaint the buttons become enabled and functional however the rest of the scope isn't drawn as dc is needed throughout OnPaint to draw the data scope.
    Last edited by David-I; July 1st, 2014 at 08:51 AM.

  9. #9
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: BS_PUSHBUTTON starts disabled on creation

    Quote Originally Posted by David-I View Post
    MxScopePanel is my class which is used to produce a data scope panel.
    This is what gets created through OnPaint.
    ...
    What I am currently working with produces the data scope and draws it through OnPaint. What I have added is the + and - button and the slider.
    The slider works fine so that isn't disabled. If I comment out the CPaintDC dc(this) along with all the dc parts within the rest of OnPaint the buttons become enabled and functional however the rest of the scope isn't drawn as dc is needed throughout OnPaint to draw the data scope.
    1. What is your class derived from?
    2. Isn't it possible to add radio button in the resource editor?
    3. CPaintDC dc(this) is used within OnPaint. It is by design of Microsoft Framework. So if you comments it out then nothing will be painted on the panel. Except the controls that draw themselves (all visible child controls)
    4. If your radio button gets (or, at least looks like) disabled because of executing the code in OnPaint then you are doing your drawing wrong!
    Victor Nijegorodov

  10. #10
    Join Date
    Jun 2014
    Posts
    6

    Re: BS_PUSHBUTTON starts disabled on creation

    Solved it.

    I examined how the CImageButton help button that is currently on there works and found it has an extra Message Map handle that I didn't spot before. So I passed my buttons through it and they now work as expected.
    Code:
    BEGIN_MESSAGE_MAP(MxScopePanel, MxScopePanel_Base)
    ...
    ON_UPDATE_COMMAND_UI(IDC_BTNHELP, OnHelpUI)
    ON_UPDATE_COMMAND_UI(IDC_INCREASEZOOM, OnHelpUI)
    ON_UPDATE_COMMAND_UI(IDC_DECREASEZOOM, OnHelpUI)
    ON_CONTROL_RANGE(BN_CLICKED, IDC_INCREASEZOOM, IDC_DECREASEZOOM, OnModifyZoom)   
    END_MESSAGE_MAP()
    
    
    void MxScopePanel::OnHelpUI(CCmdUI *pCmdUI)
    {
      // Update the command checkbox based on mode
      pCmdUI->Enable();
    }
    Thank you for your help and time Victor. Much appreciated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured