Solved

Closing full screen dos application from windows

Posted on 1999-01-12
26
222 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

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
 

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

726 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