D3D wrapper and Control dialog on vc++6

Started by
4 comments, last by Endurion 19 years, 4 months ago
Hi every one, i just have a problem , do anybody had code for make a window app initialitating D3D with dialog or control in the window? control i mean, for example the clasic FILE-->OPEN or FILE-->SAVE AS.. that clasic windows with a D3D device ready. i just have problem with that. if anybody has code samples of that, it would be very welcome, thanks to all.
Advertisement
The only difference in the code should be the HWND you set in the presentation parameters. Instead of the main HWND you insert the HWND of the control which should display the D3D device.

It works best with a static control set to ownerdraw (SS_OWNERDRAW). In that case you need to call the rendering function inside WM_DRAWITEM instead of WM_PAINT though.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

i dont understand thar part, im going to look in google or yahoo, abou that

a paste this code main.cpp, maybe someone see the error fast than me.

thanks.



#pragma comment(lib, "d3d8.lib")
#pragma comment(lib, "d3dx8.lib")
//
#include <windows.h>

//d3d wrapper
#include "d3d.h"
//input
#include "ZGInput.h"
#include "CUBO.h"
#include "ZGIMG2D.h"
#include "resource.h"
#include "IDS.h"


LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM);

//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////


HWND g_hwnd = NULL; //Main window handler
char g_title[] = "D3D Wrapper";
char g_class[] = "D3D Wrapper";
BOOL g_isWindowed = TRUE;

float MX=0.1;
float MY=0.1;
float fRotx=0.01;
float fRoty=0.01;
CUBO *cubo[4];
int CH=VERD;
ZGInput DInput;


ZGIMG2D *imagen2d;


void ProcesarKeyboard()
{

if (DInput.Read_Keyboard())
{
//lee con exito el keyb
if (DInput.KeyDown(DIK_RIGHT))
{
fRoty+=0.01f;
//MessageBox(NULL, "tecla ", "derecha", MB_OK);
//todo tecla derecha
}
}

if (DInput.Read_Keyboard())
{
if (DInput.KeyDown(DIK_LEFT))
fRoty-=0.01f;
}

if (DInput.Read_Keyboard())
{
if (DInput.KeyDown(DIK_UP))
fRotx+=0.01f;
}

if (DInput.Read_Keyboard())
{
if (DInput.KeyDown(DIK_DOWN))
fRotx-=0.01f;
}

}

void ProcesarMouse()
{
if (DInput.Read_Mouse())
//lee con exito el mouse
{
if (DInput.Button_Down(LEFT_BUTTON))
{
//MessageBox(NULL, "mouse ", "bizq", MB_OK);
exit(0);
}
else
DInput.Get_Mouse_Coords(MX,MY);

}
}



BOOL CALLBACK DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
UINT indice;

switch (msg)
{
case WM_INITDIALOG:
SetFocus(GetDlgItem(hDlg, ID_EDIT1));
return FALSE;
case WM_COMMAND:
if(LOWORD(wParam) == IDOK)
EndDialog(hDlg, FALSE);
return TRUE;
}
return FALSE;
}



/----------------------------------
//la función de window proc callback
//se fija cosas como ESC o ALT+ENTER
//----------------------------------
LRESULT CALLBACK winProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{

static HINSTANCE hInstance;

switch(msg)
{

case WM_CREATE:
hInstance = ((LPCREATESTRUCT)lParam)->hInstance;
return 0;
break;


case WM_DESTROY:
PostQuitMessage(0);
return 0;
break;

case WM_COMMAND:
if(LOWORD(wParam) == CM_DIALOGO) //DialogExit == DIALOG
DialogBox(hInstance, "DialogExit", hwnd, DlgProc);
break;

// se presionó una tecla?
case WM_KEYDOWN:
switch(wParam)
{
//
case VK_ESCAPE:
PostQuitMessage(0);
break;
}
return 0;
break;

//se fija por ALT+ENTER para cambiar a window o fullscreen
case WM_SYSKEYDOWN:
switch(wParam)
{
case VK_RETURN:
//si se presionó hace el toggle
g_d3dwrapper.toggleFullscreen(0,0,300,400);
break;
}
return 0;
break;
}

return DefWindowProc(hwnd, msg, wParam, lParam);
}

