如何得到当前窗口的句柄?

ruchimy 2005-09-16 10:50:41
任何时刻,只有一个当前窗口,那如何得到它的句柄.当前窗口可能不是本进程的窗口.GetActiveWindow行不通吧?
...全文
417 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
社会栋梁 2005-09-18
  • 打赏
  • 举报
回复
GetTopWindow
legendhui 2005-09-17
  • 打赏
  • 举报
回复
GetWindow
The GetWindow function retrieves a handle to a window that has the specified relationship (Z order or owner) to the specified window.

HWND GetWindow(
HWND hWnd, // handle to original window
UINT uCmd // relationship flag
);

Parameters
hWnd
Handle to a window. The window handle retrieved is relative to this window, based on the value of the uCmd parameter.
uCmd
Specifies the relationship between the specified window and the window whose handle is to be retrieved. This parameter can be one of the following values: Value Meaning
GW_CHILD The retrieved handle identifies the child window at the top of the Z order, if the specified window is a parent window; otherwise, the retrieved handle is NULL. The function examines only child windows of the specified window. It does not examine descendant windows.
GW_ENABLEDPOPUP Windows NT 5.0 and later: The retrieved handle identifies the enabled popup window owned by the specified window (the search uses the first such window found using GW_HWNDNEXT); otherwise, if there are no enabled popup windows, the retrieved handle is that of the specified window.
GW_HWNDFIRST The retrieved handle identifies the window of the same type that is highest in the Z order. If the specified window is a topmost window, the handle identifies the topmost window that is highest in the Z order. If the specified window is a top-level window, the handle identifies the top-level window that is highest in the Z order. If the specified window is a child window, the handle identifies the sibling window that is highest in the Z order.
GW_HWNDLAST The retrieved handle identifies the window of the same type that is lowest in the Z order. If the specified window is a topmost window, the handle identifies the topmost window that is lowest in the Z order. If the specified window is a top-level window, the handle identifies the top-level window that is lowest in the Z order. If the specified window is a child window, the handle identifies the sibling window that is lowest in the Z order.
GW_HWNDNEXT The retrieved handle identifies the window below the specified window in the Z order. If the specified window is a topmost window, the handle identifies the topmost window below the specified window. If the specified window is a top-level window, the handle identifies the top-level window below the specified window. If the specified window is a child window, the handle identifies the sibling window below the specified window.
GW_HWNDPREV The retrieved handle identifies the window above the specified window in the Z order. If the specified window is a topmost window, the handle identifies the topmost window above the specified window. If the specified window is a top-level window, the handle identifies the top-level window above the specified window. If the specified window is a child window, the handle identifies the sibling window above the specified window.
GW_OWNER The retrieved handle identifies the specified window's owner window, if any.

legendhui 2005-09-17
  • 打赏
  • 举报
回复
GetForegroundWindow
The GetForegroundWindow function returns a handle to the foreground window (the window with which the user is currently working). The system assigns a slightly higher priority to the thread that creates the foreground window than it does to other threads.

HWND GetForegroundWindow(VOID)

legendhui 2005-09-17
  • 打赏
  • 举报
回复
GetTopWindow
The GetTopWindow function examines the Z order of the child windows associated with the specified parent window and retrieves a handle to the child window at the top of the Z order.

HWND GetTopWindow(
HWND hWnd // handle to parent window
);

Parameters
hWnd
Handle to the parent window whose child windows are to be examined. If this parameter is NULL, the function returns a handle to the window at the top of the Z order.
i_noname 2005-09-16
  • 打赏
  • 举报
回复
HWND hwnd = ::GetTopWindow(NULL);
whitening 2005-09-16
  • 打赏
  • 举报
回复
用EnumProcess枚举所有进程
2021‘someday 2005-09-16
  • 打赏
  • 举报
回复
好像有个函数吧!
wxwxiaofeng 2005-09-16
  • 打赏
  • 举报
回复
GetSafeHwnd()

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