Link to home
Start Free TrialLog in
Avatar of GlennDean
GlennDean

asked on

Defining a child CWnd object from a CRect

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


ASKER CERTIFIED SOLUTION
Avatar of DanRollins
DanRollins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of GlennDean
GlennDean

ASKER

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  
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
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
Oops, didn't finish my comment.  I will have to get back to you later on whether TextOut works on my child window.
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.
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
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
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