Home All Groups Group Topic Archive Search About
Author
20 Mar 2009 5:12 PM
Claus Centrino
I'm looking for a way to have a DOS box window as an own
child window (not nescessarily a MDI child window) of my
application, so that moving and resizing my application will
move and resize the DOS box window also.

I saw several examples which run a "Shell CMD ...."
statement followed by a SetParent call to assign the DOS box
window to the VB application, but there was still the
child's title bar visible, and therefore the child window
easily could be moved out of the parent window or even
closed, independent from the host.

Therefore I would like to have only the DOS box' client
window without title bar, so that the user can enter DOS
commands but cannot shift out or close the DOS box window.
Is there an example available showing how to do this?

Author
20 Mar 2009 6:23 PM
Karl E. Peterson
Claus Centrino wrote:
Show quoteHide quote
> I'm looking for a way to have a DOS box window as an own
> child window (not nescessarily a MDI child window) of my
> application, so that moving and resizing my application will
> move and resize the DOS box window also.
>
> I saw several examples which run a "Shell CMD ...."
> statement followed by a SetParent call to assign the DOS box
> window to the VB application, but there was still the
> child's title bar visible, and therefore the child window
> easily could be moved out of the parent window or even
> closed, independent from the host.
>
> Therefore I would like to have only the DOS box' client
> window without title bar, so that the user can enter DOS
> commands but cannot shift out or close the DOS box window.
> Is there an example available showing how to do this?

Maybe if you captured the standard output from a console application, and displayed
that in your own window?

   http://www.vb-helper.com/howto_capture_console_stdout.html

Not sure what might be involved, if the process is interactive.
--
..NET: It's About Trust!
http://vfred.mvps.org
Author
20 Mar 2009 10:59 PM
MikeD
Show quote Hide quote
"Claus Centrino" <c***@sofort-mail.de> wrote in message
news:gq0irh$uv4$1@online.de...
> I'm looking for a way to have a DOS box window as an own child window (not
> nescessarily a MDI child window) of my application, so that moving and
> resizing my application will move and resize the DOS box window also.
>
> I saw several examples which run a "Shell CMD ...." statement followed by
> a SetParent call to assign the DOS box window to the VB application, but
> there was still the child's title bar visible, and therefore the child
> window easily could be moved out of the parent window or even closed,
> independent from the host.
>
> Therefore I would like to have only the DOS box' client window without
> title bar, so that the user can enter DOS commands but cannot shift out or
> close the DOS box window. Is there an example available showing how to do
> this?


No guarantee of success, but before you call SetParent, make sure the
console window does not have the WS_POPUP window style and give it the
WS_CHILD and WS_CLIPSIBLINGS styles (a window can't have both WS_POPUP and
WS_CHILD; hence the need to remove WSPOPUP if it has that style before
giving it WS_CHILD).  This should take care of the console window getting
moved outside the parent.  IOW, it should remain contained within the
parent, just like an MDI child window. To get rid of the Close button on the
title bar, remove the Close command from the system menu.

Here's a function you can try for setting the parent:

-----BEGIN CODE
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long,
ByVal hWndNewParent As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA"
(ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA"
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long,
ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As
Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Private Const GWL_STYLE = (-16)
Private Const WS_CHILD = &H40000000
Private Const WS_POPUP = &H80000000
Private Const WS_CLIPSIBLINGS = &H4000000
Private Const SWP_FRAMECHANGED = &H20
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOZORDER = &H4

Public Function SetAsParent(ByVal hChild As Long, ByVal hParent As Long) As
Boolean

    Dim lRet As Long
    Dim lStyle As Long
    Dim lFlags As Long

    'Get current window style
    lStyle = GetWindowLong(hChild, GWL_STYLE)

    'A window cannot have both the WS_POPUP and WS_CHILD styles
    'so make sure WS_POPUP is removed
    If (lStyle And WS_POPUP) = WS_POPUP Then
        lStyle = lStyle And Not WS_POPUP
    End If

    'Give the window the WS_CHILD and WS_CLIPSIBLINGS styles.
    If (lStyle And WS_CHILD) <> WS_CHILD Then
        lStyle = lStyle Or WS_CHILD Or WS_CLIPSIBLINGS
    End If

    lRet = SetWindowLong(hChild, GWL_STYLE, lStyle)
    lFlags = SWP_NOMOVE Or SWP_NOSIZE Or SWP_NOZORDER Or SWP_FRAMECHANGED
    SetWindowPos hChild, 0, 0, 0, 0, 0, lFlags

    'Now go ahead and set the new parent window.
    Call SetParent(hChild, hParent)
    SetWindowPos hParent, 0, 0, 0, 0, 0, lFlags

    SetAsParent = True

End Function
------END CODE

Now, to remove the Close button:

-----BEGIN CODE
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long,
ByVal bRevert As Long) As Long
Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As
Long
Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal
nPosition As Long, ByVal wFlags As Long) As Long

Private Const MF_BYCOMMAND      As Long = &H0
Private Const SC_CLOSE          As Long = &HF060
Private Const MF_DISABLED       As Long = &H2&
Private Const MF_GRAYED         As Long = &H1&

    Dim hSysMenu            As Long
    Static bDisabled        As Boolean

    If bDisabled Then
        'Restores the system menu to its default state.
        Call GetSystemMenu(Me.hwnd, 1)
    Else
        'Get a handle for the system menu
        hSysMenu = GetSystemMenu(Me.hwnd, 0)
        Call RemoveMenu(hSysMenu, SC_CLOSE, MF_BYCOMMAND)
    End If

    bDisabled = Not bDisabled

    'Redraw the menu to reflect the change
    Call DrawMenuBar(Me.hwnd)
-----END CODE

One thing I noticed in Vista with Aero enabled is that the Close button on
the title bar was not actually removed (the Close command on the system menu
was removed though).  But the button WAS non-functional. I also only
"tested" removing the close button and it was against a VB6 form window.
I've no idea if ANY of this will work against a console window. But I figure
it's worth a shot. (and sorry for any word-wrapping of the code that you may
have to correct).


--
Mike
Author
21 Mar 2009 9:27 AM
Claus Centrino
I would like to have a dos box window without title bar,
then I don't have to take care of window shifting,
minimizing, or maximizing, I only would have to detect
window closing after executing the EXIT command.