第一程序是一个叫BackForm 的Form窗口,仅做背景,无任何内容,已用Api函数 SetWindowPos 设置为TopMost窗口,窗口属性 Enabled=False。
 第二程序是一个叫ShowForm的Form窗口,窗口上放一个叫"Clock"的自制ACTIVEX控件,该控件是一个模拟时钟。控件"Clock"的属性Enabled=False,AutoRedraw=False(设置成True错误也一样),CanGetFocus=False,该自制控件没有使用Paint事件。ShowForm窗口的属性Enabled=False,并且已用API函数SetWindowPos 设置为TopMost.编译"ShowForm"窗口为"ShowForm.exe".
 在第一程序BackForm的Load事件中用 Shell函数 "Shell ShowForm.exe"显示SowForm窗口,希望窗口"ShowForm"一直显示在窗口"BackForm"之上.
 问题是:BackForm窗口程序执行后,一用鼠标点击SHowForm窗口,ShowForm窗口立刻被BackForm窗口盖掉.!!如果删掉"Clock"控件或更换"Clock"控件成任一微软的现成控件,则同样用鼠标点击ShowForm窗口,ShowForm仍然显示在BackForm之上,执行正常,说明问题肯定出现在自制的ACTIVEX控件上,我的ACTIVEX控件仅用一个TIMER定时器画时钟指针,请问我的ActiveX控件到底错在那些地方??

解决方案 »

  1.   

    两个窗体都用了SetWindowPos 设置为TopMost,这样做不是很好,我的建议,设置BackForm窗口为TopMost,然后用SetParent将SHowForm设为BackForm的子窗口,下面是调用记事本的一个例子:
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long
    Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
    Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
    Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
    Private Declare Function GetDesktopWindow Lib "user32" () As Long
    Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
    Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
    Private Declare Function Putfocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long
    Const GW_HWNDNEXT = 2
    Dim mWnd As Long
    Function InstanceToWnd(ByVal target_pid As Long) As Long
        Dim test_hwnd As Long, test_pid As Long, test_thread_id As Long
        'Find the first window
        test_hwnd = FindWindow(ByVal 0&, ByVal 0&)
        Do While test_hwnd <> 0
            'Check if the window isn't a child
            If GetParent(test_hwnd) = 0 Then
                'Get the window's thread
                test_thread_id = GetWindowThreadProcessId(test_hwnd, test_pid)
                If test_pid = target_pid Then
                    InstanceToWnd = test_hwnd
                    Exit Do
                End If
            End If
            'retrieve the next window
            test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT)
        Loop
    End Function
    Private Sub Form_Load()
        Dim Pid As Long
        'Lock the window update
        LockWindowUpdate GetDesktopWindow
        'Execute notepad.Exe
        Pid = Shell("c:\windows\notepad.exe", vbNormalFocus)
        If Pid = 0 Then MsgBox "Error starting the app"
        'retrieve the handle of the window
        mWnd = InstanceToWnd(Pid)
        'Set the notepad's parent
        SetParent mWnd, Me.hwnd
        'Put the focus on notepad
        Putfocus mWnd
        'Unlock windowupdate
        LockWindowUpdate False
    End Sub
    Private Sub Form_Unload(Cancel As Integer)
        'Unload notepad
        DestroyWindow mWnd
        'End this program
        TerminateProcess GetCurrentProcess, 0
    End Sub
      

  2.   

    自己解决了
    ShowForm.enabled=true