Solved

set a console window to full screen

Posted on 1998-10-05
17
348 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

929 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now