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. 刨根究底字符编码之十四——UTF-16究竟是怎么编码的

    UTF-16究竟是怎么编码的 1. 首先要注意的是,代理Surrogate是专属于UTF-16编码方式的一种机制,UTF-8和UTF-32是不用代理的. 如前文所述,为了让UTF-16能继续编码基本平 ...

  2. Mysql连接出错问题

    1.java 提示:java.lang.ClassNotFoundException: com.mysql.jdbc.Driver 处理:导入mysql-connector-java-5.1.7-bi ...

  3. java开发必读 书单

    希望读的书单 重构 改善既有代码的设计 设计模式 可复用面向对象软件的基础 高性能MySQL第3版 Effective Java第1版 Effective Java第2版 Java核心技术I-基础知识 ...

  4. 用CSS的border画三角形

    用border画三角形,实际上属于一种奇淫巧技. 利用的是border的一个特性:当一个元素的宽高都为0时,给border设置宽度(至少给2个相邻的边框设置宽度),border就会撑开这个元素. 四个 ...

  5. mac下,mysql5.7.18连接出错,错误信息为:Access denied for user 'root'@'localhost' (using password: YES)

    mac下,mysql5.7.18连接出错,错误信息为:Access denied for user 'root'@'localhost' (using password: YES)()里面的为shel ...

  6. Delphi Screen.DataModuleCount 总是返回 0!Delphi 的 Bug? DataModuleCount = 0

         今天遇到一个很隐蔽的 Delphi 问题,不知做了什么,有一个功能总是不能使用,后来跟踪以下发现是因为 Screen.DataModuleCount 总是返回 0,而程序中一个函数正好要用到 ...

  7. FreeRTOS——错误排查

    1. printf-stdarg.c 在调用标准库函数时,栈空间的用量可能急剧上升,特别是IO与字符串处理函数,比如 sprintf(). 在FreeRTOS下载包中有一个名为printf-stdar ...

  8. SignalR在ASP.NET MVC中的应用

    一.简介 ASP.NET SignalR 是为 ASP.NET 开发人员提供的一个库,可以简化开发人员将实时 Web 功能添加到应用程序的过程.实时 Web 功能是指这样一种功能:当所连接的客户端变得 ...

  9. HDOJ-2006求奇数的乘积

    Problem Description 给你n个整数,求他们中所有奇数的乘积.   Input 输入数据包含多个测试实例,每个测试实例占一行,每行的第一个数为n,表示本组数据一共有n个,接着是n个整数 ...

  10. 【流量】netflow 基础知识

    摘要 记录下关于netflow的基础知识以及应用,现状 是什么 一种数据交换方式,NetFlow流量统计数据包括数据流时戳 源IP地址和目的IP地址 源端口号和目的端口号 输入接口号和输出接口号 下一 ...