title image


Smiley Re: E97: API: Tastenkombi per Sendmessage an Fenster-Handle
Hallo,



mit postmessage kann man Alt-Befehle senden,

(im folgenden Beispiel an Notepad).



Form1:

--------------------

'Benötigt 2 Command Buttons

Private Declare Function PostMessage Lib "user32.dll" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Declare Function SetActiveWindow Lib "user32.dll" (ByVal hwnd As Long) As Long

Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Const WM_SYSKEYDOWN = &H104: Private Const WM_SYSKEYUP = &H105

Const WM_KEYDOWN = &H100: Const WM_KEYUP = &H101

Dim hwn

Private Sub Command2_Click()

MsgBox "ich bestätige, daß notepad gestartet ist"

hwn = FindWindow(vbNullString, "Unbenannt - Editor")



MsgBox "notepad hat das handle " & hwn

Call notepadprint



Call focusaufnotepad: Call Sleep(999)



'sendet ALT-D-u (=Datei/Speichern unter in Notepad)

Call PostMessage(hwn, WM_SYSKEYDOWN, Asc("D"), &H20000001) 'Alt-D Down

Sleep 1999

PostMessage hwn, WM_KEYDOWN, Asc("U"), &H0 'sende ASC("U")

Sleep 2222



Me.SetFocus

MsgBox "die Folge ALT-D u wurde an notepad gesendet! - vb beenden?"

End

End Sub

Private Sub Command1_Click()

Shell "notepad.exe", vbNormalFocus: DoEvents

End Sub

Private Sub Form_Load()

Me.Move 0, 0, 4000, 3000: Command1.Width = 3000

Command1.Caption = "step1: Notepad starten (wenn noch nicht gestartet)"

Command2.Caption = "step2: starte den Test"

End Sub

Sub notepadprint()

MsgBox "ich sende jetzt : TEST mit dem Sendkeys-Befehl"

focusaufnotepad

Sleep 999

Call SendKeys("test", True): Call Sleep(999): Call Me.SetFocus

MsgBox "TEST gesendet"

MsgBox "ich sende jetzt" & vbCrLf & "ALT_D_u für" & vbCrLf & "Alt_Datei speichern_unter"

End Sub

Sub focusaufnotepad()

SetForegroundWindow hwn

SetActiveWindow hwn

DoEvents

End Sub




 Die von mir vorgeschlagenen Lösungen wurden unter VB6 getestet (Betriebssystem: Windows 98 SE)
Meine Microsite


geschrieben von

Login

E-Mail:
  

Passwort:
  

Beitrag anfügen

Symbol:
 
 
 
 
 
 
 
 
 
 
 
 
 

Überschrift: