简体   繁体   中英

Can't change MFC Button Caption

int firstButton = IDC_BUTTON1;  

for(int i = firstButton; i < firstButton + 16; ++i)
{
    CWnd *pB = GetDlgItem(i);

    for(int j = 0; j < 16; ++j)
    {

        pB->SetWindowTextW((LPCTSTR)(szTest[j]));
    }
}

I want to change button caption dynamically.

when in use SetWindowTextW with static text like "static txt" it works well,

but with char array (in this case szTest), the captions are'nt changed

Am i coded a wrong type casting?

The inner for loop in your code doesn't make sens to me. You probably want this:

char szTest[] = "0123456789ABCDEF" ;

int firstButton = IDC_BUTTON1;  

for (int i = firstButton; i < firstButton + 16; ++i)
{
    CWnd *pB = GetDlgItem(i);
    CString str(szTest[i]) ;
    pB->SetWindowText(str);
}

With that piece of code, the first button will contain "0", the second will contain "1" etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM