Jump to content

WinWindowFromID: Difference between revisions

From EDM2
No edit summary
No edit summary
 
Line 1: Line 1:
Searches the children of hwndParent to find a window whose identifier matches ulId.
This function returns the handle of the child window with the specified identity.


==Syntax==
== Syntax ==
  WinWindowFromID (hwndParent, ulId)
  WinWindowFromID(hwndParent, id)


==Parameters==
== Parameters ==
;hwndParent ([[HWND]]):Parent-window handle
;''hwndParent'' ([[HWND]]) - input: Parent-window handle.
;ulId (ULONG):Window identifier


It returns the window handle (HWND) if found, or [[NULLHANDLE]] otherwise.
;''id'' ([[ULONG]]) - input: Identity of the child window.
:It must be greater or equal to 0 and less or equal to 0xFFFF.
 
== Returns ==
;''hwnd'' ([[HWND]]) - returns: Window handle.
:NULLHANDLE: No child window of the specified identity exists.
:Other: Child-window handle.
 
== Remarks ==
To obtain the window handle for an item within a dialog box, set ''hwndParent'' to the dialog-box window's handle, and set ''id'' to the identity of the item in the dialog template.
 
== Errors ==
Possible returns from [[WinGetLastError]]
;PMERR_INVALID_HWND (0x1001)
:An invalid window handle was specified.
 
== Example Code ==
Declaration:
<pre>
#define INCL_WINWINDOWMGR /* Or use INCL_WIN, INCL_PM, */
#include &lt;os2.h&gt;
 
HWND     hwndParent;  /*  Parent-window handle. */
ULONG    id;          /*  Identity of the child window. */
HWND     hwnd;        /*  Window handle. */
 
hwnd = WinWindowFromID(hwndParent, id);
</pre>
This example calls WinWindowFromID to get the window handle of the system menu and calls WinSendMsg to send a message to disable the Close menu item.
<pre>
#define INCL_WINFRAMEMGR   /* for FID_ definitions. */
#define INCL_WINMENUS      /* for MIA_ definitions. */
#define INCL_WINWINDOWMGR
#include &lt;OS2.H&gt;
 
HWND hwndSysMenu, hwndDlg;
 
hwndSysMenu = WinWindowFromID(hwndDlg, FID_SYSMENU);
WinSendMsg(hwndSysMenu, MM_SETITEMATTR,
     MPFROM2SHORT(SC_CLOSE, TRUE),
     MPFROM2SHORT(MIA_DISABLED, MIA_DISABLED));
</pre>
 
== Related Functions ==
* [[WinEnableWindow]]
* [[WinIsThreadActive]]
* [[WinIsWindow]]
* [[WinIsWindowEnabled]]
* [[WinQueryDesktopWindow]]
* [[WinQueryObjectWindow]]
* [[WinQueryWindowDC]]
* [[WinQueryWindowProcess]]
* [[WinQueryWindowRect]]
* [[WinWindowFromDC]]
* [[WinWindowFromPoint]]


[[Category:Win]]
[[Category:Win]]
[[Category:WorkToDo]]

Latest revision as of 22:09, 15 May 2025

This function returns the handle of the child window with the specified identity.

Syntax

WinWindowFromID(hwndParent, id)

Parameters

hwndParent (HWND) - input
Parent-window handle.
id (ULONG) - input
Identity of the child window.
It must be greater or equal to 0 and less or equal to 0xFFFF.

Returns

hwnd (HWND) - returns
Window handle.
NULLHANDLE: No child window of the specified identity exists.
Other: Child-window handle.

Remarks

To obtain the window handle for an item within a dialog box, set hwndParent to the dialog-box window's handle, and set id to the identity of the item in the dialog template.

Errors

Possible returns from WinGetLastError

PMERR_INVALID_HWND (0x1001)
An invalid window handle was specified.

Example Code

Declaration:

#define INCL_WINWINDOWMGR /* Or use INCL_WIN, INCL_PM, */
#include <os2.h>

HWND     hwndParent;  /*  Parent-window handle. */
ULONG    id;          /*  Identity of the child window. */
HWND     hwnd;        /*  Window handle. */

hwnd = WinWindowFromID(hwndParent, id);

This example calls WinWindowFromID to get the window handle of the system menu and calls WinSendMsg to send a message to disable the Close menu item.

#define INCL_WINFRAMEMGR   /* for FID_ definitions. */
#define INCL_WINMENUS      /* for MIA_ definitions. */
#define INCL_WINWINDOWMGR
#include <OS2.H>

HWND hwndSysMenu, hwndDlg;

hwndSysMenu = WinWindowFromID(hwndDlg, FID_SYSMENU);
WinSendMsg(hwndSysMenu, MM_SETITEMATTR,
     MPFROM2SHORT(SC_CLOSE, TRUE),
     MPFROM2SHORT(MIA_DISABLED, MIA_DISABLED));

Related Functions