Results 1 to 1 of 1

Thread: Classic VB/API - What is a window handle (hWnd) and what is it used for?

Threaded View

  1. #1

    Thread Starter
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Arrow Classic VB/API - What is a window handle (hWnd) and what is it used for?

    A window handle (usually shortened to hWnd) is a unique identifer that Windows assigns to each window created. By window in this case we are referring to everything from command buttons and textboxes, to dialog boxes and full windows.

    The window handle is used in APIs as the sole method of identifying a window. It is a Long (4 byte) value and you can get the handle for forms and almost all controls in Visual Basic by using the .hWnd property.

    A form's .hWnd property

    For those that don't have a .hWnd property, or windows outside your application, see "How can I find a window outside my program?".

    You can use the hWnd for all operations involving windows. Most of these are encapsulated by Visual Basic as methods and properties, however there are a few that aren't (and this number will only increase as Windows is updated and VB isn't) such as alpha-blending (layering), sending messages (SendMessage/PostMessage), making a window always on top, etc.

    For a demonstration of many of the things you can do if you know a window's handle, check out my CWindows+CWindow classes in the Codebank, which encapsulates a lot of this functionality into two easy to use classes and shows you how to use the window-related APIs.
    Last edited by penagate; Feb 17th, 2006 at 03:40 AM.

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