Solved

MFC Dialog Change labels for buttons with Function

Posted on 2004-10-20
6
590 Views
Last Modified: 2013-11-20
I have been trying to make a dynamic MFC menu.  I have a function that updates the variables and then tries to change the label.  The function keeps getting an assert error.

Here is the function:
int currlevel;
CString ( lbutton1 );
CString ( lbutton2 );
CString ( lbutton3 );
CString ( lbutton4 );
CString ( lbutton5 );
CString ( lbutton6 );
CString ( lbutton7 );

CString ( abutton1 );
CString ( abutton2 );
CString ( abutton3 );
CString ( abutton4 );
CString ( abutton5 );
CString ( abutton6 );
CString ( abutton7 );

CButton ( m_button1 );
CButton ( m_button2 );
CButton ( m_button3 );
CButton ( m_button4 );
CButton ( m_button5 );
CButton ( m_button6 );
CButton ( m_button7 );

CString ( ascreentitle );
CString ( aleveluid );
CString ( htmlpg );
CString ( webloc ) = ".\\Web\\";


void SetMenuButtons( )
{
    currlevel = 1;
    lbutton1 = MENUARRAY[currlevel][2];
    lbutton2 = MENUARRAY[currlevel][4];
    lbutton3 = MENUARRAY[currlevel][6];
    lbutton4 = MENUARRAY[currlevel][8];
    lbutton5 = MENUARRAY[currlevel][10];
    lbutton6 = MENUARRAY[currlevel][12];
    lbutton7 = MENUARRAY[currlevel][14];
    abutton1 = MENUARRAY[currlevel][3];
    abutton2 = MENUARRAY[currlevel][5];
    abutton3 = MENUARRAY[currlevel][7];
    abutton4 = MENUARRAY[currlevel][9];
    abutton5 = MENUARRAY[currlevel][11];
    abutton6 = MENUARRAY[currlevel][13];
    abutton7 = MENUARRAY[currlevel][15];
      m_button1 = "Command Button 1";
      m_button2 = "Command Button 1";
      m_button3 = "Command Button 1";
      m_button4 = "Command Button 1";
      m_button5 = "Command Button 1";
      m_button6 = "Command Button 1";
      m_button1 = "Command Button 1";
//    htmlpg   = MENUARRAY[currlevel][1];

    //m_html->LoadPage( webloc + htmlpg );
   
    if    ( (lbutton1) != "NULL" )
      {
            if ( (lbutton1) != ""  )
        {
        m_button1.SetWindowText ( lbutton1 );
        }
      }
    else
        {
        CWnd* pWnd = GetDlgItem(IDC_BUTTON1);
                 ASSERT(pWnd);
                 pWnd->ShowWindow(SW_HIDE);
      ((CButton*)GetDlgItem(IDC_BUTTON1))->ShowWindow(SW_HIDE)
        };
etc., etc...

It fails each time.  Should the variable not be associated with the variable I defined in the class wizard for the button?  Is the variable type incorrect?
0
Comment
Question by:vivekpara
  • 3
  • 3
6 Comments
 
LVL 2

Author Comment

by:vivekpara
ID: 12361656
Also, the GetDlgItem keeps saying that it cannot take 1 parameters?

Any ideas on that as well?
0
 
LVL 8

Accepted Solution

by:
AaronReams earned 500 total points
ID: 12364157
Well as far as the GetDlgItem problem.   That's because you have to pass it a windows handle if your not invoking it from CWnd derived object's function.  

To fix this you either need

1) make the void SetMenuButtons( ) a member of CWnd derived class.  (ie.  CMyDlg::SetMenuButtons()  )

2) pass GetDlgItem a window handle (i.e.  GetDlgItem(m_pMyDlg, IDC_BUTTON1) )

Cheers,
Aaron
0
 
LVL 8

Expert Comment

by:AaronReams
ID: 12364224
I'm trying to figure out what you're attempting to do in the rest of your code... Dynamic menu?  Do you actually mean you want to dynamically switch the text of some buttons?   If so, I can easily help you with that.

-A
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 2

Author Comment

by:vivekpara
ID: 12364245
Actually, I had a library that was overriding the GetDlgItem.  I finally, in a fit of frustration, just made the CButton variables global so I could change their values in any function.

Bad programming...bad programming...but it WORKS!
0
 
LVL 2

Author Comment

by:vivekpara
ID: 12364290
Actually...got the lion's share working.  Dynamically updating buttons and it changes seamlessly.  My memory will fragment a bit...but I'm not going to worry about it.

=)

Points awarded for the attempt.
0
 
LVL 8

Expert Comment

by:AaronReams
ID: 12364302
Glad I could attempt to help:  ;-)

Cheers,
-Aaron
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Host to IP 7 78
sum67 challenge 35 99
has22 challenge 11 96
matchUp  challenge 6 64
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question