求怎样在 VB中嵌入DOS窗口,并且固定DOS窗口的位置和大小
如题看见有人将一个VB窗体嵌入到另一个窗体中,并固定子窗易做图置。
http://cache.baidu.com/c?m=9f65cb4a8c8507ed4fece763105392230e54f7276c828d4829c3933fc239045c013ca3ec74740704a5c0766301a85e5c9cf32172410037b7ec92ce1583afd7756fde2870200b863005a312b8ba3732b1248729e3b81996ad863784d8d3c4de2444ba55120a82e7fb2e1762b9&p=8e769a46d69b11a05becc12f454396&user=baidu&fm=sc&query=vb+%B9%CC%B6%A8+%D7%D3%B4%B0%BF%DA&qid=d90814ee0379ede6&p1=13&fast=y
我参照其编程,但是使用SetWindowLong时,对DOS窗体无效。这是怎么回事呢? --------------------编程问答-------------------- 这对老子来说太简单了,有现成的示例代码 --------------------编程问答-------------------- 有啊,一会儿 --------------------编程问答--------------------
bas
Option Explicit
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function DefWindowProc Lib "user32" Alias "DefWindowProcA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Const GWL_WNDPROC = (-4)
Public Const WM_NCHITTEST = &H84
Public Const HTCAPTION = 2
Public oldhwnd As Long
Public Flag As Boolean
Public Function WndProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Flag = False Then
Flag = True
Debug.Print "WndprocHandle="; hWnd
End If
If uMsg = WM_NCHITTEST Then
If DefWindowProc(hWnd, uMsg, wParam, lParam) = HTCAPTION Then
WndProc = 1
Exit Function
End If
End If
WndProc = CallWindowProc(oldhwnd, hWnd, uMsg, wParam, lParam)
End Function
form1
Option Explicit
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Sub Command1_Click()
Dim commandstring As String
Dim TaskID As Long
Dim hWnd As Long
TaskID = Shell("cmd.exe", vbNormalNoFocus)
MsgBox "开始运行DOS"
hWnd = FindWindow("ConsoleWindowClass", "C:\WINDOWS\system32\cmd.exe")
SetParent hWnd, Form1.hWnd
oldhwnd = SetWindowLong(hWnd, -4, AddressOf WndProc)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Unload Form1
End Sub
--------------------编程问答-------------------- 自己顶一下,请大侠帮助指点下 --------------------编程问答-------------------- 设置窗口过程需要那个窗口归当前进程管,你的明显不是这样 --------------------编程问答-------------------- 额 有点不明白
很感谢你的提示,我再看看 --------------------编程问答-------------------- --------------------编程问答-------------------- 怎么就没想到用SetParent
补充:VB , API