本人对VB6不擅长,请教一个问题。使用VB6怎么才能打开一个指定的文本文件,并且以置顶的方式显示?

解决方案 »

  1.   


    Option Explicit
    Private Const SWP_NOMOVE = 2
    Private Const SWP_NOSIZE = 1
    Private Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
    Private Const HWND_TOPMOST = -1
    Private Const HWND_NOTOPMOST = -2Private Declare Function SetWindowPos Lib "user32" _
          (ByVal hwnd As Long, _
          ByVal hWndInsertAfter As Long, _
          ByVal x As Long, _
          ByVal y As Long, _
          ByVal cx As Long, _
          ByVal cy As Long, _
          ByVal wFlags As Long) As LongPrivate Function SetTopMostWindow(hwnd As Long, Topmost As Boolean) As Long
       If Topmost = True Then 'Make the window topmost
          SetTopMostWindow = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
       Else
          SetTopMostWindow = SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS)
          SetTopMostWindow = False
       End If
    End FunctionPrivate Sub Form_Load()
        Me.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2, 5000, 5000
        SetTopMostWindow Me.hwnd, True
        Label1.Move 0, 0, Me.Width - 100, Me.Height - 100
        'Label1.AutoSize = False
        Open "c:\1.txt" For Input As #1
        Dim s As String
        s = StrConv(InputB(LOF(1), 1), vbUnicode)
        Label1.Caption = s
    End Sub
      

  2.   

    chinaboyzyq意思是:将文本文件的内容写到弹出的窗体的LAB上,然后再把弹出的窗体置顶吗?我这边情况有点特殊,不能使用任何窗体,只能直接打开文本文件,并且在最上层显示。
      

  3.   

    简单,打开文件后,找出记事本的hwnd,用SetTopMostWindow 记事本.hwnd, True ,应该可以了吧 ?没测试过。
      

  4.   

    刚找到1个,你看看这个,就方便多了。可窗口置顶的微软记事本:http://www.hconly.com/post/564.html
      

  5.   

    简单,打开文件后,找出记事本的hwnd,用SetTopMostWindow 记事本.hwnd, True ,应该可以了吧 ?没测试过。
    -------------------
    VB6 不太熟,能给出找句柄的相关代码吗?  谢谢SetForegroundWindow
    --------------------------
    用这个的话,光标是否还能切换到别的应用界面上,但是不影响文本的前置?
      

  6.   

    有没有使用SetForegroundWindow的相关代码啊?