Start
Recently, I have read the masterpiece of Charles Petzold "Windows program design", and there is a feeling of changing the evening. This is a published in 1999, which mainly tells how to use the C language to use the API function under the Windows platform. Today, today's RAD tools are full of market today, the book is still a newcomer to engage in the introduction of software development under Windows. I have been engaged in Windows platform software for nearly three years, and Windows-related books and documents have also read a lot, until they have exposed to the book, many past concepts suddenly suddenly. Speaking here, I have to admire Mr. CHARLES PETZOLD, and can understand the Windows program to develop knowledge is so simple and easy to understand.
The first chapter is mainly introduced, basic text content.
The prerequisite for contacting the book is to install a Windows system, understand the C language, and install a development environment that can make Windows programming.
Winows is a graphics operating system that supports a multi-task, multi-threaded multi-thread. Support for CUI (Console User Interface) and GUI (Graphical User Interface) two programming methods. All GUI-based Windows programs have at least one window, supports mouse and keyboard control, and multiple Windows programs can be run at the same time, and they do not conflict.
The core of WinOWS operation is a concept called "dynamic connection". The system functions that Windows are available, which can be called by the "Dynamic Connection" feature, which is mainly included in kernel.dll (including memory management, file I / O, task processing API function), user.dll (including user interface API functions) GDI.DLL (including graphics device interface API function) three dynamic connection libraries. Conventionally call the C library function, as long as the header file can be connected to our program; call the Windows API function, in addition to the header file, there is also a corresponding "import library (Import Library ) File, used to indicate the function of the DLL dynamic library call entry, and the DLL dynamic library is not connected to our programs, only when the program is running, the system will load the corresponding DLL dynamic library into memory.
In the 16-bit version of Windows, memory management is performed by segmentation mode (memory address consists of a 16-bit address and a 16-bit offset), and the int data type in the C language is 16-bit wide. In the 32-bit version of Windows, Windows supports the 32-bit mode flat memory mode, and the int data type in the C language has also expanded 32-bit wide. Considering program compatibility, current 32-bit version of Windows supports Win16 API and Win32 API, calling Win16 functions to Win32 function calls via a conversion layer and then calls by operating system.
Using the C language and the original API is not the only way to write a Windows program, but it is the most effective way to understand the principles of Windows system operations in the WINDOWS system. Of course, large-scale source code such as MFC, VCL is still very reference value, which allows you to understand how the expert-level Windows programming is.
It is recommended to use Visual C 6.0 as a programming environment. MSDN is a treasure house of Windows developers.
Below is a typical code based on the console mode:
#include
Main ()
{
Printf ("Hello, World! / N");
}
Below is a typical code based on graphic mode:
#include
Int WinApi Winmain (Hinstance Hinstance, Hinstance Hpreinstance, PSTR Szcmdline, IC ICMDSHOW)
{
MessageBox (Null, Text ("Hello, Windows 98!"), Text ("Hellomsg"), 0);
Return 0;
}
Windows.h contains multiple other Windows header files, such as WindEf.h (basic type definition), Winnt.h (support Unicode type definition), WinBase.h (kernel function), WinUser.h (user interface function), Wingdi.h (graphics device interface function).
If the entry point function based on the console mode is Main, the entry point of the Windows graphics mode program is WinMain, always wants to appear like this:
Int WinApi Winmain (Hinstance Hinstance, Hinstance Hpreinstance, PSTR Szcmdline, IC ICMDSHOW)
WinAPI is a call agreement, equivalent to __stdcall.
Hinstance is a handle type that is used to identify objects. The first parameter is used to represent the program instance;
The second parameter is now discarded, always null, we don't have to pay attention to; the third parameter is the command line of the running program; the fourth parameter indicates the way the program is initially displayed.
MessageBox displays a message dialog. The first parameter indicates the parent window handle, set to null, no parent window; the second parameter display message content; the third parameter display dialog header; the fourth parameter indicates the button combination and display icon on the dialog; return The value is an integer value, the identifier is to press which button on the dialog box.
When you compile this program, generate a .Obj file, link phase, link. Obj file, and .lib file establishment .exe file. You can see the Import Library list by selecting Setting on the Project Options, then click the Link tab.
In Visual C , you can choose Different configuration compilation and link programs, defaults to DEBUG and RELEASE configurations.