Solved

InvalidateRect

Posted on 2002-03-18
4
485 Views
Last Modified: 2013-11-20
If I understand things correctly, if you want a certain area of a window to be redrawn you call the CWnd::InvalidateRect function.

Question: Given an edit box in a form: How do get the coordinates of said edit box (in the CRect structure) to plug into the CWnd::InvalidateRect function?

Thanx
Ace
0
Comment
Question by:Smave
  • 2
4 Comments
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
Not neccessary.  

You can use Invalidate() or InvalidateRect(0) for the Edit control itself (rather than get a rect for some subset of the screen or some other window).

Also, it is not needed, sinc rhe Edit control updates itself each time its contents change.

But to answer your question, use the GetWindowRect() member function of the control.

-- Dan
0
 

Author Comment

by:Smave
Comment Utility
GetWindowRect(IDC_EDIT_RecordCNT);

gave me a compiler error.

error C2664: 'GetWindowRect' : cannot convert parameter 1 from 'const int' to 'struct tagRECT *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast

Do I need to create a member variable that is a control?

Thanx
Ace
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 50 total points
Comment Utility
>> GetWindowRect(IDC_EDIT_RecordCNT);

You should check the online help because that command is wrong in at least two obvious ways.  IDC_EDIT_RecordCNT is just an integer that identifies a control.  

>>Do I need to create a member variable that is a control?

no, but if you do, the command would like like:

CRect rc;
m_ctlEdit1.GetWindowRect( & rc );

if you don't create a member-variable control, you could use:

GetDlgItem(IDC_EDIT_RecordCNT)->GetWindowRect( & rc );

But as I said in the other question, the edit control will display the value automatically and does not need to be updated

(Exception: The screeen won't update right away if you do a lot of work in OnInitDialog.  Just set things up and return, otherwise all message processing stops).

-- Dan
0
 
LVL 1

Expert Comment

by:kirthir
Comment Utility
One addition to what Dan Rollins suggested
1)The GetWindowRect returns the postion of the control in terms of screen coordinates, to get the position in terms of client coordinates - call ScreenToClient(rc);

Hope this helps

0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now