Results 1 to 19 of 19

Thread: [2005] Findwindow API

Hybrid View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: [2005] Findwindow API

    I have been using VB .NET for a while, i used a couple API functions.. here and there but i got them on different websites that just said this and that does this. I never really understood how to write a API so by the link you provided i completly dont know anything about API therefore i cannot do anything yet. Can someone explain the functions of API and how it works etc... (Should i put this in a new thread?)

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142

    Re: [2005] Findwindow API

    i put a basic sample together for you, there are probably loads more on here also. open an instance of notepad & see what happens.
    Code:
        Public Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Int32
        Public Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWnd1 As Int32, ByVal hWnd2 As Int32, ByVal lpsz1 As String, ByVal lpsz2 As String) As Int32
        Public Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As String) As Int32
        Public Const WM_SETTEXT As Int32 = &HC
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim hWnd As Int32 = FindWindow("Notepad", vbNullString)
            If hWnd > 0 Then
                '/// we have the handle to an open instance of notepad
                '/// now get the edit window ( the part that the text goes in )
                Dim hWndChild As Int32 = FindWindowEx(hWnd, 0, "Edit", vbNullString)
                '/// if the edit window returns as valid, we will attempt to add some text to notepad..
                If hWndChild > 0 Then
                    Dim strText As String = "some text to add to notepad!"
                    SendMessage(hWndChild, WM_SETTEXT, 0, strText)
                End If
            End If
        End Sub
    hope it helps
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  3. #3
    Hyperactive Member cameron2's Avatar
    Join Date
    Mar 2008
    Location
    Australia
    Posts
    401

    Re: [2005] Findwindow API

    Quote Originally Posted by noahssite
    I never really understood how to write a API so by the link you provided i completly dont know anything about API therefore i cannot do anything yet.
    The program from the link i gave you above actually gives you the API declaration, you just need to know the API's name, search with it in the program and it will show you the declaration, copy-paste then done!
    It probably comes with a readme.
    If this post helped you, please click the rate button to say thank you! Remember to mark the thread as resolved too.
    Autoclicker, Hide Taskbar, Sounds on internal speaker, Changing Start Button Text (with code)

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: [2005] Findwindow API

    Quote Originally Posted by cameron2
    The program from the link i gave you above actually gives you the API declaration, you just need to know the API's name, search with it in the program and it will show you the declaration, copy-paste then done!
    It probably comes with a readme.
    So i use the program to get the API name. Say i want to insert text into the internet explore address bar to recieve the name of it i used the program..

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Findwindow API

    Quote Originally Posted by noahssite
    So i use the program to get the API name. Say i want to insert text into the internet explore address bar to recieve the name of it i used the program..
    No. The API Viewer will give you the method signature, i.e. the declaration for the method that you add to your code that, when called, will be mapped to the actual function in the Windows API. It's still up to you to call that method and pass it the appropriate values in order to get the information you need. For instance, to get a top-level window handle you need to call FindWindow and pass the window title, which you can see in the title bar, and the class name, which you will have to use a tool like Spy++, WinID or Winspector to find. Also, have you done as suggested and searched the forum for examples? FindWindow is probably the most common API function because getting a top-level window handle is often the first step in any operation.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Findwindow API

    Quote Originally Posted by noahssite
    I have been using VB .NET for a while, i used a couple API functions.. here and there but i got them on different websites that just said this and that does this. I never really understood how to write a API so by the link you provided i completly dont know anything about API therefore i cannot do anything yet. Can someone explain the functions of API and how it works etc... (Should i put this in a new thread?)
    The Windows API is a set of C/C++ DLLs that export various types, values and functions. Using the Declare key word or the DllImport attribute in VB.NET you are able to declare a function in your VB code that corresponds to the exported function in a C/C++ DLL, which may be part of the Windows API or not. When you call your method in code, at run time the system will reroute the call to the function in the unmanaged library.

    Obviously the managed types available to you are different to the types used in unmanaged C/C++. You will always be able to find one, sometimes more, managed types to correspond to the unmanaged types in the original code. For instance, in dynamic_sysop's code he has used the Int32 type for all the hWnd parameters, which correspond to window handles. While this is quite acceptable, and was how it was always done in VB6, it is generally considered preferable to use the IntPtr type for handles in VB.NET. For instance, the Handle property of a form or control in VB.NET, which corresponds to the hWind property in VB6, is type IntPtr.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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