CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Threaded View

  1. #1
    Join Date
    Nov 2008
    Posts
    19

    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, &center, &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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured