VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)

VB爱好者乐园(VBGood)

 找回密码
 立即注册
搜索
查看: 2971|回复: 4

把DOS程序转化成Windows程序。

[复制链接]
 楼主| 发表于 2005-11-2 16:13:20 | 显示全部楼层
建三个菜单项,分别命名为mmFileApplication(打开应用程序)、mmFileNotePad(打开记事本)和mmFileQuit(退出)。<br />为控件工具箱添加一个部件“Microsoft Common Dialog”,并把这个控件添加一个到窗体里,命名为DlgOpen<br /><br />然后,下面是代码,(但为什么打开的程序不能作为子窗口呢,如果实现得了的话,我想把DOS程序转化成Windows窗口程序也是可能的吧):<br /><br />Option Explicit<br />rivate Declare Function GetWindowThreadProcessId Lib &quot;user32&quot; (ByVal hwnd As Long, lpdwProcessId As Long) As Long<br />rivate Declare Function GetParent Lib &quot;user32&quot; (ByVal hwnd As Long) As Long<br />rivate Declare Function FindWindow Lib &quot;user32&quot; Alias &quot;FindWindowA&quot; (ByVal lpClassName As String, ByVal lpWindowName As String) As Long<br />Private Declare Function GetWindow Lib &quot;user32&quot; (ByVal hwnd As Long, ByVal wCmd As Long) As Long<br />Private Declare Function GetWindowText Lib &quot;user32&quot; Alias &quot;GetWindowTextA&quot; (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long<br />Private Declare Function SetParent Lib &quot;user32&quot; (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long<br /><br />Private Const GW_HWNDNEXT = 2<br /><br />Private hwndApplicationParent As Long<br />Private hwndApplication As Long<br /><br />Private Function GetWindowHwnd(ByVal lSourceID As Long) As Long<br />    Dim hwndTemp As Long<br />    Dim lProcessID As Long<br />    Dim lIDTemp As Long<br />    hwndTemp = FindWindow(ByVal 0&amp;, ByVal 0&amp;)<br />    Do While hwndTemp &lt;&gt; 0<br />        If GetParent(hwndTemp) = 0 Then<br />            lIDTemp = GetWindowThreadProcessId(hwndTemp, lProcessID)<br />            If lProcessID = lSourceID Then<br />                GetWindowHwnd = hwndTemp<br />                Exit Do<br />            End If<br />        End If<br />        hwndTemp = GetWindow(hwndTemp, GW_HWNDNEXT)<br />    Loop<br />End Function<br /><br />Private Sub Form_Load()<br />    DlgOpen.Filter = &quot;应用程序|*.exe&quot;<br />    DlgOpen.Flags = cdlOFNFileMustExist Or cdlOFNLongNames &#39;注意参数搭配<br />End Sub<br />Private Sub mmFileApplication_click()<br />    Dim lID As Long<br />    DlgOpen.ShowOpen<br />    If Trim(DlgOpen.FileName) = &quot;&quot; Then Exit Sub<br />    lID = Shell(DlgOpen.FileName, vbMinimizedFocus)<br />    If lID = 0 Then<br />        MsgBox &quot;应用程序不能正确执行&quot;, vbOKOnly + vbInformation<br />        Exit Sub<br />    End If<br />    hwndApplication = GetWindowHwnd(lID)<br />    hwndApplicationParent = SetParent(hwndApplication, Me.hwnd)<br />End Sub<br /><br />Private Sub mmfileNotePad_click()<br />    Dim lID As Long<br />    lID = Shell(&quot;notepad.exe&quot;, vbNormalFocus)<br />    If lID = 0 Then<br />        MsgBox &quot;记事本不能正确执行&quot;, vbOKOnly + vbInformation<br />        Exit Sub<br />    End If<br />    hwndApplication = GetWindowHwnd(lID)<br />    hwndApplicationParent = SetParent(hwndApplication, Me.hwnd)<br />End Sub<br /><br />Private Sub mmFileQuit_click()<br />    Unload Me<br />End Sub<br />
回复 支持 反对

使用道具 举报

发表于 2005-11-3 06:29:49 | 显示全部楼层
function gethwnd()有问题,例如findwindow(vbnullstring,vbnullstring)<br />(仅看出这个)<br /><br />换个方式,你可以用shell(  ,normolfocus)启动,然后getfocus取得句柄
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-11-3 09:30:08 | 显示全部楼层
高手啊,你! 是哦,就是那段自定义的函数有错,我却不知道错在哪里,你给的提示我还不知道怎么应用,麻烦你把这段自定义函数改一改,好吗?<br />rivate Function GetWindowHwnd(ByVal lSourceID As Long) As Long<br />Dim hwndTemp As Long<br />Dim lProcessID As Long<br />Dim lIDTemp As Long<br />hwndTemp = FindWindow(ByVal 0&amp;, ByVal 0&amp;)<br />Do While hwndTemp &lt;&gt; 0<br />If GetParent(hwndTemp) = 0 Then<br />lIDTemp = GetWindowThreadProcessId(hwndTemp, lProcessID)<br />If lProcessID = lSourceID Then<br />GetWindowHwnd = hwndTemp<br />Exit Do<br />End If<br />End If<br />hwndTemp = GetWindow(hwndTemp, GW_HWNDNEXT)<br />Loop<br />End Function<br />
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-11-4 14:19:40 | 显示全部楼层
哇,我的问题推到老后头去了。<br />麻烦,高手们看一眼吧,帮我好吗。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-6-1 17:51:23 | 显示全部楼层
论坛升级后,N久以前的代码不换行了。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

文字版|手机版|小黑屋|VBGood  

GMT+8, 2022-7-5 10:45

VB爱好者乐园(VBGood)
快速回复 返回顶部 返回列表