Results 1 to 6 of 6

Thread: Bringing window to front and sending a message

Threaded View

  1. #1

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Bringing window to front and sending a message

    Gah. Im depressed that I cant do this, I used to be good at programming! I'm in Vb.Net 2008 express, and I have a window that I need to send the message F9 to. So, I tried using sendmessage, but it isnt working. So I figured I would use keybd_event after bringing the window to the front. Problem is, I cant bring the window to the front!!! Im tearing my hair out. Okay. Heres my code (along with a whole bunch of other crud I threw in there to hopefully get it to work)



    VB Code:
    1. Public Class Form1
    2.     Const VK_F9 = 120
    3.     Const VK_SPACE As Int32 = &H20
    4.     Const SW_SHOW As Int32 = 5
    5.     Const WM_KEYDOWN As Integer = 256
    6.     Const WM_KEYUP As Integer = 257.0
    7.     <Runtime.InteropServices.DllImport("user32", EntryPoint:="ShowWindow")> _
    8.         Private Shared Function ShowWindow( _
    9.         ByVal hwnd As IntPtr, ByVal nCmdShow As Integer) As Integer
    10.     End Function
    11.     Private SW_SHOWNORMAL As Integer = &H1
    12.     Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    13.     Declare Function SetForegroundWindow Lib "user32" Alias "SetForegroundWindow" (ByVal hwnd As Long) As Long
    14.  
    15.     Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
    16.         Dim recordingAudioHwnd As Int32 = Process.GetProcessesByName("Live 7.0.1")(0).MainWindowHandle
    17.         Dim recordingVideoHwnd As Int32 = Process.GetProcessesByName("LiveCam")(0).MainWindowHandle
    18.         ShowWindow(recordingAudioHwnd, SW_SHOWNORMAL)
    19.         SetForegroundWindow(recordingAudioHwnd)
    20.         keybd_event(VK_F9, 0, 0, 0)
    21.         keybd_event(VK_F9, 0, WM_KEYUP, 0)
    22.         Application.DoEvents()
    23.         keybd_event(VK_SPACE, 0, 0, 0)
    24.         keybd_event(VK_SPACE, 0, WM_KEYUP, 0)
    25.         Me.Close()
    26.     End Sub
    27.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    28.  
    29.     End Sub
    30. End Class

    NOTHING works. Thanks for your help.

    Edit**
    myAudio(0) is returning a hwnd for those who are wondering

    edit#2-
    I had to fix the declaration for ShowWindow. Now that somewhat works. Problem is, it isnt sending the vk_space ever, any ideas?
    Last edited by |2eM!x; May 17th, 2008 at 06:57 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width