-
February 16th, 2009, 07:51 PM
#1
Child window problems
I have a program that im working on that's supposed to have a main window, then another window load up off of that.
It has both the main window, then the child window load up.
the main window is fine, it refreshes as it is supposed to.
the client window will move around fine, but the client area gets painted once, and doesn't repaint after that.
the program uses some basic directx
main.cpp
Code:
int WINAPI WinMain( HINSTANCE hInstance, // handle to application
HINSTANCE hPrevInstance,
LPSTR lpCmdLine, // cmd line arguments (pointer to null terminated string)
int nCmdShow) // flag for how window will be shown.. see msdn for flags
{
d3d = Direct3DCreate9(D3D_SDK_VERSION); // create the Direct3D interface
// Client main wnd initialization
HWND hWndMain;
HWND hWndLogin;
WNDCLASSEX cClientWindow;
ZeroMemory(&cClientWindow, sizeof(WNDCLASSEX));
cClientWindow.cbSize = sizeof(WNDCLASSEX);
cClientWindow.style = CS_BYTEALIGNCLIENT | CS_HREDRAW | CS_VREDRAW;
cClientWindow.lpfnWndProc = (WNDPROC)WindowProc;
cClientWindow.hInstance = hInstance;
cClientWindow.hCursor = LoadCursor(NULL, IDC_ARROW);
cClientWindow.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
cClientWindow.lpszClassName = L"Client";
RegisterClassEx(&cClientWindow);
hWndMain = CreateWindowEx(NULL,
L"Client", // name of the window class
L"Main Window", // title of the window
WS_CLIPCHILDREN|WS_OVERLAPPED|WS_CAPTION|WS_MINIMIZEBOX|WS_SYSMENU|WS_EX_LAYERED, // window style.. dont allow resizing
0, // x-position of the window
0, // y-position of the window
CLIENTWIDTH, // width of the window
CLIENTHEIGHT, // height of the window
NULL, // parent window
NULL, // menus
hInstance,// application handle
NULL); // multiple windows?
D3DPRESENT_PARAMETERS d3dpp; // create a struct to hold various device information
ZeroMemory(&d3dpp, sizeof(d3dpp)); // clear out the struct for use
d3dpp.Windowed = TRUE; // program windowed, not fullscreen
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; // discard old frames
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dpp.hDeviceWindow = hWndMain; // set the window to be used by Direct3D
// create a device class using this information and the info from the d3dpp stuct
d3d->CreateDevice(D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
hWndMain,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
&d3ddev);
D3DXCreateSprite(d3ddev, &d3dspt); // create the Direct3D Sprite object
D3DXCreateTextureFromFileEx(d3ddev, // the device pointer
L"LoginBackground.bmp", // the new file name
D3DX_DEFAULT, // default width
D3DX_DEFAULT, // default height
D3DX_DEFAULT, // no mip mapping
NULL, // regular usage
D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
D3DPOOL_MANAGED, // typical memory handling
D3DX_DEFAULT, // no filtering
D3DX_DEFAULT, // no mip filtering
D3DCOLOR_XRGB(255, 0, 255), // the hot-pink color key
NULL, // no image info struct
NULL, // not using 256 colors
&sprite); // load to sprite
// child window
WNDCLASSEX cClientLogin;
ZeroMemory(&cClientLogin, sizeof(WNDCLASSEX));
cClientLogin.cbSize = sizeof(WNDCLASSEX);
cClientLogin.style = CS_HREDRAW | CS_VREDRAW;
cClientLogin.lpfnWndProc = (WNDPROC)WindowProc;
cClientLogin.hInstance = hInstance;
cClientLogin.hCursor = LoadCursor(NULL, IDC_ARROW);
cClientLogin.hbrBackground = NULL;
cClientLogin.lpszClassName = L"Child Window";
RegisterClassEx(&cClientLogin);
hWndLogin = CreateWindowEx(NULL,
L"Child Window", // name of the window class
L"Child window", // title of the window
WS_CHILD|WS_OVERLAPPED|WS_CAPTION,
(CLIENTWIDTH/2-LOGINWIDTH/2), // x-position of the window
(CLIENTWIDTH/2-LOGINHEIGHT), // y-position of the window
LOGINWIDTH, // width of the window
LOGINHEIGHT, // height of the window
hWndMain, // parent window
NULL, // menus
hInstance,// application handle
NULL); // multiple windows?
D3DPRESENT_PARAMETERS d3dppLogin; // create a struct to hold various device information
ZeroMemory(&d3dppLogin, sizeof(d3dppLogin)); // clear out the struct for use
d3dppLogin.Windowed = TRUE; // program windowed, not fullscreen
d3dppLogin.SwapEffect = D3DSWAPEFFECT_DISCARD; // discard old frames
d3dppLogin.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dppLogin.hDeviceWindow = hWndLogin; // set the window to be used by Direct3D
// create a device class using this information and the info from the d3dpp stuct
d3d->CreateDevice(D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
hWndLogin,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
&d3ddevLogin);
ShowWindow(hWndMain, nCmdShow);
ShowWindow(hWndLogin, nCmdShow);
// this struct holds Windows event messages
MSG msg;
// wait for the next message in the queue, store the result in 'msg'
while(true)
{
DWORD startTime = GetTickCount();
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
// If the message is WM_QUIT, exit the while loop
if (msg.message == WM_QUIT)
{break;}
// translate keystroke messages into the right format
TranslateMessage(&msg);
// send the message to the WindowProc function
DispatchMessage(&msg);
}
while ((GetTickCount() - startTime) <25);
}
cleanD3D();
// return this part of the WM_QUIT message to Windows
return msg.wParam;
}
include.h
Code:
/*
Include in all cpp files
*/
#define LEAN_AND_MEAN
#include <Windows.h>
#include <d3d9.h>
#include <d3dx9.h>
// include the Direct3D Library file
#pragma comment (lib, "d3d9.lib")
#pragma comment (lib, "d3dx9.lib")
#include "initialize.h"
#include "loop.h"
#include "cleanup.h"
initialize.h
Code:
#define CLIENTWIDTH 1000
#define CLIENTHEIGHT 750
#define LOGINWIDTH 400
#define LOGINHEIGHT 300
#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEY_UP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)
// global declarations
LPDIRECT3D9 d3d; // the pointer to our Direct3D interface
LPDIRECT3DDEVICE9 d3ddev; // the pointer to the device class
LPDIRECT3DDEVICE9 d3ddevLogin;
LPD3DXSPRITE d3dspt; // the pointer to our Direct3D Sprite interface
// sprite declarations
LPDIRECT3DTEXTURE9 sprite; // the pointer to the sprite
loop.h
Code:
// the WindowProc function prototype
LRESULT CALLBACK WindowProc(HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam);
void render_frame(void); // renders a single frame
// this is the main message handler for the program
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
// sort through and find what code to run for the message given
switch(message)
{
// this message is read when the window is closed
case WM_DESTROY:
{
// close the application entirely
PostQuitMessage(0);
return 0;
}
case WM_PAINT:
{
render_frame();
break;
}
}
// Handle any messages the switch statement didn't
return DefWindowProc (hWnd, message, wParam, lParam);
}
// this is the function used to render a single frame
void render_frame(void)
{
// clear the window to a deep blue
d3ddev->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_ARGB(0,0,0,0),1.0f,0);
d3ddev->BeginScene();
d3ddevLogin->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_ARGB(255,255,255,255),1.0f,0);
d3ddev->EndScene();
d3ddev->BeginScene(); // begins the 3D scene
d3dspt->Begin(D3DXSPRITE_ALPHABLEND); // begin sprite drawing
// draw the sprite
D3DXVECTOR3 center(0.0f, 0.0f, 0.0f); // center at the upper-left corner
D3DXVECTOR3 position(0.0f, 0.0f, 1.0f); // position at 50, 50 with no depth
d3dspt->Draw(sprite, NULL, ¢er, &position, D3DCOLOR_ARGB(255,255, 255, 255));
d3dspt->End(); // end sprite drawing
d3ddev->EndScene(); // ends the 3D scene
d3ddev->Present(NULL, NULL, NULL, NULL); // displays the created frame on the screen
return;
}
cleanup.h
Code:
void cleanD3D(void); // closes Direct3D and releases memory
// this is the function that cleans up Direct3D and COM
void cleanD3D(void)
{
d3ddev->Release(); // close and release the 3D device
d3ddevLogin->Release();
d3d->Release(); // close and release Direct3D
return;
}
EDIT:
Ive decided to pick up acouple of books and just read, the msdn library isnt a very good place to learn.
thanks for the help, please let this topic just die out.
Last edited by Flipsy; February 17th, 2009 at 02:37 AM.
-
February 16th, 2009, 08:37 PM
#2
Re: Child window problems
Yes the main.cpp is not really main.cpp because it is clearly a pure windows native application with only the new coat on the same body. bhahahah
Definition of L"string" and _T("String") or TEXT("String") is also different
Thanks
-
February 16th, 2009, 09:05 PM
#3
Re: Child window problems
im sory im not really understanding what you are saying.
Yes the main.cpp is not really main.cpp because it is clearly a pure windows native application with only the new coat on the same body
main.cpp is just a name, it dosent matter weather its an empty project, console , or win32 application.. main.cpp just means its the name i gave the cpp, telling me thats where the main function is. it dosetn need to be called WinMain.cpp for WinMain() to work...
Definition of L"string" and _T("String") or TEXT("String") is also different
I had to use L"String" because thats what the function asked of me, or else i wouldnt have.. i dont know what that has to do with the problem im having.
-
February 16th, 2009, 09:12 PM
#4
Re: Child window problems
Actually just use whatever you like, either L"" or TEXT("") works just fine for your application
-
February 16th, 2009, 09:20 PM
#5
Re: Child window problems
You must have spent some time attaching code snippets.
It would have been mutually beneficial (for you and responders) if you attached zipped project.
In my case (and I think many of us) we do not have time to piece all snippets together in order to debug your code and give you an intelligent answer.
There are only 10 types of people in the world:
Those who understand binary and those who do not.
-
February 16th, 2009, 09:23 PM
#6
Re: Child window problems
Originally Posted by JohnCz
You must have spent some time attaching code snippets.
It would have been mutually beneficial (for you and responders) if you attached zipped project.
In my case (and I think many of us) we do not have time to piece all snippets together in order to debug your code and give you an intelligent answer.
Yes, I agree with JohnCz, you can send it via my email or my home address, can't you ?
This won't take your time actually
Another way is to contact directly via phone for somewhere to debate (if we live in the same region) on a day off, ie weekends
-
February 16th, 2009, 09:38 PM
#7
Re: Child window problems
Originally Posted by ChayKieu
Yes, I agree with JohnCz, you can send it via my email or my home address, can't you . . .
Anything is possible; However, attaching compressed project to a post is most efficient way of getting response.
This way many people can participate in discussion, and present different approach to solving a problem.
There are only 10 types of people in the world:
Those who understand binary and those who do not.
-
February 16th, 2009, 09:44 PM
#8
Re: Child window problems
Yes, I agree there are alot of people on codeguru who I think will love to read and disgcust
-
February 16th, 2009, 09:49 PM
#9
Re: Child window problems
If you want to use two different windows with both having the DirectX rendering loop, you will need to use the Swap Chains. Google for it, you will find lot of examples...
-
February 16th, 2009, 11:08 PM
#10
Re: Child window problems
Originally Posted by streamer
If you want to use two different windows with both having the DirectX rendering loop, you will need to use the Swap Chains. Google for it, you will find lot of examples...
thanks for the response streamer,
i did read up on these swap chains, but i also read up on using different devices rather than swap chains.. so i got kinda confused and thought that initializing and using two different devices might be easier.
-
February 17th, 2009, 06:43 AM
#11
Re: Child window problems
Originally Posted by Flipsy
thanks for the response streamer,
i did read up on these swap chains, but i also read up on using different devices rather than swap chains.. so i got kinda confused and thought that initializing and using two different devices might be easier.
Handling two d3d devices is a much more work to handle than swap chains. Example:
So you have one windowed application, and you think you don' t need to handle lost device, when user switch from fullscreen to windowed mode with alt-tab or similar, because your application is not full screen . Wrong.
Just change resolution of the desktop window to something different and ta-da, your program crashes. You need to handle lost device. And ops but you have two devices opened...so you need to handle two devices separately. Also when you load some texture, texture is bound to device. If you have two device and you want to some textures be used by both of devices you need to load them for every device you have, meaning you are losing memory because of bad design etc etc. You will have every problem doubled.
Swap chains use the same device, and it's a small amount of work to add them.
If I understood well from your code, you're using second window as login page? Not so good design, I think so.
One use of more screens - swap chains is for example 3DMAx screen. Did you see that?
They use 4 views, left , top , front and perspective to show one scene. But is rendered on one window.
Its easier to use swap chains, than only one screen. Why? You have only one scene shown from different points of view. Shown scene uses the same scene, only cameras are on different position. They just move cameras render to swap chain and everything is working.
-
February 17th, 2009, 11:45 AM
#12
Re: Child window problems
alright, i think i understand now why i want to use swap chains, im reading up on them, thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|