Winapi 如何使整数显示在窗口中?

Winapi 如何使整数显示在窗口中?,winapi,calculator,Winapi,Calculator,我希望在窗口中有如下内容: int a; cout<<a; inta; cout您可以在相应的按钮处理程序中进行计算,并使用消息设置“屏幕”文本 想法如下: 你有两个按钮,一个加一个减。您可以在WM\u create处理程序中创建它们,如下所示: case WM_CREATE: { HWND btnAdd = CreateWindowEx( 0, L"Button", L"+1", //this is the te

我希望在窗口中有如下内容:

int a;
cout<<a;
inta;

cout您可以在相应的按钮处理程序中进行计算,并使用消息设置“屏幕”文本

想法如下:

你有两个按钮,一个加一个减。您可以在
WM\u create
处理程序中创建它们,如下所示:

case WM_CREATE:
    {
        HWND btnAdd = CreateWindowEx( 0, L"Button", 
                     L"+1", //this is the text for your adding button
                     WS_CHILD | WS_VISIBLE | WS_BORDER | BS_PUSHBUTTON,
                     50, 150, 150, 25, hWnd, (HMENU)8004, hInst, 0 );

        HWND btnSubtract = CreateWindowEx( 0, L"Button", 
                     L"-1", //this is the text for your adding button
                     WS_CHILD | WS_VISIBLE | WS_BORDER | BS_PUSHBUTTON,
                     50, 250, 150, 25, hWnd, (HMENU)8005, hInst, 0 );

        // since you want "calculator type" application
        // here is your result window-edit control

        HWND input = CreateWindowEx( 0, L"Edit", 
                     L"", // no need for text
                     WS_CHILD | WS_VISIBLE | WS_BORDER | ES_NUMBER | ES_AUTOHSCROLL,
                     50, 450, 150, 25, hWnd, (HMENU)8006, hInst, 0 );

        HWND result = CreateWindowEx( 0, L"Edit", 
                     L"", // no need for text
                     WS_CHILD | WS_VISIBLE | WS_BORDER | ES_READONLY | ES_AUTOHSCROLL,
                     50, 450, 150, 25, hWnd, (HMENU)8007, hInst, 0 );

        // other stuff

    }
    return 0L;
用户单击按钮后,您可以使用
SetWindowText
设置
result
编辑控件的文本,如
WM_命令中的处理程序所示:

case 8004: // add 1 to the number
    {
        // get the number from input edit control
        wchar_t temp[10];
        GetWindowText( GetDlgItem( hWnd, 8006 ), temp, 10 );   

        //convert text to nubmer
        int InputedNumber = wtoi( temp );

        // show the result in the result edit control
        memset( temp, L'\0', sizeof(temp) ); //reuse variable to save memory
        swprintf_s( temp, 10, L"%d", InputNumber+1 ); //convert result to text
        SetWindowText( GetDlgItem( hWnd, 8007 ), temp ); //show the result
    }
case 8005: // subtract 1 to the number
    {
        // get the number from input edit control
        wchar_t temp[10];
        GetWindowText( GetDlgItem( hWnd, 8006 ), temp, 10 );   

        //convert text to number
        int InputedNumber = wtoi( temp );

        // show the result in the result edit control
        memset( temp, L'\0', sizeof(temp) ); //reuse variable to save memory
        swprintf_s( temp, 10, L"%d", InputNumber-1 ); //convert result to text
        SetWindowText( GetDlgItem( hWnd, 8007 ), temp ); //show the result
    }
上面是
C++
的相关代码片段

这对你来说可能是个大麻烦,所以我建议你去处理


祝你好运,并致以良好的祝愿

您正在询问如何创建GUI应用程序。那太宽了。读佩佐尔德的书。