Making a console window go fullscreen automatically

Started by
8 comments, last by cilcoder 18 years, 11 months ago
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.
Advertisement
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.
Hack my projects! Oh Yeah! Use an SVN client to check them out.BlockStacker
Quote:Original post by staaf
Good luck.


Thanks!
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.

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.
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]
SetConsoleDisplayMode() is even easier ...
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
Quote:Original post by Martee
SetConsoleDisplayMode() 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?
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);

HMODULE dll = LoadLibrary("kernel32.dll");
SetConsoleDisplayModeProc SetConsoleDisplayMode = (SetConsoleDisplayModeProc)GetProcAddress(dll, "SetConsoleDisplayMode");


.. or something like that.
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
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.

This topic is closed to new replies.

Advertisement