?
Solved

MFC Dialog Change labels for buttons with Function

Posted on 2004-10-20
6
Medium Priority
?
604 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 1500 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month11 days, 12 hours left to enroll

752 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