Parent bug

i want to parent dosbox in a Form.

Page 1 of 1

7 Replies - 1859 Views - Last Post: 08 May 2010 - 03:16 AM Rate Topic: -----

#1 geert160  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 01-February 09

Parent bug

Posted 14 April 2010 - 12:59 PM

Code is working but there is a bug.
Notepad is no problem to Parent.
Dosbox is a problem, its outside my form, i can't get it parent.

Public Class Form1
    Dim proc As Process
    Private Const WM_SYSCOMMAND As Integer = 274

    Private Const SC_MAXIMIZE As Integer = 61488

    Declare Auto Function SetParent Lib "user32.dll" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer

    Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Run Notepad application inside Panel1 control



        proc = Process.Start("Notepad.exe")

        proc.WaitForInputIdle()

        SetParent(proc.MainWindowHandle, Me.Panel1.Handle)

        SendMessage(proc.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        ' Close process by sending a close message to its main window.
        proc.CloseMainWindow()
        ' Free resources associated with process.
        Proc.Close()


    End Sub

    Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        
        proc = Process.Start("C:\Program Files\DOSBox-0.72\dosbox.exe", "-noconsole")

        proc.WaitForInputIdle()

        SetParent(proc.MainWindowHandle, Me.Panel1.Handle)

        SendMessage(proc.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
    End Sub

    
End Class


When i use
 Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        
        proc = Process.Start("C:\Program Files\DOSBox-0.72\dosbox.exe")

        proc.WaitForInputIdle()

        SetParent(proc.MainWindowHandle, Me.Panel1.Handle)

        SendMessage(proc.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
    End Sub

and skip "-noconsole" part then the console is in my form as a parent.
But when i use the noconsole part then nothing is in my form as a parent.
I think its a bug but i can't find it.
There is no error.

Is This A Good Question/Topic? 0
  • +

Replies To: Parent bug

#2 demausdauth  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 182
  • View blog
  • Posts: 663
  • Joined: 03-February 10

Re: Parent bug

Posted 15 April 2010 - 10:46 AM

Have you tried debugging and stepping through the Button3 click event to see if there is actually a MainWindowHandle for the process with the noconsole parameter?
Was This Post Helpful? 0
  • +
  • -

#3 geert160  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 01-February 09

Re: Parent bug

Posted 15 April 2010 - 12:33 PM

Howe can i edit my code sowe that there is a MainWindowHandle for the process with the noconsole parameter?

When i don't use that parameter then all works fine.
I gess that i need to change somthing.
Problem is that i don't know where to look, this stuff is new for me.
Google gave me all info to get this far.

There are no errors.

Iff you have a link then i'm happy :-)
I want to learn from this.
Was This Post Helpful? 0
  • +
  • -

#4 demausdauth  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 182
  • View blog
  • Posts: 663
  • Joined: 03-February 10

Re: Parent bug

Posted 15 April 2010 - 01:05 PM

I assume from your response, that you did the debug and found out that there was no window handle? I guess I would assume that since there is no console, hence no window then you won't be able to get a window handle.

Now why would you want to make a process the child of your application that is not shown to the user? Why do you need it to not show?
Was This Post Helpful? 0
  • +
  • -

#5 geert160  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 01-February 09

Re: Parent bug

Posted 15 April 2010 - 01:24 PM

Dos box hase 2 windows, one is the console and one is the dosbox.
But i only need that dosbox window.
To get that there is a option to put -noconsole after dosbox.exe icon.
Thats why i want to add that no console parameter.

I want to make dosbox the child sowe that i can give it a nice layout.
I'm going to add some buttons and use sendkeys sowe that i can control my old dos programs.

I hope you understand what i mean.
I'm dutch, sorry for poor typing.

I did the debug and there is no window handle when i use -noconsole.
There is a window handle when i don't use -noconsole.
But then only the console screen is child and not the dosbox screen.
Dosbox screen is like a cmd screen.

I wonder, can it be that console window = main window
and dosbox window = top level window ???

iff yes than hawe can i get that top level window?

This post has been edited by geert160: 15 April 2010 - 02:12 PM

Was This Post Helpful? 0
  • +
  • -

#6 Ändrew  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 25
  • View blog
  • Posts: 312
  • Joined: 21-April 08

Re: Parent bug

Posted 16 April 2010 - 01:23 AM

Done a thing like your doing try this.

EDIT[forgot to explain it]
This loops through all the processes looking for the title that Dos box uses.

Dim handle As IntPtr
For Each proc As Process In Process.GetProcesses()
    If proc.MainWindowTitle.StartsWith("Dosbox Title") Then
         handle = proc.MainWindowHandle
    End If
Next



Replace "Dosbox Title" with the title that DOS Box uses.
Code converted from C# still should work.

Ändrew

This post has been edited by Ändrew: 16 April 2010 - 01:25 AM

Was This Post Helpful? 1
  • +
  • -

#7 geert160  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 01-February 09

Re: Parent bug

Posted 16 April 2010 - 02:36 AM

THX for tip, it works.

 Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        proc = Process.Start("C:\Program Files\DOSBox-0.72\dosbox.exe", "-noconsole")

        proc.WaitForInputIdle()
        For Each proc As Process In Process.GetProcesses()
            If proc.MainWindowTitle.StartsWith("DOSBox") Then
                handle = proc.MainWindowHandle
            End If
        Next

        SetParent(proc.MainWindowHandle, Me.Panel1.Handle)

        SendMessage(proc.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
        
    End Sub


I'm going to make it sendkeys and then when all works fine i'm going to post all code here.
Its hard to find info on this stuff.
THX again for your help.
Was This Post Helpful? 0
  • +
  • -

#8 geert160  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 01-February 09

Re: Parent bug

Posted 08 May 2010 - 03:16 AM

I have focus problems to use sendkeys.
Do i have to focus on form1 , panel1 , ...

 Public Function whichbuttonpushed(ByVal _sender As String) As String



        SetActiveWindow(Me.Panel1.Handle) 'Set focus Active window



        Select Case _sender
            Case "btna"
                keybd_event(VK_A, 0, 0, 0) 'send a key
                keybd_event(VK_A, 0, KEYEVENTF_KEYUP, 0) 'release a key 
                My.Computer.Keyboard.SendKeys("22", True)'Other way to send a key

        End Select

    End Function

This post has been edited by geert160: 08 May 2010 - 11:40 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1