Public Group

# Making a console window go fullscreen automatically

This topic is 4864 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Another noob post coming up ;-), I'm trying to get a simple console window to automatically go full-screen when the program starts to run, instead of having to press alt-enter. Is it possible to do this using any type of code, and how would I go about doing it? It's just a standard Console app, no Win32 or anything fancy. I'm coding it on Win2K if that helps. Thanks for your help, ukdeveloper.

##### Share on other sites
Not sure if you can change it from within your code. Seems unlikely to me. Anyway you can set the default display mode for cmd.exe from the Defaults option in the system menu of the console window. Might be able to set it with a flag to cmd.exe. I didn't find any using "cmd /?" but perhaps there is some other way.

Good luck.

##### Share on other sites
Quote:
 Original post by staafGood luck.

Thanks!

##### Share on other sites
You can programmatically locate the CMD process and get the HWND and use that to set it to full screen by sending a WM_ message to it.

##### Share on other sites
Or you could just make a shortcut to your program with the full screen display option selected. I believe this is something that an install program can also do quite easily.

##### Share on other sites
This code will do it, though it does use some win32 stuff. If you have any questions, ask away!
// Auto-fullscreen routine for console windows by Nathan Dunn, 2005// Include stuff for manipulating windows #include <windows.h>// The length of our buffer to hold the window title#define CONSOLE_TITLE_LENGTH 200// Entry pointint main(){	// Buffer to hold the original title	char szOldConsoleTitle[CONSOLE_TITLE_LENGTH] = {0};	// The new title of the window. I used random 	// numbers/letters to make it as unique as I can	char szNewConsoleTitle[CONSOLE_TITLE_LENGTH] = "fd3739j531kse43p";	// First, we get the title of the console window.	// We store it in the old title string so that we can put it	// back later on. Right now, we want a totally unique title.	GetConsoleTitle(szOldConsoleTitle, CONSOLE_TITLE_LENGTH);	// This sets the window to the unique title.	SetConsoleTitle(szNewConsoleTitle);	// Chill for a moment to make sure the title is updated.	Sleep(40);	// Now we can grab the handle to the window by trying to	// find it using the unique name we have assigned it.	HWND hConsoleWnd = FindWindow(NULL, szNewConsoleTitle);	// Make sure we have the handle to the window. If we don't,	// back away slowly.	if (!hConsoleWnd)	{		MessageBox(NULL, "Window Handle Not Found!", "Error", MB_OK);		return -1;	}	// Return the title of the window to its original title.	SetConsoleTitle(szOldConsoleTitle);	// Now we send the ALT+ENTER message to the window. We	// send SendMessage the handle to the window, the message	// that we are pressing the ALT key and another key, that	// that other key is the ENTER key, and verification that	// the ALT key is indeed down. The window receives this and	// says "Oh, hey! I need to go fullscreen! Well, let's do it	// then." All that is handled by the console window itself,	// and you don't have to worry about it.	SendMessage(hConsoleWnd, WM_SYSKEYDOWN, VK_RETURN, 1<<29);		// Now we say things are cool, and return normally.	return 0;}

[Edited by - N8dunn on April 25, 2005 7:07:21 PM]

##### Share on other sites
SetConsoleDisplayMode() is even easier ...

##### Share on other sites
Quote:
 Original post by MarteeSetConsoleDisplayMode() is even easier ...

...or would be if i could figure out how to get it to be defined. according to my local msdn (that was installed with VS) it doesnt exist, but the online one lists it. possibly a .net framework 2 beta thing? or is there an updated windows sdk?

##### Share on other sites
It's probably in the most recent version of the Platform SDK. Alternately, you can define it yourself:

typedef BOOL (WINAPI *SetConsoleDisplayModeProc) (HANDLE, DWORD, PCOORD);

.. or something like that.

##### Share on other sites
According to:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/setconsoledisplaymode.asp

It required Windows XP. So if you intend on supporting Windows operating systems becides XP then it will not work. As for it not being defined, it is probably related. You probably hae to define some constant to enable XP only APIs. I can't remember what it is off teh top of my head though.

1. 1
2. 2
3. 3
JoeJ
12
4. 4
5. 5

• 12
• 16
• 13
• 20
• 12
• ### Forum Statistics

• Total Topics
632176
• Total Posts
3004588

×