Solved

MFC Dialog Change labels for buttons with Function

Posted on 2004-10-20
6
595 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
[X]
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
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
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!

 
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

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!

Question has a verified solution.

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

696 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