2013-03-12 70 views
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; 
} 

我應該在哪裏給調用的函數更新標籤(靜態文本)

+1

這看起來很有意思:你已經設法編寫了上面的代碼,但是對它沒有任何瞭解?我們怎麼說這是** HOMEWORK **,你需要一兩個提示。然後這裏有一個提示:查看代碼中每個東西的*文檔*。 – 2013-03-12 08:07:18

+1

您還需要了解_indentation_。 – 2013-03-12 08:13:48

回答

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 
         } 
    
        } 
    

舉例:從這裏

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

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

  1. 要改變窗口的標籤http://msdn.microsoft.com/en-us/library/windows/desktop/ms633546(v=vs.85).aspx

+0

非常感謝georgesl – 2013-03-12 09:19:15