Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't change MFC Button Caption

Tags:

c++

mfc

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?

like image 445
Kyeong Wook Ma Avatar asked Apr 23 '26 10:04

Kyeong Wook Ma


1 Answers

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.

like image 167
Jabberwocky Avatar answered Apr 24 '26 22:04

Jabberwocky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!