How to Know the handle is for Window or control
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: How to Know the handle is for Window or control

  1. #1
    Join Date
    Nov 2002
    Location
    Chennai
    Posts
    80

    How to Know the handle is for Window or control

    Hi,

    I am having a Handle. The handle can be a handle to a control or a window. I want to see whether the handle is a handle to Control or a handle to window How can I do this. Is there any API for this?

    Regards

    Siva

  2. #2
    Join Date
    Aug 1999
    Location
    Germany
    Posts
    2,338
    A control is a window as well, but with a specific behavior (like an Edit-Control). You can use GetClassName to retrieve the class-name (for example "EDIT" for an edit-control) to see if your window-handle is some kind of control.

  3. #3
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940
    Generally speaking controls have no captions and windows do. You could provide this as your condition to find out.

    I.e.

    Code:
    if ((::GetWindowLong(hWnd, GWL_STYLE) & WS_CAPTION) != 0)
    {
        // I'm a window
    }
    else
    {
        // I'm a control
    }
    Darwen.

  4. #4
    Join Date
    Sep 2002
    Location
    14 39'19.65"N / 121 1'44.34"E
    Posts
    9,815
    Originally posted by darwen
    Generally speaking controls have no captions and windows do. You could provide this as your condition to find out.
    I'd be careful about that. There are many windows (just think of MFC CView windows or other embedded windows, like panes) which have no caption, and still aren't controls.

  5. #5
    Join Date
    Nov 2002
    Location
    Chennai
    Posts
    80
    You are correct gstercken, There are many windows which does not have caption. More over a window does not have a constant class name. For example a dialog have a class name "#3770", A MDI and SDI application have a dynamic classname starting with "Afx:"

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center