我用vb做了一个放大镜程序,但并不是只一个放大镜,而是嵌入到一个图形显示程序中的。也就是一点click键就执行放大镜程序但是没法退出,只有关闭vb才可以推出。我的想法是再次点击这个键停止放大镜程序,也就是只退出这个程序别的都不变。望知道者告诉怎么做,给出代码最好

解决方案 »

  1.   

    你的嵌入是什么意思
    是两个独立exe软件还是 一个软件中
      

  2.   

    Private 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 Long
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
    Private Type POINTAPI
    X As Long
    Y As Long
    End Type
    Const Srccopy = &HCC0020
    Const Swp_nomove = &H2
    Const Swp_nosize = &H1
    Const Flags = Swp_nomove Or Swp_nosize
    Const hwnd_topmost = -1
    Dim pos As POINTAPI
    Private Sub Command11_Click()
    Timer4.Interval = 10
    SetWindowPos hwnd, hwnd_topmost, 0, 0, 0, 0, Flags
    End Sub
    Private Sub start()
    Dim sx As Integer
    Dim sy As Integer
    GetCursorPos pos
    sx = IIf(pos.X < 50 Or pos.X > 1000, IIf(pos.X < 50, 0, 950), pos.X - 50)
    sy = IIf(pos.Y < 50 Or pos.Y > 600, IIf(pos.Y < 50, 0, 550), pos.Y - 50)
    Caption = "坐标" & sx & "," & sy & " 放大镜程序"
    StretchBlt Picture1.hdc, 0, 0, 200, 200, GetDC(0), sx, sy, 100, 100, Srccopy
    End SubPrivate Sub Timer4_Timer()
    start
    End Sub
    上面是代码,一点CLICK就执行放大镜程序,怎么做才可以再次点CLICK就停止放大镜程序啊
      

  3.   

    不知道这样是否可以达到阁下的要求Private 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 Long
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
    Private Type POINTAPI
    X As Long
    Y As Long
    End Type
    Const Srccopy = &HCC0020
    Const Swp_nomove = &H2
    Const Swp_nosize = &H1
    Const Flags = Swp_nomove Or Swp_nosize
    Const hwnd_topmost = -1
    Dim pos As POINTAPIPrivate Sub Command11_Click()
    If Command11.Caption = "放大" Then
    Timer4.Enabled = True
    Timer4.Interval = 10
    SetWindowPos hwnd, hwnd_topmost, 0, 0, 0, 0, Flags
    Command11.Caption = "停止"
    ElseIf Command11.Caption = "停止" Then
    Timer4.Enabled = False
    Command11.Caption = "放大"
    Picture1.Picture = LoadPicture("")
    End If
    End SubPrivate Sub start()
    Dim sx As Integer
    Dim sy As Integer
    GetCursorPos pos
    sx = IIf(pos.X < 50 Or pos.X > 1000, IIf(pos.X < 50, 0, 950), pos.X - 50)
    sy = IIf(pos.Y < 50 Or pos.Y > 600, IIf(pos.Y < 50, 0, 550), pos.Y - 50)
    Caption = "坐标" & sx & "," & sy & " 放大镜程序"
    StretchBlt Picture1.hdc, 0, 0, 200, 200, GetDC(0), sx, sy, 100, 100, Srccopy
    End Sub
    Private Sub Timer4_Timer()
    start
    End Sub
      

  4.   

    哦,对了,在设置command属性的时候,让其caption等于"放大"
      

  5.   

    把command1的caption设成文字比如"开始"
    再把click事件代码改成:
    if command1.caption="开始" then
    command1.caption="停止"
    Timer4.Interval = 10
    SetWindowPos hwnd, hwnd_topmost, 0, 0, 0, 0, Flags
    else
    unload me
    end if
      

  6.   

    谢谢deterly(entries),这样确实可以,一时胡涂了,这么简单的实现方法都忘了,晕死
    也谢谢Alzzl(果子林) ,你这样的话,一下就把程序全关闭了
    多谢大家的帮助