Solved

Getting the coordinates of a picture control

Posted on 2000-04-06
8
343 Views
Last Modified: 2013-11-20
I have a picture control (type rectangle) placed on a form view for a SDI application.  I am trying to get the coordinates of this control to render OpenGL at that location.  However, when I use:
CWnd *pwnd = GetDlgItem(IDC_PICT_CONTROL), it always returns NULL ??  Is there something special about the properties of the form (or if I do this on a dialog) that I need to know?

I have used this method successfully before to display bitmaps on dialogs and it worked well.

I'd appreciate any ideas.
0
Comment
Question by:klingej
8 Comments
 

Author Comment

by:klingej
Comment Utility
// the code looks like this that I am trying to use


RECT rectDest, rectParent;
CWnd pwnd  = GetDlgItem(IDC_STATIC_VIEWPORT);
if(pwnd) {
  pwnd->GetWindowRect(&rectDest);
  GetWindowRect(&rectParent);
  rectDest.left -= rectParent.left;
  rectDest.right -= rectParent.left;
  rectDest.top -= rectParent.top;
  rectDest.bottom -= rectParent.top;
}
0
 
LVL 8

Expert Comment

by:VinExpert
Comment Utility
Hi,

From where r u calling GetDlgItem(IDC_PICT_CONTROL)?. If U r calling from the child of the window where u have placed the control, then use like

CWnd *pwnd = GetParent()->GetDlgItem(IDC_PICT_CONTROL);
or
CWnd *pwnd = ((UrFormViewClassName *)GetParent())->GetDlgItem(IDC_PICT_CONTROL);

Try it out.

VinExpert
0
 

Author Comment

by:klingej
Comment Utility
I'm calling it from a function belonging to either the dialog or form view (not a child), so I don't need GetParent().

0
 

Expert Comment

by:degarn
Comment Utility
How is your image control created klingej ? I've just tried the same code and it works as you want it to work (pWnd has a value!)...
Check that your control already exists when you call the GetDlgItem !
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:klingej
Comment Utility
I put it on the form view (or dialog) using the graphical editor.  I place a picture control, set the type to rectangle, and uncheck the visible option.  This has worked for me in the past, so I guess something must be different?
0
 

Accepted Solution

by:
degarn earned 50 total points
Comment Utility
It still works for me now ...
Something is different in your code !
Where do you call the GetDlgItem() function ?
The only reason I see you could get a NULL pointer is that your control doesn't exists (still not created when getDlgItem is called) or that the ID you use in the call is not correct ...

Perhaps try to call your GetDlgItem() at another place in your class (set a button that execute it when you click for instance and see if pWnd still NULL).

In this case, a call to GetLastError() just after the call to GetDlgItem()could leran you more about the reasons control is not found...
0
 

Expert Comment

by:leowlf
Comment Utility
trying adding another picture control, rebuild all, see if the GetDlgItem(ID_SECONDCONTROL) returns NULL also.

 
0
 

Author Comment

by:klingej
Comment Utility
I was calling it in OnSize, but I moved it to OnPaint and it works fine now..  (although this causes other issues to deal with :)


thanks.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Running shell command from Access 3 63
sameEnds challenge 3 105
Hibernate methods 2 58
How to convert MFC::CString to UTF8 wchar_t* 10 92
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

763 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

9 Experts available now in Live!

Get 1:1 Help Now