There are many closely-related concepts involved, and related terms are often misused, even in the official documentation.

Important types of windows:

  • top-level windows:  Windows that have no parent window.  The main window for an application is almost always a top-level window.  It does not have anything to do with z-order.

  • child windows:  Windows that are contained by a parent window.  Their position is always relative to the parent widow's area.  Child windows are often "controls":  UI things like buttons and edit boxes.

  • parent windows:  Windows that have child windows.  Top-level windows often have children.  But note that child windows may also have children and thus be both parent and child windows.

  • owned windows:  Windows that are controlled by a another window, but aren't necessarily children of the other window.  An example is a floating tool palette: it's owned by another window in the application, but it's not locked to that other window's area.

  • owner windows:  Windows that own an owned window.

Often the distinction between an owner/owned relationship and a parent/child relationship isn't important, so the parent and child terms are often used for both contexts, even in documentation.  In some cases, parent fields and parameters are overloaded to mean parent and/or owner.

Important concepts:

  • top of the z-order:  This literally means the window that displays above other windows.

  • active window:  A fuzzy concept, but it typically means the top-level window the user would consider the "current" window.  The active window is typically drawn with a distinctive border and its tile on the task bar is highlighted.  The active window is usually at or near to the top of the z-order among all other top-level windows, and it is the parent or owner (perhaps indirectly) of the window with keyboard focus.

  • keyboard focus:  Indicates the window that will receive the keyboard messages.  Conceptually, there is one window with keyboard focus.  Often the window with focus is a child (or grandchild, etc.) of the active window.

  • foreground:  The active window is typically in the foreground.  The name seems to suggest that it's at the top of the z-order, but it really means that the thread that created the window gets a slight priority boost.  That active window is usually also the foreground window.

So let's say you've got this browser window open, and you've also got an instance of Notepad running.  If you click on the document in Notepad, a whole flurry of messages and state changes occur.  You're actually clicking on a big edit box, which is a child window of Notepad's top-level window.  That click causes the edit box to get activated, but child windows can't really be the "active" window, so it just takes the keyboard focus and passes the activation message up through its ancestors until it gets to a top-level window.  The top-level window "activates" by moving to the top of the z-order, highlighting its border, etc.  It also becomes the foreground window, so its thread gets a little boost to make the UI a little more responsive than any other windows.

With these terms in mind, you can parse the MSDN descriptions for the functions you listed to tease out the subtle differences.

If you're trying to lay out your window's children, just use SetWindowPos (or MoveWindow, SizeWindow, and ShowWinow).  Of the remaining functions, SwitchToThisWindow looks deprecated and essentially the same as SetForegroundWindow.  (Note that, in many cases, SetForegroundWindow won't do what you want unless you're the active application or the active application has given you permission to use it.)  BringWindowToTop is mostly about bringing a window to the top of the z-order (which you can do with SetWindowPos), with extra side effects that make it behave like SetForegroundWindow if you call it on a top-level window.