//------------------------------
int WINAPI WinMain(HINSTANCE hinst, HINSTANCE pHinst, LPSTR cmdLine, int showCmd)
{
WNDCLASSEX wc;
MSG msg;
ZeroMemory(&msg, sizeof(MSG));

wc.cbSize = sizeof(wc);
wc.style = CS_CLASSDC;
wc.lpfnWndProc = winProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hinst;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = g_class;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

//ShowCursor(FALSE);

if(!RegisterClassEx(&wc))
return FALSE;


g_hwnd = CreateWindow(g_class, g_title, ((g_isWindowed == TRUE)? WS_OVERLAPPEDWINDOW : WS_POPUP),
0, 0, 800, 600, NULL, NULL, hinst, NULL );


if(g_hwnd == NULL)
return FALSE;

ShowWindow(g_hwnd, SW_NORMAL);
UpdateWindow(g_hwnd);

//terminamos la inicialización de la clase window

//Inicializa Direct3D
g_d3dwrapper.init(g_hwnd, g_isWindowed, TRUE, 300, 400);

//inicializa Input/////////////////////////////////
DInput.Init_ZGInput(hinst);
DInput.Init_Keyboard(g_hwnd);
DInput.Init_Mouse(g_hwnd);
///////////////////////////////////////////////////

//inicializa un cubo /////////////////////////////////////////
cubo[0] = new CUBO(g_d3dwrapper.getD3DDevice(), 0.0, .0.0, 0.0);
cubo[1] = new CUBO(g_d3dwrapper.getD3DDevice(), 0.0, .0.0, 0.0);
///////////////////////////////////////////////////////////////

//////////////////Init Imagen 2D //////////////////////////////

//primero cargamos el constructor
imagen2d = new ZGIMG2D();

//inicializa las imagenes con el device que estamos usando
if (!(imagen2d->Init(g_d3dwrapper.getD3DDevice())))
exit(0);

g_d3dwrapper.setViewport(0,0,800,600,0);

g_d3dwrapper.LookAt(0);


// game loop //
while(msg.message != WM_QUIT)
{
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{

if(g_d3dwrapper.isDeviceThere())
{
g_d3dwrapper.clear(D3DCOLOR_XRGB(0,0,0));
g_d3dwrapper.beginScene();

ProcesarKeyboard();
ProcesarMouse();

g_d3dwrapper.clear(D3DCOLOR_XRGB(50,50,50));


cubo[0]->Renderizar(MX,MY,fRotx,fRoty,g_d3dwrapper.getD3DDevice());

cubo[1]->Renderizar(0.0,0.0,fRotx,fRoty,g_d3dwrapper.getD3DDevice());


imagen2d->Procesar(MX*1.9,MY*1.9);

//restauramos el viejo viewport
// g_d3dwrapper.restoreViewport();

//deccimos a d3d que terminamos de dibujar
g_d3dwrapper.endScene();

//flip el back buffer pasa a ser el front buffer
g_d3dwrapper.flip();
}
}
}

//fin del game loop


//destuimos imagen2d //////////////
imagen2d->Destruir();
///////////////////////////////////

// destruimos d3d
g_d3dwrapper.kill();


//limpiamos nuestra clase
UnregisterClass(g_class, hinst);
return 0;
}




Ah, i think i misunderstood. Do you want to have default windows controls inside the direct3d window (buttons, dialogs) or the direct 3d window inside a dialog (not using the complete dialog)?

The first won't work easily, it's easier to use your own GUI or look at the DirectX 9.0c SDK, which has some neat GUI controls.

The second is almost the same as your code already is, but instead of calling g_d3dwrapper.init(g_hwnd, g_isWindowed, TRUE, 300, 400); in WinMain with g_hwnd you call it in WM_CREATE and use the HWND of the control. The HWND of the control can be gotten with GetDlgItem.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

i put code like you said about init d3dwrapper on WM_CREATE so :



LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static HINSTANCE hInstance;

switch (msg)
{
case WM_CREATE:
hInstance = ((LPCREATESTRUCT)lParam)->hInstance;
g_d3dwrapper.init(hwnd, g_isWindowed, TRUE, 300, 400); //here it is
return 0;
break;
case WM_COMMAND:
if(LOWORD(wParam) == CM_DIALOGO)
DialogBox(hInstance, "DIALOGOPRUEBAEXIT", hwnd, DlgProc);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}



BOOL CALLBACK DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
UINT indice;

switch (msg)
{
case WM_INITDIALOG:
SetFocus(GetDlgItem(hDlg, ID_EDIT1));
return FALSE;
case WM_COMMAND:
if(LOWORD(wParam) == IDOK)
EndDialog(hDlg, FALSE);
return TRUE;
}
return FALSE;
}




int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
HWND hwnd;
MSG mensaje;
WNDCLASSEX wincl;


wincl.hInstance = hThisInstance;
wincl.lpszClassName = "NUESTRA_CLASE";
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);


wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = "Menu";
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;

