无法更改MFC按钮标题

Kye*_* Ma 3 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]));
    }
}
Run Code Online (Sandbox Code Playgroud)

我想动态更改按钮标题.

当使用SetWindowTextW与静态文本,如"静态文本",它运作良好,

但是使用char数组(在本例中为szTest),标题不会改变

我编码错误的类型铸件?

Jab*_*cky 7

代码中的内部for循环对我来说并不敏感.你可能想要这个:

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);
}
Run Code Online (Sandbox Code Playgroud)

使用那段代码,第一个按钮将包含"0",第二个按钮将包含"1"等.