Results 1 to 7 of 7

Thread: Starting up Notepad

  1. #1

    Thread Starter
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457

    Question

    Hi!

    I want to make my program start Notepad without the user doing anything (but not instantly, I want it to do it as if the user was doing it!). It's a kind of joke, I can't tell you because if someone tries to trick you with this it won't work

    I know how to move the cursor smoothly to a location (using the same calculations used to draw lines), but I need the APIs to do it.

    At first I wanted it to open up the Start menu, point to Programs » Accessories » Notepad, but I know it would be kinda hard to find the exact positions of all this.

    So I thought of another thing: the user can edit the Start menu's shortcut, the shortcuts could be in another language/under another name, sorted in another order or even deleted. So pointing directly at the position where it was suposed to be wouldn't be very efficient.

    While writing this (and know that I have re-writen it a dozen times because I'm always having new ideas ) I also came to the conclusion that using the mouse would be cool, but it wouldn't be easy (I think) to find all the handles to the objects I wanna point to (mainly submenus). I'll simply send keystrokes instead of moving the cursor *sigh*

    So we would find the Start Menu button's handle, give it the focus and send it the Enter key to simulate a click, press the Up Arrow key 3 times to select Run, send the Enter key (to simulate a click again), type "notepad" and send the Enter key again to execute it, wait a couple of seconds and voila, Notepad is open.

    Basically I need the API/APIs to find the Start Menu's button and give it focus. Unless you know how to do it using the mouse (by finding submenus' handles)... it would be awsome!

    Please, if you have -any- clue on one of these solutions, even if it's just a tiny one, reply here. Thanks!

  2. #2
    Guest
    This will click the start menu.
    Code:
    Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    Private Const BM_CLICK = &HF5
    
    Private Sub Command1_Click()
        hbtn = FindWindowEx(FindWindowEx(0, 0, "Shell_TrayWnd", vbNullString), 0, "Button", vbNullString)
        PostMessage hbtn, BM_CLICK, 0, 0
    End Sub

  3. #3

    Thread Starter
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Thanks a lot! Now the code is much easier

    If it's not asking too much, do you have the code to find a menu's handle?...

  4. #4
    Guest
    Sure. Use the GetMenu and GetSubMenu API's.
    Code:
    Private Declare Function GetMenu Lib "user32" Alias "GetMenu" (ByVal hwnd As Long) As Long
    Private Declare Function GetSubMenu Lib "user32" Alias "GetSubMenu" (ByVal hMenu As Long, ByVal nPos As Long) As Long
    
    Private Sub Command1_Click()
        Dim hMenu As Long
        hMenu = GetMenu(Form1.hWnd)
    
        MsgBox "The hWnd is: " & hMenu
    End Sub

  5. #5

    Thread Starter
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Again, thanks! Can I find a menu's handle and then use the same API to find the handle of one of its submenus?

  6. #6
    Guest
    Use the GetSubMenu API to get the submenus.
    Code:
    Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
    
    Private Sub Command1_Click()
        Dim hMenu As Long. hSubMenu As Long
        hMenu = GetMenu(Form1.hwnd)
        hSubMenu = GetSubMenu(hMenu, 5) 'Get the SubMenu from position 5
     
        MsgBox "The hWnd is: " & hMenu
    End Sub

  7. #7

    Thread Starter
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457

    Thanks!

    And sorry for asking so many questions

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