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. 初步研究一下sourceTree

    今天研究sourceTree,在此小结一下 1.下载链接:https://www.atlassian.com/software/sourcetree 2.安装,注册账户登录,连接到GitHub账号上, ...

  2. HTML5 服务器推送事件(Server-sent Events)

    服务器推送事件(Server-sent Events)WebSocket 协议的一种服务器向客户端发送事件&数据的单向通讯.目前所有主流浏览器均支持服务器发送事件,当然除了 Internet ...

  3. 面向对象15.3String类-常见功能-判断

    /*3.判断 * 3.1两个字符串内容是否相同? * boolean equals(Object obj)(参数是Object,不是String,因为equals是覆盖Object里面的equals方 ...

  4. css中的层叠性及权重的比较

    假如同一个标签被多个选择器选中,每个选择器都设置了相同的样式,浏览器中加载时这个样式听谁的? 不同选择器设置的同一个样式,只会选择一个进行加载,不会叠加. 为了解决听谁的问题,引入层叠性的概念. 层叠 ...

  5. Socket通信中的 BeginReceive与EndReceive

    BeginReceive 与endReceive 必须成对出现,如果BeginReceive没有及时调用endReceive,可能会出现数据被从buffer中读取二次,如果在下面这行代码下面加入别的代 ...

  6. 使用apidoc根据JS文件生成接口文档

    1.安装nodejs.下载网址:http://www.nodejs.org: 2.安装apidoc.运行cmd,切换到nodejs的安装目录,在命令行输入: 1 npm install apidoc ...

  7. Extjs4+PHP MVC模式一(入门)

    Extjs是一个js框架,可以实现大部分web页面的东西,个人理解是一款集html.css.js一体的框架,功能挺强大的.结合PHP和sql可以实现整个系统.现在来说说怎么用它.(我的项目是用的TP框 ...

  8. 【转载】 ISO14229系列之二:诊断指令格式和相关概念

    转载链接:http://www.cnblogs.com/autogeek/p/4458658.html 1. 简单的通信机制 其实诊断通信的机制很简单,可以类比client-server通信方式,即客 ...

  9. JMeterPluginsCMD Command Line Tool

    There is small command-line utility for generating graphs out of JTL files. It behave just like righ ...

  10. jacoco统计Android手工测试覆盖率并自动上报服务器

    改进了几个点 1. 不用借助Instrumentation启动,正常启动即可: 2. 测试代码不用push到主分支,主分支代码拉到本地后用git apply patch方式合并覆盖率代码: 3. 测试 ...