Archived

This topic is now archived and is closed to further replies.

Doddler

Problem creating a window with DX...

Recommended Posts

I''m having some trouble creating a window with DX... The code doesn''t use really any DX, so I figured it would be best to post in this forum... anyways, heres the code... int PASCAL WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MSG msg; HRESULT hr; WNDCLASS wndClass; hr = D3DXInitialize(); if(FAILED(hr)) return 1; world = NULL; world = new World; if(!world) return 1; wndClass.style = 0; wndClass.lpfnWndProc = WindowProc; wndClass.cbClsExtra = 0; wndClass.cbWndExtra = 0; wndClass.hInstance = hInstance; wndClass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1)); wndClass.hCursor = NULL; wndClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); wndClass.lpszMenuName = NULL; wndClass.lpszClassName = APP_NAME; if(RegisterClass(&wndClass) == 0) return 1; world->hWnd = CreateWindow( APP_NAME, APP_NAME, WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, (HWND) NULL, (HMENU) NULL, hInstance, (LPVOID) NULL); ShowWindow(world->hWnd, nCmdShow); UpdateWindow(world->hWnd); if(!world->hWnd) return 1; ... and that''s where it fails... hWnd == 0, and returns 1. I can''t find out what''s wrong. If your wondering, it compiles fine, and hWnd is a member of world. I thought there was a problem with it being in the class, but I tried it otherwise and it did nothing... I''m not sure what''s wrong. If you want to see my actual code, email me and I''ll gladly send it to you. Well, thanks for your time... Doddler

Share this post


Link to post
Share on other sites
You got your parameters all screwed up, thats why!!!
Heres the prototype:
HWND CreateWindow( LPCTSTR lpClassName,
// pointer to registered class name

LPCTSTR lpWindowName,
// pointer to window name

DWORD dwStyle,
// window style

int x,
// horizontal position of window

int y,
// vertical position of window

int nWidth,
// window width

int nHeight,
// window height

HWND hWndParent,
// handle to parent or owner window

HMENU hMenu,
// handle to menu or child-window identifier

HANDLE hInstance,
// handle to application instance

LPVOID lpParam
// pointer to window-creation data

);


The first parameter is the name of the pre-defined windows class (should be WINCLASS1 in your case).
Otherwise all other parameters are fine.

Edited by - Zipster on 4/6/00 6:23:35 PM

Share this post


Link to post
Share on other sites
His parameters look the same as yours..I think, I might not be seeing something though..

What I think the problem is would be that he doesn''t fill in the cbSize field of his WNDCLASS, like this-winclass.cbSize = sizeof(WNDCLASS);

Hope you get it working.

Kaellaar.

Share this post


Link to post
Share on other sites
Um, cbSize isn't a member of WNDCLASS... I think it's a member of WNDCLASSEX, but not WNDCLASS... I'm not sure... the create window code is taken from one of the D3DX examples...

Zipster, how exactly would I be able to use WNDCLASS1? I'm pretty new to windows programming. I have been programming DX and D3D, but I only know enough windows programming to get me by.

Thanks for responding...

And once again, any help is apreciated.
-Doddler

Edited by - Doddler on 4/6/00 7:28:21 PM

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Sorry, Zipster, didn''t work either. Kaellaar, APP_NAME is defined as "Project RPG", the name of my project (for now).

I''ve got the troubling project source online at...
members.xoom.com/Doddler/Source.zip

I seriously don''t know what''s wrong... I''ve been completely stumped for about a week now... I can''t seem to put my finger on what could be preventing it from working. If you do take a look at the source, be sure to read the readme I put in there.

Anyways, I''m seriously baffled as to why it does what it does. Mabe taking a look at the source will give you a better understanding of what''s going on.

Well, thank you again for trying to help...
-Doddler

Share this post


Link to post
Share on other sites
Sorry, Zipster, didn''t work either. Kaellaar, APP_NAME is defined as "Project RPG", the name of my project (for now).

I''ve got the troubling project source online at...
members.xoom.com/Doddler/Source.zip

I seriously don''t know what''s wrong... I''ve been completely stumped for about a week now... I can''t seem to put my finger on what could be preventing it from working. If you do take a look at the source, be sure to read the readme I put in there.

Anyways, I''m seriously baffled as to why it does what it does. Mabe taking a look at the source will give you a better understanding of what''s going on.

Well, thank you again for trying to help...
-Doddler

Share this post


Link to post
Share on other sites


In your WindowProc, you are not returning the value of the DefaultWinodwProc after you call it. I bet during the window creation, this value isn''t being returned correctly so it fails (hwnd == 0).

Try:

default:
return DefWindowProc(hWnd, message, wParam, lParam);

instead and see if that solves the problem.


- HTH

Z

Share this post


Link to post
Share on other sites
Wow, Thanks! It works now, just like it''s supposed to. I didn''t even bother looking at WndProc for the problem... I suppose I don''t know enough about windows programming to know that...

Anyways, thanks to everyone for responding, you''ve all been a great help!

-Doddler

Share this post


Link to post
Share on other sites