views:

63

answers:

2

Hey all i am trying to figure out why this is not sending a ALT+F to notepad!

Private Declare Function FindWindow1 Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Const WM_KEYUP = &H101
Private Const WM_KEYDOWN = &H100
Private Const WM_SYSKEYDOWN = &H104

Private Sub Command_Click()
Dim parenthwnd As Long
Dim hwnd As Long

  parenthwnd = FindWindow1(vbNullString, "Untitled - Notepad")
  retvalue = SendMessage(parenthwnd, WM_SYSKEYDOWN, VK_MENU, 1&)
  retvalue = SendMessage(parenthwnd, WM_KEYDOWN, VK_F, 1&)
End Sub

I get a value for parenthwnd but not for any of the retvalue values (0).

What am i missing???

David

A: 

Use Postmessage instead of Sendmessage

Public Const WM_SYSKEYDOWN = &H104

PostMessage hwnd, WM_SYSKEYDOWN, vbKeyF, 2 ^ 29

'Simulates Alt + F (2^29 sets the 29 bit of lParam indicating Alt is being pressed.

Cidtek
Thanks for the reply, Cidtek but that didn't seem to work.
StealthRT
A: 

I think this is the problem: you're sending your message to the frame around the notepad window, and need to send it to the menu window. Use your handle with FindWindowEx and the 32768 class name (that's a menu) to get the menu window, which is a child of the one you've got the handle to. Here are two pages: http://msdn.microsoft.com/en-us/library/ms633500(v=VS.85).aspx and http://msdn.microsoft.com/en-us/library/ms633574(VS.85).aspx#class_name that should help.

BobRodes