Solved

Getting the coordinates of a picture control

Posted on 2000-04-06
8
385 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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:VinExpert
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 50 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: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

729 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