Click here to Skip to main content
15,897,891 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Threaded Concept Question Pin
Blake Miller3-Feb-05 6:18
Blake Miller3-Feb-05 6:18 
GeneralDetecting fullscreen apps Pin
Anonymous2-Feb-05 16:51
Anonymous2-Feb-05 16:51 
GeneralTired of this problem Pin
pc_dev2-Feb-05 16:42
pc_dev2-Feb-05 16:42 
GeneralMFC help PLEASE!! Pin
messin182-Feb-05 14:19
messin182-Feb-05 14:19 
GeneralRe: MFC help PLEASE!! Pin
Bob Ciora2-Feb-05 14:31
Bob Ciora2-Feb-05 14:31 
GeneralRe: MFC help PLEASE!! Pin
messin182-Feb-05 18:10
messin182-Feb-05 18:10 
GeneralRe: MFC help PLEASE!! Pin
Bob Ciora3-Feb-05 1:53
Bob Ciora3-Feb-05 1:53 
General3D in a dialog... Pin
Bob Ciora3-Feb-05 3:33
Bob Ciora3-Feb-05 3:33 
Ok, here's how I got this to work in the dialog:

1. As I mentioned, create some dummy control, a static text box, for example. Size this control within the dialog editor to the place where you want the 3D rendering to occur. Give it an ID that you can remember. For demo purpose, I used IDC_3DANCHOR. In the example below, I used a Static Text control so I can display errors if 3D initialization fails.

2. Declare a CWnd as a member variable of your dialog, e.g. CWnd m_wnd3D (as used in the examples below). This is the actual window to which 3D will be rendered.

3. In OnInitDialog, do the following (after the call to CDialog::OnInitDialog):
// Get the position of the anchor control within the dialog.
CWnd * pAnchor = GetDlgItem(IDC_3DANCHOR);
RECT rectAnchor;
pAnchor->GetWindowRect(&rectAnchor);
ScreenToClient(&rectAnchor);

// Create the window using the anchor's dialog-relative client rectangle.
if( !m_wnd3D.Create( NULL, "", WS_VISIBLE, rectAnchor,
                     this, ID_3DWINDOW, NULL ) )
{
  pAnchor->SetWindowText("Failed creating anchor window");
}

Note that you'll have to explicitly define ID_3DWINDOW in your resource file. But that's easy enough. The Create call will build your (future) rendering window, and position it within the dialog exactly over the Control that you're using as the anchor (IDC_3DANCHOR in this case). Passing this as the fifth parameter makes the window a child of the dialog.

4. After that, do the normal 3D initialization...get the IDirect3D interface, get the desktop format from the current display mode, and use that to create the device:
// Get the display mode to initialize the window..
HRESULT hResult =
   m_pDirect3D->GetAdapterDisplayMode(0, &m_d3dDisplayMode);
if( hResult != S_OK )
{
  pAnchor->SetWindowText("Failed getting adapter display mode");
  return TRUE;
}

// Now to create a windowed view.
memset(&m_d3dPresentParams, 0, sizeof(D3DPRESENT_PARAMETERS));
m_d3dPresentParams.Windowed = TRUE;
m_d3dPresentParams.hDeviceWindow = m_wnd3D;
m_d3dPresentParams.BackBufferFormat = m_d3dDisplayMode.Format;
m_d3dPresentParams.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC;
m_d3dPresentParams.EnableAutoDepthStencil = TRUE;
m_d3dPresentParams.AutoDepthStencilFormat = D3DFMT_D16;
hResult = m_pDirect3D->CreateDevice(
                          0, D3DDEVTYPE_HAL,
                          m_wnd3D,
                          D3DCREATE_HARDWARE_VERTEXPROCESSING,
                          &m_d3dPresentParams,
                          &m_p3DDevice );
if( hResult != S_OK )
{
  pAnchor->SetWindowText("Failed creating 3D Device");
  return TRUE;
}



5. If this was all successful, then the final step is to make sure that the original control you used as an anchor remains hidden:
pAnchor->ShowWindow(SW_HIDE);


6. OnPaint, then, is where you'd perform all of your rendering.

You'll probably want to consider adding OnSize handling in the event that the dialog gets resized, etc. etc.

But this sequence works just fine. In fact, if you know exactly where you want to put your 3D mini-view within the dialog, you don't really need the "anchor" control. I just included it since it's easier to manipulate its size in the dialog editor and just use the GetWindowRect call.

Oh, one other issue....if you're rendering to a Dialog and a View at the same time, you may want to look into Swap Chains. Just more fun Direct3D reading Smile | :)

Hope it helps!


Bob Ciora
GeneralRe: 3D in a dialog... Pin
Anonymous3-Feb-05 7:53
Anonymous3-Feb-05 7:53 
GeneralRe: 3D in a dialog... Pin
Bob Ciora3-Feb-05 11:31
Bob Ciora3-Feb-05 11:31 
GeneralRe: MFC help PLEASE!! Pin
Rick York3-Feb-05 7:28
mveRick York3-Feb-05 7:28 
GeneralRe: MFC help PLEASE!! Pin
Bob Ciora3-Feb-05 11:35
Bob Ciora3-Feb-05 11:35 
GeneralRe: MFC help PLEASE!! Pin
messin183-Feb-05 17:28
messin183-Feb-05 17:28 
GeneralRe: MFC help PLEASE!! Pin
Bob Ciora4-Feb-05 1:44
Bob Ciora4-Feb-05 1:44 
GeneralRe: MFC help PLEASE!! Pin
messin187-Feb-05 10:38
messin187-Feb-05 10:38 
GeneralUsing hot key to play CD with Hook !?! Pin
TTT812-Feb-05 14:13
TTT812-Feb-05 14:13 
QuestionWhy I was rejected so much with following resume ? Pin
vgrigor12-Feb-05 13:43
vgrigor12-Feb-05 13:43 
AnswerRe: Why I was rejected so much with following resume ? Pin
Bob Ciora2-Feb-05 14:11
Bob Ciora2-Feb-05 14:11 
GeneralRe: Why I was rejected so much with following resume ? Pin
vgrigor12-Feb-05 14:27
vgrigor12-Feb-05 14:27 
GeneralRe: Why I was rejected so much with following resume ? Pin
Anthony_Yio2-Feb-05 23:19
Anthony_Yio2-Feb-05 23:19 
GeneralRe: Why I was rejected so much with following resume ? Pin
vgrigor13-Feb-05 0:06
vgrigor13-Feb-05 0:06 
Generalmath puzzle Pin
ghostpirate72-Feb-05 13:26
ghostpirate72-Feb-05 13:26 
GeneralRe: math puzzle Pin
Bob Ciora2-Feb-05 13:43
Bob Ciora2-Feb-05 13:43 
GeneralPerformance Testing Pin
LighthouseJ2-Feb-05 12:56
LighthouseJ2-Feb-05 12:56 
GeneralRe: Performance Testing Pin
Bob Ciora2-Feb-05 13:28
Bob Ciora2-Feb-05 13:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.