SetWindowPos和SetForegroundWindow的更多相关文章

  1. (C++)窗口置前SetForegroundWindow(pThis->hwndWindow);

    一段代码主要是创建一个Window,然后将其置顶显示.奇怪的是这个功能有时候无效. pThis->bWindowDisplayed = SetForegroundWindow(pThis-> ...

  2. BringWindowToTop(), SetForegroundWindow(), SetActiveWindow()

    1. SetActiveWindow() 原型: <span style="font-size:14px;">CWnd* SetActiveWindow(); HWND ...

  3. 将窗口置顶的方法:SetWindowPos、AttachThreadInput、SwitchToThisWindow

    将窗口置顶的方法:SetWindowPos.AttachThreadInput.SwitchToThisWindow [转]http://hi.baidu.com/neil_danky/item/f9 ...

  4. SetWindowPos 和Z序

    参考文档:http://www.cnblogs.com/findumars/p/3948315.html SetWindowPos(hWnd: HWND; {窗口句柄}hWndInsertAfter: ...

  5. AdjustWindowRect 与 SetWindowPos

    这两个函数经常一起使用,所以放到一起讲: 1 AdjustWindowRect 函数功能:该函数依据所需客户矩形的大小,计算需要的窗口矩形的大小.计算出的窗口矩形随后可以传递给CreateWindow ...

  6. MFC 的SetWindowPos 用法

    转自于:http://hi.baidu.com/max_new/blog/item/e2bbe607b1f127c57b8947c0.html 许多软件,特别是占桌面面积不是很大的软件,通常都提供了一 ...

  7. delphi API: SetWindowPos改变窗口的位置与状态

    SetWindowPos 函数功能:该函数改变一个子窗口,弹出式窗口式顶层窗口的尺寸,位置和Z序.子窗口,弹出式窗口,及顶层窗口根据它们在屏幕上出现的顺序排序.顶层窗口设置的级别最高,并且被设置为Z序 ...

  8. SetForegroundWindow以及 如何将一个某个窗口提到最顶层(转)

    http://hi.baidu.com/gookings/item/2b7912ca8d5b3625a0b50aa2 SetForegroundWindow 函数功能:该函数将创建指定窗口的线程设置到 ...

  9. SetWindowPos,RegisterHotKey,GlobalAddAtom的用法

    还以为SetWindowPos是给Frm的子框架间编写的,原来是给mainfrm写的,可以把你写的主窗口置顶,置底(看样子应该可以变成桌面了,还没试呢,才忙到现在...) 子窗口的遮挡可以使用窗口的样 ...

随机推荐

  1. C/C++中对链表操作的理解&&实例分析

    链表概述 链表是一种常见的重要的数据结构.它是动态地进行存储分配的一种结构.它可以根据需要开辟内存单元.链表有一个“头指针”变量,以head表示,它存放一个地址.该地址指向一个元素.链表中每一个元素称 ...

  2. Unity3D-Shader-热扭曲效果

    [旧博客转移 - 2016年1月13日 13:18 ] 前面的话: 本来我是想写一个水的原理的,但是发现涉及的知识太多,还有好多不懂的,所以就先一步一步来 最近呢,我在网上捡到了一本<热扭曲秘籍 ...

  3. 使用 electron 做个播放器

    使用 electron 做个播放器 本文同步更新在:https://github.com/whxaxes/blog/issues/8 前言 虽然 electron 已经出来好长时间了,但是最近才玩了一 ...

  4. TCP错误恢复特性之一TCP重传

    TCP的错误恢复特性是我们用来定位.诊断并最终修复网络高延迟的最好工具. 常见的TCP错误恢复特性有:TCP重传.TCP重复确认和快速重传 1. TCP重传: 重传数据包是TCP最基本的错误恢复特性之 ...

  5. git分支的使用

    本文章假定你已经接触了一些git的基本概念和基本的操作知识 这里先贴出关于分支的一些常用命令 git branch /*查看所有分支*/git branch <branch-name> / ...

  6. Java 用Freemarker完美导出word文档(带图片)

    Java  用Freemarker完美导出word文档(带图片) 前言 最近在项目中,因客户要求,将页面内容(如合同协议)导出成word,在网上翻了好多,感觉太乱了,不过最后还是较好解决了这个问题. ...

  7. angularjs初窥门径

    貌似angularjs出来之后网上各种夸angularjs的好黑jquery. angularjs大致可以分为几个板块:作用域,控制器,指令(主要),路由,依赖注入. 1 作用域 作用域在angula ...

  8. (转)如何在maven的pom.xml中添加本地jar包

    1 maven本地仓库认识 maven本地仓库中的jar目录一般分为三层:图中的1 2 3分别如下所示: 1 groupId 2 artifactId 3 version 4 jar包的依赖 如果要将 ...

  9. 小白读iOS冗余资源扫描脚本

    随着公司项目的不断功能迭代,项目的体积越来越大,各种瘦身策略迫在眉睫.由于平时使用Linux高级命令和 shell脚本的机会不多,之前学的知识一下子想起来很难.所有趁着这次看脚本,重新温习一下. 本文 ...

  10. tomcat 与 java web中url路径的配置以及使用规则详情(长期更新)

    首先我们看一下在myeclipse中建立的java web项目的结构 在这里我们需要注意这个webroot也就是我们在tomcat里的webapp里面的应用 之所以每一个项目都有这个webroot,是 ...