winmain

Started by
13 comments, last by Mantrid 18 years, 5 months ago
hi all, i'm only new so sorry if this is the wrong forum or anything. but my problem is that if i build in vis.net as a release no window will open at all. it exits at the "hWnd" failure case. yet it will ok and accept input if i build as debug :( can anyone take a look at this code? i'm not getting any warnings at all :(

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

//global so visualisation class can use it
HWND hWnd;




int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
	// TODO
	// 1. Register our window class. Use IDI_CGPICON as the icon and IDI_CGPICON_SMALL as the small icon, the menu is IDC_OURMENU
	WNDCLASSEX wcex;

	wcex.cbSize = sizeof(WNDCLASSEX);
	wcex.style= CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc= (WNDPROC)WndProc;
	wcex.cbClsExtra= 0;
	wcex.cbWndExtra= 0;
	wcex.hInstance= hInstance;
	//wcex.hIcon= LoadIcon(hInstance, (LPCTSTR)IDI_ICON1);//'TT' icon
	wcex.hCursor= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground= (HBRUSH)(COLOR_WINDOW+1);
	wcex.lpszMenuName= NULL;//(LPCSTR)IDC_OURMENU;
	wcex.lpszClassName= "MainWindowClass";
	//wcex.hIconSm= LoadIcon(wcex.hInstance, (LPCTSTR)IDI_ICON1);

	RegisterClassEx(&wcex);

	// 2. Create the window using the WS_OVERLAPPEDWINDOW style

	hWnd = CreateWindow("MainWindowClass", "Audio Program", WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

	   if (!hWnd) 
        return FALSE;
	// 3. Display the window and force an initial paint


	//initialise sound+video
	gMedia.Initialise();


	ShowWindow(hWnd, nCmdShow);
	UpdateWindow(hWnd);



	// 4. Enter our program loop - this loop continues until the program exits	
	MSG msg;


	
	//BADLY BEHAVED WINDOWS PROGRAM MESSAGE CODE


	while(GetMessage(&msg, NULL, 0, 0))
	{

			TranslateMessage(&msg);
			DispatchMessage(&msg);

	}


	//return msg.wParam;		
	return 0;
}
Advertisement
The first thing to check is that all variables are manually initialised because in Release mode, unlike Debug, they are not done for you.

ace
The only real difference between that code and some of mine is that I pass HWND_DESKTOP as the hWndParent parameter of CreateWindow(). This may or may not be the issue. If it isn't, the problem could lie in your WndProc function, especially if you handle WM_CREATE and it fails. See the CreateWindow documentation from the MSDN Library.
{[JohnE, Chief Architect and Senior Programmer, Twilight Dragon Media{[+++{GCC/MinGW}+++{Code::Blocks IDE}+++{wxWidgets Cross-Platform Native UI Framework}+++
First thing, can you post your WndProc function.
Second, try calling

ShowWindow( hWnd, TRUE );

Just as a test.

Lastly, you should ZERO out your WNDCLASSEX, as some members are not initialized by you.

ZeroMemory( &wcex, sizeof(WNDCLASSEX) );

Hi.

I found two holes in your code (maybe more):
1.You did not check for the return value of RegisterClassEx ()
2.You did not specified wcex.hIcon and wcex.hIconSm. Even you dont't want to specify any icon, you must set it to NULL.

It should solve your problem. Hope this helps.
V@T

[Edit]: These guys are faster tham me :)
--> The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones <--
cheers mister anonymouse guy i'll try that


here's my wndproc, it's probably been mauled by the trial-and-error of up-all-night desperate debugging but it should more or less be there:

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){		//	int KEYPRESS;	switch (message)	{	case WM_PAINT:	 		break;	case WM_DESTROY:		PostQuitMessage(0);		break;		///DEBUG KEYS STUFF	case	WM_KEYDOWN:		{			switch(wParam)			{				case'W':				case 'w':				{					PlaySound(NULL, NULL, SND_FILENAME);				}				break;				case'S':				case 's':				{					PlaySound("test.wav", NULL, SND_FILENAME | SND_LOOP);								}				break;			case'D':			case 'd':				{					gMedia.PlayMediaFile(logo);				}				break;			case'A':			case 'a':				{					PlaySound("test2.wav", NULL, SND_FILENAME | SND_LOOP);							}				break;			}	default:		return DefWindowProc(hWnd, message, wParam, lParam);           // We do not want to handle this message so pass back to Windows		// to handle it in a default way		}	}	return 0;}
Quote:Original post by Skeleton_V@T

2.You did not specified wcex.hIcon and wcex.hIconSm. Even you dont't want to specify any icon, you must set it to NULL.

It should solve your problem. Hope this helps.
V@T

[Edit]: These guys are faster tham me :)


we have a winner! thanks very much fella, and to everyone who replied, i'll try all your other things as well so as not to tempt fate

now does anyone know why the 'w' key in wndproc won't stop the wave file from playing? :-/
Quote:Original post by Anonymous Poster

Lastly, you should ZERO out your WNDCLASSEX, as some members are not initialized by you.

ZeroMemory( &wcex, sizeof(WNDCLASSEX) );


awesome. zeroing that out seemed to solve a minor problem with mpeg-playback.. we're on a roll here!
Another hole :(
The WM_PAINT message process nothing, in this case, you can call BeginPaint () and Endpaint () functions or let Windows do this for you by not processing the message at all.
The 'w' and 'W' is working properly, I guess because your window incorrectly processes WM_PAINT message, the multimedia system has no chance to play and stop sound.

Hth
V@T
--> The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones <--
Quote:Original post by Skeleton_V@T
Another hole :(
The WM_PAINT message process nothing, in this case, you can call BeginPaint () and Endpaint () functions or let Windows do this for you by not processing the message at all.
The 'w' and 'W' is working properly, I guess because your window incorrectly processes WM_PAINT message, the multimedia system has no chance to play and stop sound.

Hth
V@T

yeah i had of game-specific direct x calls in there which i remvoed for this demo so i can make it more black-boxy. commenting out wm_paint still doesn't let 'w' reach anything.

actually since you mention that i'll set up a breakpoint now to make sur eit's reach (i havent slept for a day or two, sorry!)

This topic is closed to new replies.

Advertisement