0

我想在 vc++ 窗口中更改标签。标签显示每 100 毫秒更新一次的实时数据。那么我怎么能在vc++窗口中做到这一点呢?任何人请帮助

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    HWND hRPMEx,hAvgTimeEx;
    int wmId, wmEvent;
    PAINTSTRUCT ps;
    HDC hdc;

    switch(message)
    {
    case WM_TIMER:
        break;

    case WM_CREATE:
        hRPMEx  = CreateWindowA("Static","",WS_CHILD | WS_VISIBLE | SS_LEFT,
            20,100,220,25,
            hWnd, (HMENU)IDC_RPM_EX, hInstance, NULL);  

        hAvgTimeEx  = CreateWindowA("Static","",WS_CHILD | WS_VISIBLE | SS_LEFT, 
            20,150,220,25,
            hWnd, (HMENU)IDC_AVGTIME_EX, hInstance, NULL);  
        break;

    case WM_COMMAND:
        wmId    = LOWORD(wParam);
        wmEvent = HIWORD(wParam);
        // Parse the menu selections:

        switch (wmId)
        {
        case IDC_BTN_CONNECT:
            break;

        case IDC_RPM_EX:
            break;

        case IDC_BTN_DISCONNECT:
            break;

        case IDM_ABOUT:
            DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
            break;

        case IDM_OPEN:
            break;

        case IDM_EXIT:
            break;

        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
        }

        break;

    case WM_PAINT:
        hdc = BeginPaint(hWnd, &ps);
        EndPaint(hWnd, &ps);
        break;

    case WM_DESTROY:
        PostQuitMessage(0);
        break;

    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }

return 0;
} 

我应该在哪里调用更新标签的函数(静态文本)

4

1 回答 1

1

两件事情 :

  1. 要定期更新某些内容,您可以使用计时器。一个例子 :

        // To set the timer
        SetTimer(hwnd,             // handle to main window 
        IDT_TIMER1,            // timer identifier 
        10000,                 // 10-second interval 
        (TIMERPROC) NULL);     // no timer callback 
    
        // In you WindProc Callback :
        case WM_TIMER:
        {
            if ( wParam == IDT_TIMER1)
            {
                  // put your code here
            } 
    
        }
    

此处的示例:http: //msdn.microsoft.com/en-us/library/windows/desktop/ms644901 (v=vs.85).aspx

  1. 要更改窗口的标签:

    BOOL WINAPI SetWindowText(
      _In_      HWND hWnd,
      _In_opt_  LPCTSTR lpString
    );
    

此处的示例:http: //msdn.microsoft.com/en-us/library/windows/desktop/ms633546 (v=vs.85).aspx

于 2013-03-12T08:24:33.500 回答