SetWindowPos和SetForegroundWindow

时间:2021-08-08 08:30:36

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-&gt ...

  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&colon; SetWindowPos改变窗口的位置与状态

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

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

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

  9. SetWindowPos,RegisterHotKey,GlobalAddAtom的用法

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

随机推荐

  1. 集合迭代器快速失败行为及CopyOnWriteArrayList

    以下内容基于jdk1.7.0_79源码: 什么是集合迭代器快速失败行为 以ArrayList为例,在多线程并发情况下,如果有一个线程在修改ArrayList集合的结构(插入.移除...),而另一个线程 ...

  2. BZOJ1946 &colon; &lbrack;Ceoi2006&rsqb;ANTENNA

    首先通过随机增量法求出最小覆盖圆,作为答案的上界. 然后二分答案,检验的时候枚举每个点作为原点,求出其他每个点被包括在圆内的角度区间,然后扫描线即可. 时间复杂度$O(Tn^2\log n)$. #i ...

  3. 移动端H5---页面适配问题详谈(一)

    一.前言 昨天唠叨了哈没用的,今天说点有用的把.先说一下响应式布局吧,我一直认为响应式布局的分项目,一下布局简单得项目做响应式还是可以可以得.例如博客.后台管理系统等.但是有些会认为响应式很牛逼,尤其 ...

  4. 20141103--SQL主键,外键

    设置主键: 右键表→设计,在需要的列上右键→设置主键 或者在创建表的时候,在想要作为索引的列后面加上 primary key create table biao3 ( [No.] int primar ...

  5. POJ 2584 T-Shirt Gumbo &lpar;二分图多重最大匹配&rpar;

    题意 现在要将5种型号的衣服分发给n个参赛者,然后给出每个参赛者所需要的衣服的尺码的大小范围,在该尺码范围内的衣服该选手可以接受,再给出这5种型号衣服各自的数量,问是否存在一种分配方案使得每个选手都能 ...

  6. SQL中declare申明变量

    在sql语句中加入�变量. declare @local_variable data_type 声明时须要指定变量的类型, 能够使用set和select对变量进行赋值, 在sql语句中就能够使用@lo ...

  7. VIM 同义词

    vim-online-thesaurus A Vim plugin for looking up words in an online thesaurus, Now thesaurus.com 一.原 ...

  8. ODI利用goldengate实现增量数据捕获

    ODI利用goldengate实现增量数据捕获 上个月,Oracle发布了ODI的最新版本10.1.3.6_02,其中增加了针对采用goldengate获取源数据库增量变化的知识模块,这样当系统需要实 ...

  9. protobuf c&plus;&plus; API

    1.在.proto文件中定义消息格式 2.使用protobuf编译器 3.使用c++ api来读写消息   0.为何使用protobuf?   1.原始内存数据结构,可以以二进制方式sent/save ...

  10. CodeChef Cards&comma; bags and coins &lbrack;DP 泛型背包&rsqb;

    https://www.codechef.com/problems/ANUCBC n个数字,选出其一个子集.求有多少子集满足其中数字之和是m的倍数.n $\le$ 100000,m $\le$ 100 ...