Solved

MFC Dialog Change labels for buttons with Function

Posted on 2004-10-20
6
584 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
how do i create updater to My Activex application? 3 74
countEvens challenge 2 59
Window placement 17 65
sumHeights2  challenge 7 78
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now