Win32编程知识积累

  • 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

?

  • 字符串编码的问题:
  • 因为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 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的控件无父子关系。

  • 句柄
  • 窗口是对象,它有代码和数据,但并不是一个类。
  • 程序用句柄指定一个窗口,句柄是一个不公开类型,它像一个数字,操作系统拥有一个记录所有窗口的大表,用句柄在表里找窗口。窗口句柄的类型为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.

原文地址:https://www.cnblogs.com/p201721410015/p/12364413.html

时间: 2024-07-29 09:22:36

Win32编程知识积累的相关文章

Unit高级环境编程 知识积累(二)。

本文仅作个人积累.待功成,重新分类排版. 章14起 1:非阻塞IO:发出open/read/write等IO操作,并使这些操作不会永远阻塞.当不能完成时,会立即出错返回. 1,非阻塞的两种标志方式:指定标志:O_NONBLOCK. 2,非阻塞语义:文件状态标志的更改影响同一文件表项的所有用户,但与通过其他文件表项对同一设备的访问无关.(关联于文件表项) 2:记录锁功能(字节范围锁):一个进程正在读/修改文件的某个部分时,使用记录锁可以阻止其他进程修改同一个文件区. 1,它可以只锁住文件的一段区域

Unit高级环境编程 知识积累。

本文仅作个人积累.待功成,重新分类排版. 1:shell 为命令行解释器.分为:交互式Shell和Shell脚本. 2:文件名建议字符集:字母+数字+ ./-/_   尽量不要使用其他符号.因为特殊符号在很多功能中已经被占用. 3:

【转】网络编程知识

网络编程知识 索引: 处理SIGCHLD信号 捕获信号时,注意处理被中断的系统调用 accept返回前连接夭折的处理 具有多个输入的处理 SIGPIPE的产生和处理 处理服务器主机崩溃 处理服务器主机崩溃重启 处理服务器主机关机 网络函数的可重入问题 套接口设置超时的方法 辅助数据 如何得知套接口接收队列中有多少数据? UNIX域协议 UNIX域套接口使用套接口函数的一些差别和限制 描述字传递机制 非阻塞套接口I/O 服务器程序常见设计方法 注意网络编程的移植性问题 注意对等方的不合理行为 开发

WinRT知识积累1之读xml数据

前述:这个知识是在Windows8.1或WP8.1中运用Linq to xml获取一个xml文件里的数据.(网上也很多类似的知识,可以借鉴参考) 平台:windows8.1 metro 或者WP8.1 步骤:1.在项目中准备一个xml文件.我在项目中建立了一个city.xml,如图: city.xml具体代码如下: <?xml version="1.0" encoding="utf-8" ?> <China> <city> <

Win32编程中如何处理控制台消息

这篇文章讨论如何处理所有的控制台消息. 第一步,首先要安装一个事件钩子,也就是说要建立一个回调函数.调用Win32 API,原型如下: BOOL SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine, // 回调函数BOOL Add // 表示添加还是删除): 参数HandlerRoutine是一个指向函数的指针,原型如下: BOOL WINAPI HandlerRoutine(DWORD dwCtrlType // 控制事件类型): 所有的

python2.7的知识积累

参考http://blog.csdn.net/jcjc918/article/details/9354815 http://blog.sina.com.cn/s/blog_6fb8aa0d0101qtt9.html http://stackoverflow.com/questions/3505831/in-python-how-do-i-convert-a-single-digit-number-into-a-double-digits-string 今天晚上折腾了一下python,主要是去跑通

Intergraph G/Technology平台上的一些知识积累

Intergraph G/Technology平台,一个主要面向管线管理的GIS平台,在国内主要用于电力.电信.煤气等公共服务行业,具体的介绍请百度. 这几年的工作主要是在平台上进行一些二次开发,在 G/Technology上做开发时,需要了解平台的一些运行机制,才能更好地完成工作,同时也才能去解决一些由平台造成的垃圾数据. 虽然在这个平台上也做了多年的开发,但平常工作时,为了能及时地交付功能,在一些地方研究还是不够深入,这次也正好借这个机会好好地整理下. 本系列主要是我在G/Technolog

如何系统、科学地自学编程知识?

虽然不是码农,但是一直都有一颗码农的心.所以一直想学好怎么编程. 先说下自己的背景吧:已经毕业若干年工科男,所以基础知识也就是大学里谭浩强的那本绿壳的 C 语言.但是除了基本的变量.数组.选择.循环,到了指针那就记不清了. 然后因为工作需要,自己学了下 Linux 的 Shell 编程(Linux 系统的基础知识很一般),以及 W3School 里面 HTML, CSS 及 PHP 的部分内容.数据库的知识仅限于基础的 selecet, insert, update 操作.最后抄抄改改做了个功能

win32编程之俄罗斯方块

因为把目标定在了游戏上,最近在学习win32编程 经过一段时间的学习,开始进行编程实现俄罗斯方块,记录一下其中遇到的一些问题 一开始是看网上的教程学习的,但是做完一部分之后发现   会有闪屏的情况   所以又去网上搜索了一下发现要用到双缓冲. 注意:这段开始正确性有待考证! 我一开始的时候是把 drawTeris(); drawBackGround(); drawBlocked(); 都放在了WM_PAINT事件里 而且里面都用了双缓冲来绘制,结果导致后面闪屏更加频繁,后来把所有的绘制动作都交由