求 VB嵌入DOS窗口,并固定DOS窗口位置和大小
如题,代码如下问题,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
页:
[1]