The Window's Real Estate

 

Application's Instance

 

A window is referred to as parent when it can be used to host, hold, or carry other windows. For examples, when the computer starts, it draws its main screen, also called the desktop, which occupies the widest area that the monitor screen can offer. This primary window becomes the host of all other window that will display as long as the computer is own. This desktop is also a complete window in its own right. As mentioned already, to get its handle, you can call the GetDesktopWindow() function.

After the desktop has been created, a window of yours can display if the user starts your application. This means that an application must have been created for the user to use it. When the user opens an application, we also say that the application has been instantiated or an instance of the application has been created. Based on this, any time you create an application, you must provide an instance of it. This allows the operating system to manage your application with regards to its interaction with the user and also its relationship with other resources. Therefore, you must always create an instance for your application. This is taken care of by the first argument of the WinMain() function.

If an application has already been created, to get its instance, you can call theGetWindowLong() function. Its syntax is:

  1. <span style="font-family:Comic Sans MS;">LONG GetWindowLong(HWND hWnd, int nIndex);</span>

Although this function is used for many other reasons, it can also help you get the instance of an application. To do this, pass the first argument as the handle to a window of the application you are examining and pass the second argument as GWL_HINSTANCE.

Window Parenting

 

There are two types of windows or object you will deal with in your applications. The type referred to here is defined by the relationship a window has with regards to other windows that are part of an application:

  • Parent: a window is referred to as a parent when there are, or there can be, other windows that depend on it. For example, the toolbar of your browser is equipped with some buttons. The toolbar is a parent to the buttons. When a parent is created, it "gives life" to other windows that can depend on it.
  • Child: A window is referred to as child when its existence and especially its visibility depend on another window called its parent.

When a parent is created, made active, or made visible, it gives existence and visibility to its children. When a parent gets hidden, it also hides its children. If a parent moves, it moves with its children. The children keep their positions and dimensions inside the parent. When a parent is destroyed, it also destroys its children (sometimes it does not happen so smoothly; a parent may make a child unavailable but the memory space the child was occupying after the parent has been destroyed may still be in use, sometimes filled with garbage, but such memory may not be available to other applications until you explicitly recover it).

Child controls depend on a parent because the parent "carries", "holds", or hosts them. All of the Windows controls you will use in your applications are child controls. A child window can also be a parent of another control. For example, a toolbar of the browser is the parent of the buttons on it. If you close or hide the toolbar, its children disappear. At the same time, the toolbar is a child of the application's frame. If you close the application, the toolbar disappears, along with its own children. In this example, the toolbar is a child of the frame but is a parent to its buttons.

After initializing an application with either the WNDCLASS, or the WNDCLASSEX structure and registering it, as we have done so far, you must create the primary parent of all objects of your class. This is usually done with either the CreateWindow() or the CreateWindowEx()function. Here is an example:

  1. <span style="font-family:Comic Sans MS;">HWND hWndParent;
  2. // Create the parent window
  3. hWndParent = CreateWindowEx(0, ClassName, StrWndName,
  4. WS_OVERLAPPEDWINDOW,
  5. 0, 100, 140, 320,
  6. NULL, NULL, hInstance, NULL);</span>

A Window's Childhood

 

After creating the main window, you can use it as a parent for other windows. To specify that a window is a child of another window, when creating it with either the CreateWindow() or the CreateWindowEx() function, pass the handle of the parent as the hWndParent argument. Here is an example:

  1. <span style="font-family:Comic Sans MS;">// Create a window
  2. CreateWindowEx(0, WndClassName, CaptionOrText,
  3. ChildStyle, Left, Top, Width, Height,
  4. hWndParent, NULL, hInstance, NULL);</span>

If a window is a child of another window, to get a handle to its parent, you can call theGetParent() function. Its syntax is:

HWND GetParent(HWND hWnd);

The hWnd argument is a handle to the child window whose parent you want to find out. Alternatively, you can also use the GetWindowLong() function, passing the second argument as GWL_HWNDPARENT, to get a handle to the parent of a window.

The Borders of a Window

 

To distinguish a particular window from the other objects on a screen, a window can be defined by surrounding borders on the left, the top, the right, and the bottom. One of the effects the user may want to control on a window is its size. For example, the user may want to narrow, enlarge, shrink, or heighten a window. To do this, a user would position the mouse on one of the borders, click and drag in the desired direction. This action is referred to as resizing a window. For the user to be able to change the size of a window, the window must have a special type of border referred to as a thick frame. To provide this border, apply or add theWS_THICKFRAME style:

  1. <span style="font-family:Comic Sans MS;">CreateWindow(ClsName, WndName,
  2. WS_VISIBLE | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME);</span>

Because many windows will need this functionality, a special style can combine them and it is called WS_OVERLAPPEDWINDOW. Therefore, you can create a resizable window as follows:

