Thread: Can't get window to show

  1. #1
    Registered User
    Join Date
    Sep 2008

    Can't get window to show

    So I've looked through everything and with a tutorial for DirectX9 I'm doing, and I for the life of me cannot find out what's wrong with the code here:
    /*            CRYSTAL BOND          */
    /*************            ***********/
    /*       DirectX game built by      */
    /**     Glitch Softwares Studios   **/
    //Include important files
    #include <windows.h>
    #include <windowsx.h>
    #include <d3d9.h>
    #include "functions.h"
    //Include Direct3D Library
    #pragma comment (lib, "d3d9.lib")
    //Include files specifically for this game
    #include "functions.h"
    //Prototype of CALLBACK
    LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
    // the entry point for any Windows program
    int WINAPI WinMain(HINSTANCE hInstance,
                       HINSTANCE hPrevInstance,
                       LPSTR lpCmdLine,
                       int nCmdShow)
    	HWND hWnd;
    		//Clear windows for use
    	ZeroMemory(&wc, sizeof(WNDCLASSEX));
    	//Build structure with information
    	wc.cbSize = sizeof(WNDCLASSEX); = CS_HREDRAW | CS_VREDRAW;
    	wc.lpfnWndProc = WindowProc;
        wc.hInstance = hInstance;
        wc.hCursor = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
        wc.lpszClassName = L"WindowClass";
    	//Make the Windows Program
    	hWnd = CreateWindowEx(NULL,
    						L"WindowClass",				//Class name
    						L"Crystal Bond",			//Window Caption
    						WS_OVERLAPPEDWINDOW,		//Style
    						5,							//X Start
    						5,							//Y Start
    						645,						//Width
    						485,						//Height
    						NULL,					//Parent Window
    						NULL,					//Menus
    						hInstance,				//Application handle
    						NULL);					//Use with multiple windows
    	//Make window visible
    	ShowWindow(hWnd, nCmdShow);
    	MSG resp;	//Create the structure to communicate the user input
    		TranslateMessage(&resp);	//Translate input to machine's language
    		DispatchMessage(&resp);		//Send message to be processed.
    	return resp.wParam;
    		// Check to see if any messages are waiting in the queue
    		while(PeekMessage(&resp, NULL, 0, 0, PM_REMOVE))
    			// Translate the message and dispatch it to WindowProc()
    		// If the message is WM_QUIT, exit the while loop
    		if(resp.message == WM_QUIT)
    							UINT message,
    							WPARAM wParam,
    							LPARAM lParam)
    	//Look for what to do at message recieved
    		//Message says: Close the program and window
    	case WM_DESTROY:
    		{PostQuitMessage(0);return 0;break;}
    	//Else, and nothing was supported in SWITCH
    	return DefWindowProc(hWnd, message, wParam, lParam);
    It's not the functions and the lack of certain pointers and things, as their defined in the other headers in "functions.h", I just KNOW it's in main.cpp here, it's GOTTA be.
    So this code is compiled under Visual C++ 2008 Express Edition, and it compiles and works fine, but for some reason it doesn't show the window, but the program is running. However I've checked the line saying:
    	//Make window visible
    	ShowWindow(hWnd, nCmdShow);
    And yet it still won't work, I'm pretty sure I did everything right, if anyone wants the other header files:

    #ifndef _FUNCTIONS_H_
    #define _FUNCTIONS_H_
    //Global declarations
    LPDIRECT3D9 d3d;
    #include "prototypes.h"
    #include "dxfunctions.h"
    #ifndef _PROTOTYPES_H_
    #define _PROTOTYPES_H_
    void initD3D(HWND hWnd);
    // initilize DirectX
    void renderFrame(void);
    // renders one (1) frame
    void cleanD3D(void);
    // when the game ends, this will be called to clear everything
    #ifndef _DXFUNCTIONS_H_
    #define _DXFUNCTIONS_H_
    //                             Initilize Direct3D
    void initD3D(HWND hWnd)
    	d3d=Direct3DCreate9(D3D_SDK_VERSION);		//Create the D3D interface
    	D3DPRESENT_PARAMETERS d3dpp;	//Structure for holding device information
    	ZeroMemory(&d3dpp,sizeof(d3dpp));	//Erase STRUCT for usability
    	d3dpp.Windowed = true;		// NOT Fullscreen
    	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;	//Erase old frames
    	d3dpp.hDeviceWindow = hWnd;		//Makes the window compatible with D3D
    	//Make the Direct3D class, using structure info above
    //                             Make new frame
    void renderFrame(void)
    	//Clear screen to color BLUE
    	d3ddev->BeginScene();	//Begin the 3D image render
    	//Render here
    	d3ddev->EndScene();		//End the 3D image render
    	//Display the rendered frame
    //                             Clear the DirectX engine and COM
    void cleanD3D(void)
    Thanks for the help, I suspect this was to go in either Windows Programming or Game Programming in DirectX, but I wasn't sure, so move if appropriate.

  2. #2
    Student legit's Avatar
    Join Date
    Aug 2008
    UK -> Newcastle
    Hey there, what errors do you get when you compile the program? The first one I spotted is that you haven't included prototype.h in dxfunctions.h. It's also frowned upon to define your functions in header files, as you have done in dxfunctions.h, unless things have changed while I've been away

  3. #3
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    RING 0
    You haven't really said what's wrong except it doesn't work. Is it compiling, is the window showing and DX not drawing, is the window showing and not being repainted, is the application failing to start?

    First thing, you usually call UpdateWindow() after a ShowWindow to force a repaint. Also you are blocked in the GetMessage() loop until WM_QUIT is encountered, only then will your DX loop start, again until a WM_QUIT.

    First thing I'd work on is getting your window to show. To do that check the return paramaters of your calls and make sure they are succeeding, or step through it with a debugger. If you are stumped on something then post that problem. After that I'd make the change to the message loop that I mentioned above, and start working on getting the DX portion working. Your first matter on that would be ensuring the Device is created successfully.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 02:33 PM
  2. my wndProc is out of scope
    By Raison in forum Windows Programming
    Replies: 35
    Last Post: 06-25-2004, 07:23 AM
  3. Window won't show
    By Toraton in forum Windows Programming
    Replies: 4
    Last Post: 11-10-2002, 08:07 PM
  4. run a program
    By goodmonkie in forum Windows Programming
    Replies: 2
    Last Post: 10-07-2001, 11:19 AM
  5. Invoking MSWord
    By Donn in forum C Programming
    Replies: 21
    Last Post: 09-08-2001, 04:08 PM