Solved

set a console window to full screen

Posted on 1998-10-05
17
349 Views
Last Modified: 2013-12-03
In Win32, how do I change a console application's
window to full screen? i.e. the equivalent of pressing
Alt + Enter.

I'm programming in Delphi if that makes a difference.

Thanks
Deryck Brown
0
Comment
Question by:deryckb
  • 5
  • 3
  • 3
  • +5
17 Comments
 
LVL 20

Expert Comment

by:Madshi
ID: 1414985
Have you tried simulating the keys with keybd_event?
That should work, but the console application must have the keyboard focus.

Regards, Madshi.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1414986
You need to get the handle to the console window.  The only way to do this that I've seen is with FindWindow() (but there may be a better way)
Then use SetWindowPos() on the console window handle.

Ask if you have questions.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1414987
Opps.  I missunderstood you.  I thought you meant maximized, but you really do mean full screen.  You can't do that the way I suggested, sorry.   Madshi, idea might be the best you can do, but it does require that the console window have the focus.  You can change the console window to have the focus with SetForegroundWindow()   Note that this always works under win95 and Win NT 4.0.  Supposidly, however, this function no longer gives another application the focus in Windows 98.  However, the console can still make itself the foreground window in windows 98.  

Sorry, reject my answer.
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

by:deryckb
ID: 1414988
Misunderstood the question.

Additional comment entered.
0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1414989
So..... Any luck with Madshi's solution?
0
 

Author Comment

by:deryckb
ID: 1414990
I haven't had a chance to try it yet. The HD on my PC
died over the weekend. I came in on Monday and got clunk, clunk,
clunk, clunk,....

I hope to get back to it today or possibly tomorrow.

Many thanks for the suggestions so far!

0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1414991
I know the answer for NT. Its undocumented API call to SetConsoleDisplayMode.
To find it, I've wasted about two hours today.
If you are interesting in it, I'll give you it for grade A and 200 points .

Answer for 95 differs from NT one because there is no SetConsoleDisplayMode in 95. It'll cost more (I don't know the answer yet).
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1414992
How about this???

ShowWindow(TheAppHandle, SW_MAXIMIZED);

Regards,
Viktor Ivanov
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1414993
See my prev comment. There is an answer for W95/98 also. Undocumented, of course.
0
 

Author Comment

by:deryckb
ID: 1414994
OK, I've raised the ante to 200 points. Spill the beans! :-)

Deryck
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1414995
Here is some sample code.
It is function  0463  of kernel32.dll

#include <windows.h>

WINBASEAPI
BOOL
WINAPI
GetConsoleDisplayMode(
    LPDWORD dwConsoleDisplayMode
    );

WINBASEAPI
DWORD
WINAPI
SetConsoleDisplayMode(
    HANDLE hConsoleHandle,
    DWORD dwConsoleDisplayMode,
    LPDWORD dwPreviousDisplayMode
    );

void main(void)
{
      HANDLE      hConsole;
      DWORD            Result;

      AllocConsole();
      hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
      SetConsoleDisplayMode(hConsole, 1, &Result);
};


0
 
LVL 2

Expert Comment

by:avico
ID: 1414996
Have you considered using MAC address ?
0
 
LVL 2

Expert Comment

by:avico
ID: 1414997
Sorry, erase my last comment....
0
 
LVL 22

Expert Comment

by:nietod
ID: 1414998
Mirkwood, I believe that was proposed by NickRepin.
0
 

Author Comment

by:deryckb
ID: 1414999
Mirkwood,

Yes your solution works, but NickRepin proposed this solution first. Therefore, in the interests of fairness, I am "rejecting" your solution to give the points to him.

Sorry!

Deryck
0
 
LVL 15

Accepted Solution

by:
NickRepin earned 200 total points
ID: 1415000
Mirkwood was the first, but it seems it's only part of the answer. There is no SetConsoleDisplayMode in Win95 (if I am not wrong).

By the way, in my NT the 0463 in KERNEL32 is GetThreadContext, in Win98 - ReadConsoleInputW.

Here is the sample for Win95/98

#include <windows.h>
#include <conio.h>

void main(void) {
   // Find our console window (may be any other code here)
   char con[120];
   GetConsoleTitle(con,sizeof(con));
   HWND w=FindWindow("tty",con);

   cprintf("Test");
   getch(); // Not necessary - just to test

   // Set full screen mode
   SendMessage(w,WM_COMMAND,57359,0);

   getch(); // Not necessary - just to test
}


0
 

Author Comment

by:deryckb
ID: 1415001
The Windows NT solution worked for me, but a very big thanks for the 95/98 version too.

I guess alot of people were looking for this information too.

Deryck
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question