标签:structure 标记 返回 some ice gdi+ paint 应用 microsoft
Win32编程预知识
Windows sdk中有命令行工具,也有编译器和连接器。可以直接使用命令行编译链接C or C++编写的windows程序。而不必使用专业开发工具。
Sdk(Software Development Kit)不支持硬件驱动开发。
绝大多数Windows APIs是由函数和com接口构成的,极少数是c++类(最典型的是GDI+, one of the 2-D graphics APIs)
-
Windows api数据类型因为历史问题而有重复和冗余。
?
常用typedefs:
Integer types
Bool数据类型是头文件中定义的整数,TRUE是1,但返回布尔值非零即为真。
Pointer Precision Types(_PTR)类型
匈牙利记号法(Hungarian notation)
?
Internally, the ANSI version translates the string to Unicode.
TCHAR ????????wchar_t????????char
TEXT("x")????L"x"????????????"x"
?
Window
application window or main window
non-client area和client area
control (the control位置与the application window相关联)
窗口特征
在指定时刻可能不可见
知道怎样绘制自己
响应事件
父子窗口,是指某窗口与其支配的控件的关系。父窗口提供坐标系,没有子窗口能在父窗口外显示。
-
Owner and owned Windows,是指窗口和对话框窗口的关系。
(An owned window always appears in front of its owner window. It is hidden when the owner is minimized, and is destroyed at the same time as the owner.)
owned Windows也可以是其控件的父窗口,Owner与Owned的控件无父子关系。
?
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow);
The four parameters are:
- hInstance is something called a "handle to an instance" or "handle to a module." The operating system uses this value to identify the executable (EXE) when it is loaded in memory. The instance handle is needed for certain Windows functions—for example, to load icons or bitmaps.
- hPrevInstance has no meaning. It was used in 16-bit Windows, but is now always zero.
- pCmdLine contains the command-line arguments as a Unicode string.
- nCmdShow is a flag that says whether the main application window will be minimized, maximized, or shown normally.
The function returns an int value. The return value is not used by the operating system, but you can use the return value to convey a status code to some other program that you write.
WINAPI is the calling convention. A calling convention defines how a function receives parameters from the caller. For example, it defines the order that parameters appear on the stack. Just make sure to declare your wWinMain function as shown.
The WinMain function is identical to wWinMain, except the command-line arguments are passed as an ANSI string. The Unicode version is preferred. You can use the ANSI WinMain function even if you compile your program as Unicode. To get a Unicode copy of the command-line arguments, call the GetCommandLine function. This function returns all of the arguments in a single string. If you want the arguments as an argv-style array, pass this string to CommandLineToArgvW.
How does the compiler know to invoke wWinMain instead of the standard main function? What actually happens is that the Microsoft C runtime library (CRT) provides an implementation of main that calls either WinMain or wWinMain.
Note
The CRT does some additional work inside main. For example, any static initializers are called before wWinMain. Although you can tell the linker to use a different entry-point function, use the default if you link to the CRT. Otherwise, the CRT initialization code will be skipped, with unpredictable results. (For example, global objects will not be initialized correctly.)
?
- 该函数在程序开始时注册了窗口过程函数的地址。程序中并没有明确调用窗口过程函数,dispatchmsg函数间接使windows调用该过程函数,每条消息进行一次dispatch。
Windows api简述
The Windows API (also known as the Win32 API, Windows Desktop API, and Windows Classic API) is a C-language-based framework for creating Windows applications. It has been in existence since the 1980s and has been used to create Windows applications for decades. More advanced and easier-to-program frameworks have been built on top of the Windows API. For example, MFC, ATL, the .NET frameworks. Even the most modern Windows Runtime code for UWP and Store apps written in C++/WinRT uses the Windows API underneath.
Wndproc章节
WM_PAINT:
The application receives the WM_PAINT message when part of its displayed window must be updated. The event can occur when a user moves a window in front of your window, then moves it away again. Your application doesn‘t know when these events occur. Only Windows knows, so it notifies your app with a WM_PAINT message. When the window is first displayed, all of it must be updated.
?
To handle a WM_PAINT message, first call BeginPaint, then handle all the logic to lay out the text, buttons, and other controls in the window, and then call EndPaint.
?
HDC in the code is a handle to a device context, which is a data structure that Windows uses to enable your application to communicate with the graphics subsystem. The BeginPaint and EndPaint functions make your application behave like a good citizen and doesn‘t use the device context for longer than it needs to. The functions help make the graphics subsystem is available for use by other applications.
Win32编程知识积累
标签:structure 标记 返回 some ice gdi+ paint 应用 microsoft
原文地址:https://www.cnblogs.com/p201721410015/p/12364413.html