CreateWindow(ClsName, WndName, WS_OVERLAPPEDWINDOW,

Window's Location and Size

 

The location of a window is defined by the distance from the left border of the monitor to the window's left border and its distance from the top border of the monitor to its own top border. The size of a window is its width and its height. These can be illustrated for a main window frame as follows:

For a Win32 application, the original distance from the left border of the monitor is passed as the x argument to the CreateWindow() or the CreateWindowEx() function. The distance from top is specified using the y argument. The x and y arguments define the location of the window. The distance from the left border of the monitor to the right border of the window is specified as the nWidth argument. The distance from the top border of the monitor to the lower border of the window is specified with the nHeight value.

If you cannot make up your mind for these four values, you can use the CW_USEDEFAULT(when-Creating-the-Window-USE-the-DEFAULT-value) constant for either one or all four arguments. In such a case, the compiler would select a value for the argument. Here is an example:

  1. <span style="font-family:Comic Sans MS;">INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  2. LPSTR lpCmdLine, int nCmdShow)
  3. {
  4. WNDCLASSEX WndClsEx;
  5. . . .
  6. RegisterClassEx(&WndClsEx);
  7. HWND hWnd = CreateWindow(ClsName,
  8. WndName,
  9. WS_OVERLAPPEDWINDOW,
  10. CW_USEDEFAULT,
  11. CW_USEDEFAULT,
  12. CW_USEDEFAULT,
  13. CW_USEDEFAULT,
  14. return 0;
  15. }
  16. </span>

Displaying the Window

 

Once a window has been created and if this was done successfully, you can display it to the user. This is done by calling the ShowWindow() function. Its syntax is:

  1. <span style="font-family:Comic Sans MS;">BOOL ShowWindow(HWND hWnd, int nCmdShow);</span>

The hWnd argument is a handle to the window that you want to display. It could be the window returned by the CreateWindow() or the CreateWindowEx() function.

The nCmdShow specifies how the window must be displayed. Its possible values are:

  Value Description
  SW_SHOW Displays a window and makes it visible
  SW_SHOWNORMAL Displays the window in its regular size. In most circumstances, the operating system keeps track of the last location and size a window such as Internet Explorer or My Computer had the last time it was displaying. This value allows the OS to restore it.
  SW_SHOWMINIMIZED Opens the window in its minimized state, representing it as a button on the taskbar
  SW_SHOWMAXIMIZED Opens the window in its maximized state
  SW_SHOWMINNOACTIVE Opens the window but displays only its icon. It does not make it active
  SW_SHOWNA As previous
  SW_SHOWNOACTIVATE Retrieves the window's previous size and location and displays it accordingly
  SW_HIDE Used to hide a window
  SW_MINIMIZE Shrinks the window and reduces it to a button on the taskbar
SW_MAXIMIZE Maximizes the window to occupy the whole screen area
  SW_RESTORE If the window was minimized or maximized, it would be restored to its previous location and size

To show its presence on the screen, the window must be painted. This can be done by calling the UpdateWindow() function. Its syntax is:

  1. <span style="font-family:Comic Sans MS;">BOOL UpdateWindow(HWND hWnd);</span>

This function simply wants to know what window needs to be painted. This window is specified by its handle. Here is an example:

  1. <span style="font-family:Comic Sans MS;">INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  2. LPSTR lpCmdLine, int nCmdShow)
  3. {
  4. WNDCLASSEX WndClsEx;
  5. . . .
  6. RegisterClassEx(&WndClsEx);
  7. HWND hWnd = CreateWindow(ClsName, WndName, WS_OVERLAPPEDWINDOW,
  8. CW_USEDEFAULT, CW_USEDEFAULT,
  9. CW_USEDEFAULT, CW_USEDEFAULT,
  10. NULL, NULL, hInstance, NULL);
  11. if( !hWnd ) // If the window was not created,
  12. return 0; // stop the application
  13. ShowWindow(hWnd, SW_SHOWNORMAL);
  14. UpdateWindow(hWnd);
  15. return 0;
  16. }
  17. </span>

The Multiple Document Interface (MDI)

 

Introduction

 

A multiple document is the type of application that uses a main, external window that acts as a frame and hosts other, floating window that act as its children. This concept allows the user to open more than one document at a time in an application, making it possible to switch from one document to another without closing the application.

MDI Application Creation

 

You start an MDI like the types of applications we have created so far. One of the primary differences is that the window procedure must return the DefFrameProc() function. Its syntax is:

  1. <span style="font-family:Comic Sans MS;">LRESULT DefFrameProc(HWND hWnd,
  2. HWND hWndMDIClient,
  3. UINT uMsg,
  4. WPARAM wParam,
  5. LPARAM lParam);</span>
转载自:http://www.functionx.com/win32/Lesson08.htm
http://blog.csdn.net/x356982611/article/details/9352499

