Solved

Closing full screen dos application from windows

Posted on 1999-01-12
26
218 Views
Last Modified: 2013-12-03
I have a dos application that's running full screen under windows 98.
Now I want in my Visual Basic program to switch back to windows 98, minimize the dos application and give focus to my Visual Basic program.
Can this be done ?
0
Comment
Question by:lermytte
  • 11
  • 8
  • 6
  • +1
26 Comments
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1418586
Yes, I can be done. But is not easy. What is your knowledge about windows API's and SendMessage.
0
 

Author Comment

by:lermytte
ID: 1418587
I have general knowledge and a book about api calls from VB.
I tried already a lot of stuff but once the doswindow is fullscreen you can't even close it anymore with SendMessage. If someone has an example you can mail it to rama@skynet.be

Thanks
0
 

Author Comment

by:lermytte
ID: 1418588
I have general knowledge and a book about api calls from VB.
I tried already a lot of stuff but once the doswindow is fullscreen you can't even close it anymore with SendMessage. If someone has an example you can mail it to rama@skynet.be

Thanks
0
 

Author Comment

by:lermytte
ID: 1418589
I have general knowledge and a book about api calls from VB.
I tried already a lot of stuff but once the doswindow is fullscreen you can't even close it anymore with SendMessage. If someone has an example you can mail it to rama@skynet.be

Thanks
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1418590
Ok, here is what to do:
Get the window handle using FindWindow
Now you have the send the same message like is send when the close option from the system menu is chosen.


0
 

Author Comment

by:lermytte
ID: 1418591
But I don't wan't to close the dosapplication. I want to  take it  from full screen to a minimized state so my windows application becomes visible.

Thanks
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1418592
Oh, same thing just another message ID.
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1418593
How bad do you want the answer.

It seems to be more difficult than I thought.

I know how to do full screen on NT now.
On win95 it is a little bit different, but I do have some progress.



 
0
 

Author Comment

by:lermytte
ID: 1418594
I need it very badly. It must be possible because dos fullscreen applications get minimized automatically by VB if it gets to a breakpoint. This works on win95,win98 and NT. Also when you do an ALT-TAB from the full screen dos application you get to the next  window and the dos application gets minimized. So it must be there somewhere !!!!.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1418595
Two ideas:

(1) Perhaps you could simulate an ALT-TAB keypress with keybd_event?
(2) Try "ShowWindow(dosWindowHandle,SW_MINIMZE)"

Don't know if one of these works...

Regards, Madshi.
0
 

Author Comment

by:lermytte
ID: 1418596
Adjusted points to 150
0
 

Author Comment

by:lermytte
ID: 1418597
1>It ssems that you can't do alt with the keybd_event.
2>When doing the "ShowWindow(dosWindowHandle,SW_MINIMZE)" the fullscreen doswindow doesn't do anything.

Thanks, Eddy

0
 
LVL 20

Expert Comment

by:Madshi
ID: 1418598
Eddy,

this works fine with my win98. I've tested it...

  keybd_event(VK_MENU,0,0,0);
  keybd_event(VK_TAB,0,0,0);
  keybd_event(VK_TAB,0,KEYEVENTF_KEYUP,0);
  keybd_event(VK_MENU,0,KEYEVENTF_KEYUP,0);

Regards, Madshi.
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.

 

Author Comment

by:lermytte
ID: 1418599
Thanks for your reply,

I tried the following code :

Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Const VK_MENU = &H12
Const VK_TAB = &H9
Const KEYEVENTF_KEYUP = &H2

Private Sub Form_Load()
  Timer1.Interval = 5000
  Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
  Call keybd_event(VK_MENU, 0, 0, 0)
  Call keybd_event(VK_TAB, 0, 0, 0)
  Call keybd_event(VK_TAB, 0, KEYEVENTF_KEYUP, 0)
  Call keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0)
End Sub

Open a dos window, start the above program and switch then the dos window to full screen with alt-enter. After 5 seconds the program has to switch, this works fine if the dos window is not full screen, but alas not when full screen. Or I could do something wrong ?

Suggestions

Kind regards

Eddy
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1418600
Hmmm. I'm programming in Delphi, so I can't test your code. But I can only say this: These four keybd_event lines work fine on my win98 computer. Perhaps you can change the keybd_events to this:
  Call keybd_event(ord('A'), 0, 0, 0);
  Call keybd_event(ord('A'), 0, KEYEVENTF_KEYUP, 0);
Only to check, whether keybd_event works at all in your source.
Hmm. I'm not so sure about the C(++) syntax. I thought, there must be a ";" in the end of each line, or am I wrong?

Regards, Madshi.

P.S: Ord('A') is just the ascii code of the big "A" letter.
0
 

Author Comment

by:lermytte
ID: 1418601
The Visual Basic program I send you works fine with a dos-window. As soon as I make the dos-window full screen with Alt-Enter it doesn't works anymore.

Kind regards

Eddy
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1418602
Hmmm, yes. But it REALLY WORKS on my computer (even with fullscreen - alt-Enter - mode).
I don't understand that...  :-(

Regards, Madshi.
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1418603
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
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1418604
For NT:

#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 13

Accepted Solution

by:
Mirkwood earned 230 total points
ID: 1418605
I think I answered your question
0
 

Author Comment

by:lermytte
ID: 1418606
Hi,

I tried what you proposed before under Delphi and it seems to work fine, now I do exactly the same thing under VB6 and it won't work when the dosbox is full screen (it works with Delphi). Is there a way to make it work under VB6 ???????

Kind regards

Eddy

0
 
LVL 20

Expert Comment

by:Madshi
ID: 1418607
Perhaps it's the same problem with my solution. It works well on my computer in Delphi. And it doesn't work on your computer with VB...   :-(

Regards, Madshi.
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1418608
Please show me your vb code and I can see what goes wrong.
0
 

Author Comment

by:lermytte
ID: 1418609
Hi,

 I tried the following codein VB6  :

Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long,
       ByVal dwExtraInfo As Long)

Const VK_MENU = &H12
Const VK_TAB = &H9
Const KEYEVENTF_KEYUP = &H2

Private Sub Form_Load()
   Timer1.Interval = 5000
   Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
   Call keybd_event(VK_MENU, 0, 0, 0)
   Call keybd_event(VK_TAB, 0, 0, 0)
   Call keybd_event(VK_TAB, 0, KEYEVENTF_KEYUP, 0)
   Call keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0)
End Sub

Now open a dos window, start the above program and switch then the dos window to full screen with alt-enter. After 5 seconds the program has to switch, this works fine if the dos window is not full screen, but alas not when full screen.

Kind regards

Eddy
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1418610
Hmmm. That's what I suggested. Mirkwood's suggestion was to use "SetConsoleDisplayMode". Have you tested that?

Regards, Madshi.
0
 

Expert Comment

by:EDJ
ID: 2335218
An other way to do it is to simulate the RESTORE in the systemmenu:

H := FindWindow('tty', 'TheTitle');
 if H <> 0 then
 begin
  SetForegroundWindow(H);
  keybd_event(VK_MENU,0, 0, 0);
  keybd_event(VK_SPACE,0, 0, 0);
  keybd_event(Ord('R'),0, 0, 0);
  keybd_event(Ord('R'),0,KEYEVENTF_KEYUP,0);
   keybd_event(VK_SPACE,0,KEYEVENTF_KEYUP,0);
   keybd_event(VK_MENU,0, KEYEVENTF_KEYUP, 0);
 end;

(You could allso simulate Alt+Enter twice)

HTH Ejnar
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

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

948 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

20 Experts available now in Live!

Get 1:1 Help Now