Pagina 2 di 2 primaprima 1 2
Visualizzazione dei risultati da 11 a 17 su 17
  1. #11
    Utente di HTML.it
    Registrato dal
    Sep 2006
    Messaggi
    562
    Ho trovato questo codice:

    Private Type POINTAPI
    x As Long
    y As Long
    End Type
    Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
    End Type

    Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function GetMenuItemRect Lib "user32" (ByVal hwnd As Long, ByVal hMenu As Long, ByVal uItem As Long, lprcItem As RECT) As Long
    Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long

    Private Const MOUSEEVENTF_ABSOLUTE = &H8000 ' absolute move
    Private Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
    Private Const MOUSEEVENTF_LEFTUP = &H4 ' left button up
    Private Const MOUSEEVENTF_MOVE = &H1 ' mouse move
    Private Const MOUSEEVENTF_MIDDLEDOWN = &H20
    Private Const MOUSEEVENTF_MIDDLEUP = &H40
    Private Const MOUSEEVENTF_RIGHTDOWN = &H8
    Private Const MOUSEEVENTF_RIGHTUP = &H10

    Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
    Private Declare Function GetMessageExtraInfo Lib "user32" () As Long
    Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
    Const SM_CXSCREEN = 0 'X Size of screen
    Const SM_CYSCREEN = 1 'Y Size of Screen

    Private Sub Command1_Click()
    MsgBox "cliccato"
    End Sub

    Private Sub Form_KeyPress(KeyAscii As Integer)
    Dim mWnd As Long
    mWnd = Me.hwnd

    Dim hMenu As Long, hSubMenu As Long

    hMenu = GetMenu(mWnd) 'Get the Menu of the Window(MenuBar)
    ClickMenuItem mWnd, hMenu, 0 'Click on the first SubMenu
    hSubMenu = GetSubMenu(hMenu, 0) 'Get its submenu
    ClickMenuItem mWnd, hSubMenu, 0 'Click on the first MenuItem of the Submenu

    End Sub


    Private Sub ScreenToAbsolute(lpPoint As POINTAPI)
    lpPoint.x = lpPoint.x * (&HFFFF& / GetSystemMetrics(SM_CXSCREEN))
    lpPoint.y = lpPoint.y * (&HFFFF& / GetSystemMetrics(SM_CYSCREEN))
    End Sub

    Private Sub Click(p As POINTAPI)
    'p.X and p.Y in absolute coordinates
    'Put the mouse on the point

    mouse_event MOUSEEVENTF_ABSOLUTE Or MOUSEEVENTF_MOVE, p.x, p.y, 0, GetMessageExtraInfo()
    'Mouse Down
    mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, GetMessageExtraInfo()
    'Mouse Up
    mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, GetMessageExtraInfo()
    End Sub

    Private Sub ClickMenuItem(ByVal mWnd As Long, ByVal hMenu As Long, ByVal Pos As Long)
    Dim ret As Long
    Dim r As RECT, p As POINTAPI
    ret = GetMenuItemRect(mWnd, hMenu, Pos, r)
    If ret = 0 Then Exit Sub
    p.x = (r.Left + r.Right) / 2
    p.y = (r.Top + r.Bottom) / 2
    ScreenToAbsolute p
    'Click on p
    Click p
    End Sub

    Private Sub Form_Load()
    Dim mWnd As Long, p As POINTAPI
    mWnd = Me.hwnd
    Dim hMenu As Long, hSubMenu As Long
    hMenu = GetMenu(mWnd) 'Get the Menu of the Window(MenuBar)
    ClickMenuItem mWnd, hMenu, 0 'Click on the first SubMenu
    hSubMenu = GetSubMenu(hMenu, 0) 'Get its submenu
    ClickMenuItem mWnd, hSubMenu, 0 'Click on the first MenuItem of the Submenu
    p.x = &HFFFF& / 2
    p.y = &HFFFF& / 2
    Click p
    Me.AutoRedraw = True
    Me.BackColor = vbWhite
    Print "Press any key"
    End Sub

    Private Sub menu2_Click()
    MsgBox "Click"
    End Sub



    Come devo fare per farlo cliccare da solo dopo un certo tempo? Che ci devo inserire?

  2. #12
    Utente di HTML.it
    Registrato dal
    Sep 2006
    Messaggi
    562
    Per il click ho risolto, come faccio per la posizione della freccetta, per esempio io voglio fare in modo che quando parte la freccetta me la sposta in una posizione che dico io.

  3. #13
    Utente di HTML.it
    Registrato dal
    Sep 2006
    Messaggi
    562
    Come faccio?

  4. #14
    Utente di HTML.it
    Registrato dal
    Sep 2006
    Messaggi
    562
    nessuno?

  5. #15
    Del codice che hai postato tieni solo le dichiarazioni; per il resto per cliccare il punto dove attualmente c'è il puntatore basta chiamare
    codice:
    mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, GetMessageExtraInfo()
    mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, GetMessageExtraInfo()
    .
    Amaro C++, il gusto pieno dell'undefined behavior.

  6. #16
    Utente di HTML.it
    Registrato dal
    Sep 2006
    Messaggi
    562
    Si, ma per spostare il mouse dove dico io, nelle coordinate che dico io, come faccio?

  7. #17
    Usando il codice che hai postato in versione "sfrondata" dalla roba inutile:
    codice:
    Private Type POINTAPI
    x As Long
    y As Long
    End Type
    
    Private Const MOUSEEVENTF_ABSOLUTE = &H8000 ' absolute move
    Private Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
    Private Const MOUSEEVENTF_LEFTUP = &H4 ' left button up
    Private Const MOUSEEVENTF_MOVE = &H1 ' mouse move
    Private Const MOUSEEVENTF_MIDDLEDOWN = &H20
    Private Const MOUSEEVENTF_MIDDLEUP = &H40
    Private Const MOUSEEVENTF_RIGHTDOWN = &H8
    Private Const MOUSEEVENTF_RIGHTUP = &H10
    
    Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
    Private Declare Function GetMessageExtraInfo Lib "user32" () As Long
    Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
    Const SM_CXSCREEN = 0 'X Size of screen
    Const SM_CYSCREEN = 1 'Y Size of Screen
    
    Private Sub ScreenToAbsolute(lpPoint As POINTAPI)
    lpPoint.x = lpPoint.x * (&HFFFF& / GetSystemMetrics(SM_CXSCREEN))
    lpPoint.y = lpPoint.y * (&HFFFF& / GetSystemMetrics(SM_CYSCREEN))
    End Sub
    
    Private Sub Click(p As POINTAPI)
    'p.X and p.Y in absolute coordinates
    'Put the mouse on the point
    
    mouse_event MOUSEEVENTF_ABSOLUTE Or MOUSEEVENTF_MOVE, p.x, p.y, 0, GetMessageExtraInfo()
    'Mouse Down
    mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, GetMessageExtraInfo()
    'Mouse Up
    mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, GetMessageExtraInfo()
    End Sub
    Per cliccare nel punto che vuoi tu usa
    codice:
    Dim p As POINTAPI 'struttura che contiene le coordinate da cliccare
    p.x=100 'coordinata X del punto da cliccare
    p.y=200 'coordinata Y del punto da cliccare
    ScreenToAbsolute p 'converte il punto da coordinate dello schermo a coordinate "assolute" (espresse in 65536esimi di lunghezza/altezza dello schermo)
    Click p 'clicca
    .
    Amaro C++, il gusto pieno dell'undefined behavior.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.