码迷,mamicode.com
首页 > Windows程序 > 详细

Win32编程知识积累

时间:2020-02-25 23:21:12      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:structure   标记   返回   some   ice   gdi+   paint   应用   microsoft   

  • Win32编程预知识
  • Windows sdk中有命令行工具,也有编译器和连接器。可以直接使用命令行编译链接C or C++编写的windows程序。而不必使用专业开发工具。
  • SdkSoftware Development Kit)不支持硬件驱动开发。
  • 绝大多数Windows APIs是由函数和com接口构成的,极少数是c++类(最典型的是GDI+, one of the 2-D graphics APIs
  • Windows api数据类型因为历史问题而有重复和冗余。

    ?

  • 常用typedefs
  • Integer types
  • Bool数据类型是头文件中定义的整数,TRUE1,但返回布尔值非零即为真。
  • Pointer Precision Types_PTR)类型
  • 匈牙利记号法(Hungarian notation

?

  • 字符串编码的问题:
  • 因为unicode支持所有语言,所以Windows广泛支持unicode编码,并使用utf-16(每个字符16位)表示字符。utf-16字符称为宽字符。区别于ANSI编码的8位的字符。数据类型wchar_t表示宽字符。用L加在文字前表示为宽字节文字。L‘ ‘;L" "
  • Unicode 函数and ANSI 函数。

Internally, the ANSI version translates the string to Unicode.

  • 宏定义????????Unicode????????ANSI(根据预处理器标记处理宏定义)

TCHAR ????????wchar_t????????char

TEXT("x")????L"x"????????????"x"

?

  • Window
  • application window or main window
  • non-client areaclient 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的控件无父子关系。

  • 句柄
  • 窗口是对象,它有代码和数据,但并不是一个类。
  • 程序用句柄指定一个窗口,句柄是一个不公开类型,它像一个数字,操作系统拥有一个记录所有窗口的大表,用句柄在表里找窗口。窗口句柄的类型为hwnd,由创建窗口返回得到。句柄不是指针。
  • 坐标系:可以以屏幕,窗口(包含非用户区),用户区为坐标系。左上角恒为原点。(横,竖)。

?

  • 应用入口函数

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!