Results 1 to 8 of 8

Thread: [RESOLVED] [2005] can't get handle with FindWindowEx

  1. #1

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    Resolved [RESOLVED] [2005] can't get handle with FindWindowEx

    *EDIT*

    ok i figured out what was causing the problem but maybe someone could still explain to me why. i took out the Auto in the declaration then it works so why does that matter???
    **********************************

    i'm using the FindWindowEx as the following


    VB Code:
    1. Public Declare Auto Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
    2.         (ByVal hWnd1 As IntPtr, _
    3.          ByVal hWnd2 As IntPtr, _
    4.          ByVal lpsz1 As String, _
    5.          ByVal lpsz2 As String) As IntPtr

    I know the classname and the caption of the window i'm trying to get and i'm using the following code, but it's returning zero. accroding to what i saw on different site this should work for getting the window's handle. so my question is what am i doing wrong???

    VB Code:
    1. HSEstimateMainWinHWnd = WinAPI.FindWindowEx(IntPtr.Zero, IntPtr.Zero, "ThunderRT6MDIForm", _
    2.             "Hendrick Manufacturing Order Estimating System")
    Last edited by vbdotnetboy; Jul 13th, 2006 at 09:17 AM. Reason: confused

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [RESOLVED] [2005] can't get handle with FindWindowEx

    change auto to Ansi

  3. #3
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Sector 001
    Posts
    1,577

    Re: [RESOLVED] [2005] can't get handle with FindWindowEx

    Why an API to get the handle?
    VB Code:
    1. Dim Notepad As Process() = Process.GetProcessesByName("notepad")
    2.         Dim NotepadPID As Integer = Notepad(0).Id
    3.         Dim NotepadHandle As IntPtr = Notepad(0).Handle
    This gives the PID and the Handle of a process. Actually you can find the two things for each instance, e.g. when 2 or more notepads are opened. GetProcessesByName returns an array with the procs with the same name.

    This is not really an answer to your question, I just thought you can use this instead of APIs.

    Regards
    VB 2005, Win Xp Pro sp2

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [RESOLVED] [2005] can't get handle with FindWindowEx

    he isn't looking for a notepad instance though.. he is looking for a VB6 form instance with a specific caption.

  5. #5
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [RESOLVED] [2005] can't get handle with FindWindowEx

    vbdotnetboy: if you leave out auto, the default is ansi, so using ansi, or leaving it out completely will do the same thing.

    You should read in the MSDN help about the difference between auto and ansi and you will see why it didn't work using auto.

  6. #6

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    Re: [RESOLVED] [2005] can't get handle with FindWindowEx

    Quote Originally Posted by kleinma
    vbdotnetboy: if you leave out auto, the default is ansi, so using ansi, or leaving it out completely will do the same thing.

    You should read in the MSDN help about the difference between auto and ansi and you will see why it didn't work using auto.

    ok thanx kleinma... i knew i had to be something real easy that i was missing... but thanx for responding and helping me clear things up

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  7. #7
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Sector 001
    Posts
    1,577

    Re: [RESOLVED] [2005] can't get handle with FindWindowEx

    Quote Originally Posted by kleinma
    he isn't looking for a notepad instance though.. he is looking for a VB6 form instance with a specific caption.
    Ah oks then. If there are two forms with the same caption, will this return the handle of the firstly opened or the secondly opened? Or will it be a random choice?

    Thx.
    VB 2005, Win Xp Pro sp2

  8. #8

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    Re: [RESOLVED] [2005] can't get handle with FindWindowEx

    should be the first one in the stack... because it's going to start at desktop level and work it's way down until it finds a match.

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

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