CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2009
    Posts
    128

    Unhappy doubt in DrawText()

    i have used DrawText() to display time init.i have used DT_CENTER which is display time in center even if window is minimised or maximised.

    but how to display it to right side of window but not on the minimise,maximise and close buttons.

    i tried DT_RIGHT =it is displaying on those 3 buttons (minimise,maximise and close buttons)

    Code:
               void CMainFrame::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");
    
    	         CWindowDC dc(this);
                     CRect rect;
    	         GetClientRect(&rect);
    
                     dc.DrawText(strTime,-1,&rect,DT_CENTER);
                   
                     //pWnd->SetWindowText(strTime);
    
                }

    also i am not able to display time on ActiveWIndow (GetForegroundWindow()) if i use DrawText() .

    If i use pWnd->SetWindowText(strTime) ,time is displayed on ActiveWindow(GetForegroundWindow()).

    what is the problem.
    plzzzzzz help me solve this problem.
    Last edited by dskp; January 21st, 2010 at 03:36 PM.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: doubt in DrawText()

    Quote Originally Posted by dskp View Post
    ...
    plzzzzzz help me solve this problem.
    You'd better explain what are you trying to accomplish...
    Victor Nijegorodov

  3. #3
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: doubt in DrawText()

    DON'T draw outside the OnDraw/OnPaint functions. It's useless because the window will redraw itself and your drawings are gone. Move your drawingroutines to the OnDraw/OnPaint and in the OnTimer you invalidate your window.

  4. #4
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: doubt in DrawText()

    You need to get the width of the window and deduct the widths of those buttons yourself.

    Note that they're located, drawn and sized differently on VIsta as opposed to XP and classic.

  5. #5
    Join Date
    Aug 2007
    Location
    Tokyo Japan
    Posts
    10

    Talking Re: doubt in DrawText()


  6. #6
    Join Date
    Nov 2009
    Posts
    128

    Re: doubt in DrawText()

    i have written it this way .but this doesn't work.

    Code:
    void CMainWnd::OnTimer(UINT_PTR nIDEvent)
    {
    	HWND hWnd;
    	hWnd = ::GetForegroundWindow();
    	CWnd *pWnd;
    	pWnd = CWnd::FromHandle(hWnd);
    	CTime Time = CTime::GetCurrentTime();
    	strTime=Time.Format("%H:%M:%S");
    	
            InvalidateRect(NULL,TRUE);
    }

    Code:
    void CMainWnd::OnPaint()
    {
    	//CPaintDC dc(this);
    	CWindowDC dc(this);
        CRect rect;
    	rect.left = 600;
    	rect.top = 4;
    	rect.right = 600;
    	rect.bottom = 23;
    
    	GetClientRect(&rect);
        dc.DrawText(strTime,-1,&rect,DT_CENTER);
    }
    what wrong with code.
    i did as " Skizmo" said.

  7. #7
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: doubt in DrawText()

    Code:
    HWND hWnd;
    hWnd = ::GetForegroundWindow();
    CWnd *pWnd;
    pWnd = CWnd::FromHandle(hWnd);
    You can remove this code from the OnTimer. You aren't using it anymore.

    Code:
    GetClientRect(&rect);
    This fills the rect with coordinates, so why are you filling it before that ?

    Code:
    rect.left = 600;
    rect.top = 4;
    rect.right = 600;
    rect.bottom = 23;
    The GetClientRect overwrites these coordinates, so it's useless to fill them.

    Code:
    //CPaintDC dc(this);
    CWindowDC dc(this);
    Why did you change to a CWindowDc ? In a normal window you should use CPaintDC.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured