how to display time in place of MY TIME

Discussion in 'MFC' started by palz, Jan 21, 2010.

  1. palz

    palz New Member

    Joined:
    Jan 13, 2010
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    India
    i have used OnNcPaint to diplay text init using the following code.

    Code:
          void CMainWnd::OnNcPaint( )
           {
                 HDC dc = GetWindowDC()->m_hDC;
                 RECT rectWnd = {800,4,880,23};
                 FillRect(dc, &rectWnd, (HBRUSH)GetStockObject(DKGRAY_BRUSH));
                 SetBkMode(dc, TRANSPARENT);
                 SetTextColor(dc, RGB(255, 0,0));
                  DrawText(dc, "MY TIME", strlen("My TIME"), &rectWnd, 0);
                 ::ReleaseDC(m_hWnd,dc);
            }
    
    and used timer to show the time in any active window using the following code

    Code:
              void CMainWnd::OnTimer(UINT_PTR nIDEvent)
               {
                     HWND hWnd;
                     hWnd = ::GetForegroundWindow();
                     CWnd *pWnd;
                     pWnd = CWnd::FromHandle(hWnd);
                     CTime Time = CTime::GetCurrentTime();
                     CString strTime=Time.Format("%H:%M:%S");
                     pWnd->SetWindowText(strTime);
               } 
    
    the problem is i want to place the updated time(IN TIMER) in the place of "MY TIME" .
    HOW TO DO THAT.
    i am unable to integrate them both.
    PLZ HELP ME.
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    In the class CMainWnd Define the member variable CString strTime and assigning it in OnTimer will update it and NCPaint will Display it.

    Remember there can be painting issue of the Non-Client Window
     
  3. palz

    palz New Member

    Joined:
    Jan 13, 2010
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    India
    there are painting issues as u said. how to solve them.is there any simple method

    can i use DrawText to display upadated time.

    my require output is towards rightside of window.
    [​IMG]

    plz help
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice