Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Getting the coordinates of a picture control

Posted on 2000-04-06
8
Medium Priority
?
409 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
ID: 2689764
// 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:Vinayak Kumbar
ID: 2689765
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
ID: 2689774
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:degarn
ID: 2689930
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
 

Author Comment

by:klingej
ID: 2689966
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 150 total points
ID: 2690021
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
ID: 2690071
trying adding another picture control, rebuild all, see if the GetDlgItem(ID_SECONDCONTROL) returns NULL also.

 
0
 

Author Comment

by:klingej
ID: 2690073
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses
Course of the Month13 days, 3 hours left to enroll

972 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