MFC Dialog Change labels for buttons with Function

Posted on 2004-10-20
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 );
        CWnd* pWnd = GetDlgItem(IDC_BUTTON1);
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?
Question by:vivekpara
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3

Author Comment

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

Any ideas on that as well?

Accepted Solution

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) )


Expert Comment

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.

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

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!

Author Comment

ID: 12364290 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.

Expert Comment

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


Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Include multiple hostnames in this command? 3 55
Excel Use VBA to get user's Mac Address for their computer 5 342
while loop over for loop 7 116
wordmultiple challenge 12 157
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. …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

726 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