Solved

Closing full screen dos application from windows

Posted on 1999-01-12
26
217 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
Comment Utility
Yes, I can be done. But is not easy. What is your knowledge about windows API's and SendMessage.
0
 

Author Comment

by:lermytte
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Oh, same thing just another message ID.
0
 
LVL 13

Expert Comment

by:Mirkwood
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Adjusted points to 150
0
 

Author Comment

by:lermytte
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:lermytte
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I think I answered your question
0
 

Author Comment

by:lermytte
Comment Utility
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
Comment Utility
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
Comment Utility
Please show me your vb code and I can see what goes wrong.
0
 

Author Comment

by:lermytte
Comment Utility
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
Comment Utility
Hmmm. That's what I suggested. Mirkwood's suggestion was to use "SetConsoleDisplayMode". Have you tested that?

Regards, Madshi.
0
 

Expert Comment

by:EDJ
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

763 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

10 Experts available now in Live!

Get 1:1 Help Now