Работа с буфером обмена Windows, нажатие клавиш прогр-но

hosm

* so what *
18.05.2009
2 442
9
#1
Работа с буфером обмена Windows
Вот код по переносу запроса в буфер. Мб будет полезно.

Код:
Declare Function OpenClipboard Lib "User32.dll" Alias "OpenClipboard" (Byval hWnd As Long) As Long
Declare Function EmptyClipboard Lib "User32.dll" Alias "EmptyClipboard" ( ) As Long
Declare Function SetClipboardData Lib "User32.dll" Alias "SetClipboardData" (Byval wFormat As Integer,Byval hAnsiText As Long ) As String
Declare Function CloseClipboard Lib "User32.dll" Alias "CloseClipboard" ( ) As Long
Declare Function GlobalAlloc Lib "Kernel32.dll" Alias "GlobalAlloc" (Byval wFlags As Long, Byval dwBytes As Long) As Long
Declare Function GlobalLock Lib "Kernel32.dll" Alias "GlobalLock"(Byval hMem As Long) As Long
Declare Function GlobalUnlock Lib "Kernel32.dll" Alias "GlobalUnlock" (Byval hMem As Long) As Long
Declare Function lstrcpy Lib "kernel32.dll" (Byval lpString1 As Any, Byval lpString2 As Any) As Long

Const CF_TEXT = &H001
Const CF_LOCALE = 16

'queryString - СТРОКА С ЗАПРОСОМ

Dim ptr As Long, ghand As Long, handle As Long
Dim ptrlocale As Long, ghandlocale As Long, handlelocale As Long

'get global storage for field contense
ghand = GlobalAlloc (0, (Len(queryString)+1))
'lock global storage
ptr = GlobalLock (ghand)
'copy contense of field to global storage
ptr = lstrcpy (ptr, queryString)
'free global storage
Call GlobalUnlock(ghand)

' проблема при заполнении не русской раскладкой, поэтому записываем русскую локаль в буфер
ghandlocale = GlobalAlloc (0, 4 )
ptrlocale = GlobalLock (ghandlocale)
ptrlocale = lstrcpy (ptrlocale, Cstr (0000419))
Call GlobalUnlock (ghandlocale)

' open clipboard
Call OpenClipboard (0)
Call EmptyClipboard()
'write to clipboard
Call SetClipboardData (CF_TEXT, ptr)

Call SetClipboardData (CF_LOCALE, ptrlocale)

'close clipboard
Call CloseClipboard()
Программное нажатие клавиш.
Нажатие Enter:

Код:
Declare Sub keybd_event Lib "user32.dll" (Byval bVk As Integer, Byval bScan As Integer, _
Byval dwflags As Long, Byval dwextrainfo As Long)

Sub Initialize
keybd_event 13,0,0,0  
keybd_event 13,0,2,0
End Sub
Код iki из темы Отобразить коллекцию