Solved

Defining a child CWnd object from a CRect

Posted on 2001-07-22
9
402 Views
Last Modified: 2013-11-20
Hi:
   I want to get a CWnd object of my view class that is a portion of the view window.  Basically what I want is a CWnd object that represents
  CRect(100,100,500,500)
of the view window.  
   Then, given the CWnd object (call it pWnd) I should be able to go
 
CDC * pDC = pWnd->GetDC();
pDC->TextOut(0,0,"Hey-Hey");

I don't know if the following info will help but the reason I need the pWnd object is because I need to tell the clipper returned by Direct3D's function DirectDrawCreateClipper what window it can draw on.  

   Glenn


0
Comment
Question by:GlennDean
  • 5
  • 4
9 Comments
 
LVL 49

Accepted Solution

by:
DanRollins earned 150 total points
ID: 6306909
You can only get a valid CWnd* from a valid window -- not from an abitrary rectangle.

So, you will need to do one of:
*) pass the CWnd* of the View ... or
*) Create a new window at the desired location and pass its CWnd*

-- Dan
0
 
LVL 3

Author Comment

by:GlennDean
ID: 6306926
I'm not sure how to, as you said,

*) Create a new window at the desired location and pass its CWnd*

I created a child window of the view at the desired coordinates and size.  Unfortunately, Direct3D didn't draw anything to that window.  That doesn't mean the idea doesn't work (i.e. create a window at the desired location), but I'm not sure if the child window I created is "acceptable to Direct3D".  

  Glenn  
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6306986
Make sure the window is fully created and valid:  Can you do other things with the window, such as TextOut, etc?

When you call pObj->SetHWnd( m_hWnd ), what is the return code?

-- Dan
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 3

Author Comment

by:GlennDean
ID: 6306995
When I create the child window at the desired coordinates, I verify the m_hWnd is non-zero.  When I call SetHWnd the return code is D3D_OK (i.e. everything worked fine).
   
   Glenn
0
 
LVL 3

Author Comment

by:GlennDean
ID: 6306999
Oops, didn't finish my comment.  I will have to get back to you later on whether TextOut works on my child window.
0
 
LVL 3

Author Comment

by:GlennDean
ID: 6307005
After creating the child window, I called GetDC on that window and it was non-null.  I then went
pDC->TextOut(0,0,"Hi")
but I did not see that text on the view window.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6307020
That text would *not* appear on the view window.  

It should appear on the child window.  Make sure that the child window that you created is visible and at the expected location (floating above the View window.

Anyway, why don't you just pass the hWnd of the View? I don't get it.

-- Dan
0
 
LVL 3

Author Comment

by:GlennDean
ID: 6308442
The reason I can't pass the hWnd of the View is because Direct3D uses that window for its drawing.  What I'm trying to do is display some graphics on a view (but eventually I want to display 3D graphics on things like a button or a dialog box) and I can't have Direct3D drawing on the entire window.  I need to specify a subportion of the window (so, for example, I want Direct3D to draw graphics on the upper right of the view).

   Glenn
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6309873
I don't have any Direct3D experience.  Perhaps you can instruct Direct3D to write on just a certain portion of the window while leaving the rest untouched.  Otherwize, you will need to float a window over the View and write to that window.  It can be a borderless windoe, like a tooltip.

You might be able to keep the target window hidden, then just blit from it onto the view surface when you need to update the view.

-- Dan
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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 a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 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