"WinMain"

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
mepatuhoo
Posts: 42
Joined: Mon Dec 19, 2005 2:16 am

"WinMain"

Post by mepatuhoo »

how do is use WinMain to hide the text at the begining i want only the game gui to show. i see that in the first tutorial it seas somthing about "WinMain" and that it will hide it but how do i use it to hide it?
Conquistador
Posts: 340
Joined: Wed Sep 28, 2005 4:38 pm
Location: Canada, Eh!

Post by Conquistador »

WinMain is as follows:

Code: Select all

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
    LPSTR lpCmdLine, int nCmdShow)
{

}
Remember to include windows.h
Royal Hamilton Light Infantry - http://www.rhli.ca
Paris/Port Dover Pipes'n Drums - http://www.parisdover.ca
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

You also have to change your linker settings so that the SUBSYSTEMTYPE is WINDOWS not CONSOLE
Image
mepatuhoo
Posts: 42
Joined: Mon Dec 19, 2005 2:16 am

Post by mepatuhoo »

i tryed the code you posted and i got the following errors
Project\main.cpp #include expects "FILENAME" or <FILENAME>
Project\main.cpp `WINAPI' does not name a type
Project\Makefile.win [Build Error] [main.o] Error 1

what am i doing thats making the errors?
Xaron
Posts: 310
Joined: Sun Oct 16, 2005 7:39 am
Location: Germany
Contact:

Post by Xaron »

mepatuhoo wrote:Project\main.cpp #include expects "FILENAME" or <FILENAME>
OMG... did you try

Code: Select all

#include windows.h
instead of

Code: Select all

#include <windows.h>
?

Regards - Xaron
genesisrage
Posts: 93
Joined: Tue Feb 08, 2005 12:19 pm

Post by genesisrage »

there is another way to hide the console window. its a bit controversial for some reason?!?

but this is what i use, and got it from the msdn website.

Code: Select all

#pragma comment(linker, "/subsystem:windows /entry:main")
it works like a charm and no need to include any headers what so ever. the way it works it changes the system to windows (and uses winmain by default), then with "/entry:main" it tells the linker to use main() instead of winmain().
Xaron
Posts: 310
Joined: Sun Oct 16, 2005 7:39 am
Location: Germany
Contact:

Post by Xaron »

Thanks for that, genesisrage! :)

Regards - Xaron
per4manz

Post by per4manz »

I just use a define to tie into whether I am compiling in DEBUG or RELEASE modes in VisualStudio. It's then "automatic" and I get the best of both worlds:

Code: Select all

#ifdef _DEBUG
int main()
#else
INT WINAPI WinMain(HINSTANCE hInst,HINSTANCE,LPSTR strCmdLine,INT)
#endif
{
	HANDLE ExistingGameMutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, "uniquegamenamehere"); 
	
	if(ExistingGameMutex) // Check to see if the game is currently running
	{
		CloseHandle(ExistingGameMutex);
		MessageBox(NULL, "\nPlease click OK to close this information box. Click on the running game in the task bar", "Game Already Running", MB_OK);
		return -1;
	}
	else
	{
		CreateMutex(NULL,0,"uniquegamenamehere");
		CloseHandle(ExistingGameMutex);
	}

..blah .. rest of (win)main code here as you need

}
Note the additional mutex code which is nothing to do with the methods mentioned but as I just cut and pasted from my project I thought I'd leave that in (it may be useful for someone) - basically it prevents you launching 2 or more versions of the same game at once (single instance). This is a good thing to do in case a user gets impatient and double clicks your icon 20 times or something ;)

rgds
mepatuhoo
Posts: 42
Joined: Mon Dec 19, 2005 2:16 am

Post by mepatuhoo »

i just tryed all of them out and there all still showing the box what am i doing incorectly? :?
genesisrage
Posts: 93
Joined: Tue Feb 08, 2005 12:19 pm

Post by genesisrage »

@mepatuhoo
depends on the ide you are using. as in my example above Code::Blocks still shows the console window when executed through the ide, but when running the .exe file itself it does not show up.
mepatuhoo
Posts: 42
Joined: Mon Dec 19, 2005 2:16 am

Post by mepatuhoo »

genesisrage wrote:@mepatuhoo
depends on the ide you are using. as in my example above Code::Blocks still shows the console window when executed through the ide, but when running the .exe file itself it does not show up.
i basicly copyed the interface tutorial and then edited it so most of the programing i have just modifyed. i tryed the exe and its still showing the box.
genesisrage
Posts: 93
Joined: Tue Feb 08, 2005 12:19 pm

Post by genesisrage »

think the only way we can really help you out now, is some code. using the interface demo (with the default winMain() function) should not show a console window, neither putting my example at the top of your main code file.
It might be something else, but have no idea without seeing some code.
mepatuhoo
Posts: 42
Joined: Mon Dec 19, 2005 2:16 am

Post by mepatuhoo »

what part of the code do you need to figer it out. ill send you the main funtion. i gess thats where is would need to be fixed

int main()
{

video::E_DRIVER_TYPE driverType;

// printf("Please select the driver you want for this example:\n"\
// " (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.5\n"\
// " (d) Software Renderer\n (e) Apfelbaum Software Renderer\n"\
// " (f) NullDevice\n (otherKey) exit\n\n");

char i;
// std::cin >> i;
i='c';
switch(i)
{
case 'a': driverType = video::EDT_DIRECT3D9;break;
case 'b': driverType = video::EDT_DIRECT3D8;break;
case 'c': driverType = video::EDT_OPENGL; break;
case 'd': driverType = video::EDT_SOFTWARE; break;
case 'e': driverType = video::EDT_SOFTWARE2;break;
case 'f': driverType = video::EDT_NULL; break;
default: return 1;



}

// create device and exit if creation failed

device = createDevice(driverType, core::dimension2d<s32>(640, 480));
// device = createDevice(driverType, core::dimension2d<s32>(640, 480));

if (device == 0)
return 1; // could not create selected driver.

/* The creation was successful, now we set the event receiver and
store pointers to the driver and to the gui environment. */

MyEventReceiver receiver;
arfgh
Posts: 104
Joined: Sat Aug 26, 2006 6:15 am

Post by arfgh »

tried all that forms you told and not got success.

#include <windows.h>
#pragma comment(linker, "/subsystem:windows /entry:main")
#pragma comment(lib, "Irrlicht.lib")
extern int main (int argc, char **argv) {
blabla...
}

i use visual studio c++ 6.0 and my irrlicht is irrlicht-0.10.0
I compiled as "win32 application" and not as usual "win32 console aplication"
when i execute the program "xxx.exe got a problem and must to close"

can someone help me to hide that cmd console ?
Ico
Posts: 289
Joined: Tue Aug 22, 2006 11:35 pm

Post by Ico »

That "extern" shouldn't be there. ;)
Post Reply