wincl.hbrBackground = GetSysColorBrush(COLOR_BACKGROUND);


if(!RegisterClassEx(&wincl)) return 0;


hwnd = CreateWindowEx(
0,
"NUESTRA_CLASE",
"Ejemplo 009",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
800,
600,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);


ShowWindow(hwnd, SW_SHOWDEFAULT);



cubo[0] = new CUBO(g_d3dwrapper.getD3DDevice(), 0.0, .0.0, 0.0);

g_d3dwrapper.clear(D3DCOLOR_XRGB(0,0,0));
g_d3dwrapper.setViewport(50,50,400,300,1);

//parametro <>1 no es el deafult
g_d3dwrapper.LookAt(0);
g_d3dwrapper.clear(D3DCOLOR_XRGB(0,0,0));



while(mensaje.message != WM_QUIT)
{
if(PeekMessage(&mensaje, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&mensaje);
DispatchMessage(&mensaje);
}
else
{

if(g_d3dwrapper.isDeviceThere())
{
g_d3dwrapper.clear(D3DCOLOR_XRGB(0,0,0));
g_d3dwrapper.beginScene();

cubo[0]->Renderizar(MX,MY,fRotx,fRoty,g_d3dwrapper.getD3DDevice());

g_d3dwrapper.endScene();

//flip el back buffer pasa a ser el front buffer
g_d3dwrapper.flip();
}
}
}


return mensaje.wParam;
}





the problem is that still didnot recognized the dialog control ("DIALOGOPRUEBAEXIT") in the callback.

///*/*/*/*/*/*//**//*/*/*/*//*/*/*//*/*/*/*//**/**/*//*//**/**/*//*//**//
//////////////////////////////
here is the main.rc and IDS.H
/////////////////////////////


////////////////////////////////////////////////////
IDS.H
/* Identificadores */

/* Identificadores de comandos */
#define CM_DIALOGO 101

/* Identificadores de diálogo */
#define ID_EDIT1 100
#define ID_EDIT2 101
///////////////////////////////////////////////////



////////////////////////////////////////////////////
main.rc


//Microsoft Developer Studio generated resource script.
//
#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#define APSTUDIO_HIDDEN_SYMBOLS
#include "windows.h"
#undef APSTUDIO_HIDDEN_SYMBOLS
#include "ids.h"

/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32

/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//

DIALOGOPRUEBAEXIT DIALOG DISCARDABLE 0, 0, 240, 120
style DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION
CAPTION "Prueba de static"
FONT 8, "Helv"
BEGIN
ICON "Icono",-1,188,47,21,20
LTEXT "Edit &1:",-1,128,73,40,9,NOT WS_GROUP
EDITTEXT ID_EDIT1,180,73,20,12
LTEXT "Edit &2:",-1,128,95,28,8,NOT WS_GROUP
EDITTEXT ID_EDIT2,180,95,20,12
PUSHBUTTON "Aceptar",IDOK,186,6,50,14,BS_CENTER
END

#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////////
// Spanish (Castilian) (unknown sub-lang: 0xB) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ESS)
#ifdef _WIN32
LANGUAGE LANG_SPANISH, 0xB
#pragma code_page(1252)
#endif //_WIN32

/////////////////////////////////////////////////////////////////////////////
//
// Menu
//

MENU MENU DISCARDABLE
BEGIN
POPUP "&File"
BEGIN
MENUITEM "&Exit", CM_DIALOGO
END
END


#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//

1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END

2 TEXTINCLUDE DISCARDABLE
BEGIN
"#define APSTUDIO_HIDDEN_SYMBOLS\r\n"
"#include ""windows.h""\r\n"
"#undef APSTUDIO_HIDDEN_SYMBOLS\r\n"
"#include ""ids.h""\r\n"
"\0"
END

3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END

#endif // APSTUDIO_INVOKED

#endif // Spanish (Castilian) (unknown sub-lang: 0xB) resources
/////////////////////////////////////////////////////////////////////////////



#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//


/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED


////////////////////////////////////////////////////////////



sorry , for now... i just cant or see the solution, i know that im newbie with control and dialog stuff, the problem is that im in a project and i need to finish the job, that is because i allways ask for help ;(



Thanks, for all. slow, but i can go on because your help ;)





Ah, i think i understand now.

You want a dialog displayed over the direct3d window. There's no special work needed for that, you could leave the wrapper.init in the WinMain then, sorry.

The second parameter for yor DialogBox call, i think it works with

DialogBox( hInstance, MAKEINTRESOURCE( DIALOGOPRUEBAEXIT ), hwnd, DlgProc );

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

This topic is closed to new replies.

Advertisement