Types of Windows的更多相关文章

  1. windows消息机制详解(转载)

    消息,就是指Windows发出的一个通知,告诉应用程序某个事情发生了.例如,单击鼠标.改变窗口尺寸.按下键盘上的一个键都会使Windows发送一个消息给应用程序.消息本身是作为一个记录传递给应用程序的 ...

  2. How to Fix Missing TortoiseSVN File Status Icons in Windows

    For many Windows-based developers, Subversion and TortoiseSVN is a great source control solution. It ...

  3. windows窗口分析,父窗口,子窗口,所有者窗口

    (本文尝试通过一些简单的实验,来分析Windows的窗口机制,并对微软的设计理由进行一定的猜测,需要读者具备C++.Windows编程及MFC经验,还得有一定动手能力.文中可能出现一些术语不统一的现象 ...

  4. [虾扯蛋] android界面框架-Window

    从纯sdk及framwork的角度看,android中界面框架相关的类型有:Window,WindowManager,View等.下面就以这几个类为出发点来概览下安卓开发的"界面架构&quo ...

  5. PL/SQL常用设置 可看引用位置更清晰直观 引自:http://blog.csdn.net/xiaoqforever/article/details/27695569

    引自:http://blog.csdn.net/xiaoqforever/article/details/27695569 1,登录后默认自动选中My Objects 默认情况下,PLSQL Deve ...

  6. Getting Text Metrics in Firemonkey(delphiscience的博客)

    Firemonkey’s abstract TCanvas class has been providing the dimensions of the bounding rectangle of s ...

  7. WindowManager.LayoutParams的探究

    上次在子线程更新UI时用了一下WindowManager.LayoutParams,当时觉得不太顺手.以前都是用空参构造器,这次用了type和flag属性,出现了意想不到的效果.也看看源码吧,多锻炼锻 ...

  8. SetWindowPos和SetForegroundWindow

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

  9. wxWidgets与其它GUI工具库比较

    WxWidgets Compared To Other Toolkits   Some general notes: wxWidgets not only works for C++, but als ...

随机推荐

  1. docker 学习手冊-中文版下载

    这个PDF算是学习docker的一个小总结,全部文章摘自我在csdn的博客专栏: http://blog.csdn.net/column/details/docker.html 第一章到第八章摘自do ...

  2. UVA 718 - Skyscraper Floors(数论)

    UVA 718 - Skyscraper Floors 题目链接 题意:在一个f层高的楼上,有e个电梯,每一个电梯有x,y表示y + k * x层都能够到,如今要问从a层是否能到达b层(中间怎么换乘电 ...

  3. 复合文档的二进制存储格式研究[ole存储结构](word,xls,ppt...)[转]

    复合文档文件格式研究   前 言 复合文档(Compound Document) 是一种不仅包含文本而且包括图形.电子表格数据.声音.视频图象以及其它信息的文档.可以把复合文档想象成一个所有者,它装着 ...

  4. 利用FFT 计算生成离散解析信号

    通常我们用到的信号都是实值信号,但是我们可以根据这个实信号构造出一个复信号,使得这个复信号只包含正频率部分,而且这个复信号的实部正好就是我们原来的实值信号.简单的推导可知,复信号的虚部是原信号的希尔伯 ...

  5. iPhone5C三大看点:性能不输iPhone5 或售3399元

    乐杨俊编辑修改转载: iPhone 5C的发售时间或最早在9月18日,抢在中秋节前:最迟至国庆十一假期期间. [IT商业新闻网综合讯](记者 林涛)苹果2013年秋季发布会还有几个小时即将开幕,除了i ...

  6. EasyUI - DataGrid 组建 - [ 新增功能 ]

    效果: html代码: <div> <!--使用JS加载方式--> <table id="tab"></table> <!-- ...

  7. SPSS Modeler数据挖掘项目实战(数据挖掘、建模技术)

    SPSS Modeler是业界极为著名的数据挖掘软件,其前身为SPSS Clementine.SPSS Modeler内置丰富的数据挖掘模型,以其强大的挖掘功能和友好的操作习惯,深受用户的喜爱和好评, ...

  8. WEB相关协议

    1.数据链路层 2.网络层 3.传输层 4.应用层 ,其中ip是在第二层网络层中,tcp是在第3层传输层中,Internet体系结构最重要的是tcp/ip协议,是实现互联网络连接性和互操作性的关键,它 ...

  9. Swift - 使用atlas图集实现动画效果(SpriteKit游戏开发)

    我们通常继承SKSpriteNode来实现游戏中的元素,除了可以使用图片作为纹理皮肤外.我们还可以使用动画纹理集来实现动画播放. 动画纹理集的制作也很简单,首先要有一套动画序列图,然后把它们放到一个文 ...

  10. Effective C++_笔记_条款02_尽量以const、enum、inline替换#define

    (整理自Effctive C++,转载请注明.整理者:华科小涛@http://www.cnblogs.com/hust-ghtao/) 这个条款或许改为“宁可以编译器替换预处理器”比较好,因为或许#d ...