GetActiveWindow与GetForegroundWindow两者有何区别? - VC/MFC / 资源

来源:百度文库 编辑:神马文学网 时间:2024/04/27 23:10:41
发表于:2007-08-17 11:34:27 来自MSDN:
    The   active   window   is   either   the   window   that   has   the   current   input   focus   or   the   window   explicitly   made   active   by   the   SetActiveWindow   member   function  
    The   foreground   window   applies   only   to   top-level   windows(frame   windows   or   dialog   boxes).
     
      网上有人说:
GetActiveWindow()   是你的程序的当前激活的窗口。
GetForegroundWindow()   是整个Windows系统的当前激活的窗口。
     
      我自己仍然有点不明白,当期窗口不就是当前激活的窗口吗?大家来讨论下。
  • 对我有用[0]
  • 丢个板砖[1]
  • 引用
  • 举报
  • 管理
  • TOP
回复次数:7
  • benkaoya
  • 等 级:
#1楼 得分:0回复于:2007-08-17 14:34:00 The   SetActiveWindow   function   activates   a   window,   but   not   if   the   application   is   in   the   background.   The   window   will   be   brought   into   the   foreground   —   the   top   of   z-order   —   if   the   application   is   in   the   foreground   when   it   sets   the   activation.  
        The   SetForegroundWindow   window   function,   on   the   other   hand,   activates   a   window   and   forces   it   into   the   foreground.   An   application   should   only   call   SetForegroundWindow   if   it   needs   to   display   critical   errors   or   information   that   needs   the   user 's   immediate   attention.  
        看了这个有点明白了,SetActiveWindow函数只有激活最前面的那个窗口(foreground     ——   the   top   of   z-order)才能使该窗口为当前窗口。而SetForegroundWindow强迫设置窗口为最前面的窗口并激活它使它成为当前窗口。 SetForegroundWindow包含有SetActiveWindow的激活功能。我这样分析对否?

  • 对我有用[0]
  • 丢个板砖[0]
  • 引用
  • 举报
  • 管理
  • TOP
精华推荐:如何对被遮盖的窗口截图
  • TalentLi
  • (总有一天不再菜)
  • 等 级:
#2楼 得分:0回复于:2007-11-03 15:53:52 最前的窗口不一定是激活的...比如说qq的主窗口,只要不靠到屏幕边上,就是总在最前的,你拖放一个ie过 去是挡不住的,这时候,你用GetActiveWindow得到的是有焦点的ie窗口,用GetForegroundWindow得到的是qq的窗口,不 知道我的描述你能否理解,呵呵
  • 对我有用[1]
  • 丢个板砖[0]
  • 引用
  • 举报
  • 管理
  • TOP
精华推荐:如何让程序在系统启动前,启动时运行。并且让其它软件在程序执行完成后才执行
  • lhy2199
  • (清茶几许)
  • 等 级:
#3楼 得分:0回复于:2009-12-15 11:31:15 有道理
  • 对我有用[0]
  • 丢个板砖[0]
  • 引用
  • 举报
  • 管理
  • TOP
精华推荐:C/C++预处理 ISO/ANSI C标准译文与注解
  • mynote
  • (户中文)
  • 等 级:
#4楼 得分:0回复于:2009-12-22 15:49:36 哦,都被你们讨论完了,我没话可说。
  • 对我有用[0]
  • 丢个板砖[0]
  • 引用
  • 举报
  • 管理
  • TOP
精华推荐:在一家小公司做VC++一年多待遇不到3K支撑我坚持这么久的信念就是有一个相对宽松的环境可以学习
  • jiereliyi
  • (别老气我~!)
  • 等 级:
#5楼 得分:0回复于:2009-12-24 17:24:20 这人不地道
  • 对我有用[0]
  • 丢个板砖[0]
  • 引用
  • 举报
  • 管理
  • TOP
精华推荐:3流大学学生,工作两年的感想。
  • cst_zf
  • 等 级:
#6楼 得分:0回复于:2010-06-17 18:12:31 GetActiveWindow Function

Retrieves the window handle to the active window attached to the calling thread's message queue.
Syntax
Copy

HWND WINAPI GetActiveWindow(void);


Parameters
This function has no parameters.
Return Value

HWND

The return value is the handle to the active window attached to the calling thread's message queue. Otherwise, the return value is NULL.
Remarks

To get the handle to the foreground window, you can use GetForegroundWindow.

To get the window handle to the active window in the message queue for another thread, use GetGUIThreadInfo.
  • 对我有用[0]
  • 丢个板砖[0]
  • 引用
  • 举报
  • 管理
  • TOP
  • cst_zf
  • 等 级:
#7楼 得分:0回复于:2010-06-17 18:13:04 GetActiveWindow只返回本线程的,GetForegroundWindow返回整个系统的。