Read windows programming (1)

Source: Internet
Author: User
Tags knowledge base

Excerpt:

"You may find that, for example, it is ideal to write an application using Visual Basic, but it does not allow you to do one or two simple basic jobs. In this case, you will have to use the original API call. API defines everything you need as a writer for a Windows program. There is no way to be more omnipotent than simply using APIs. "

"There are hundreds of problems with MFC. Although it greatly simplifies some work (such as OLE), I often find that other features (such as document/view architecture) are used to make them work as I want) hitting the wall. MFC is not a panacea for Windows programmers, and few think it is a good object-oriented design model ."

"The authors of the MFC program have benefited a lot from how they work with the definition of the object category they use, and will find that they often refer to the MFC original code. Understanding these original codes is one of the benefits of learning Windows API ."

"If you are using Visual C ++ 5.0, you need to update the header file and reference Link Library for Windows 98 and Windows NT 5.0, which can be obtained from Microsoft's website. At http://www.microsoft.com/msdn/, select 「DownloadsAnd then select 「Platform SDK(Software development kit), you can download and install the update file in the selected directory. To allow Microsoft developer studio to browse these directories, you can 「Tool"Select 「OptionsThen press 「Directories"Tag ."

In Visual C ++ 6.0 「Help"Select 「ContentsThe msdn window is opened for the project. API files are organized in a tree structure and marked 「Platform SDKAll documents referenced in this book come from this part. I will show you how 「Platform SDKStart to find the location of the file that is separated by diagonal lines. (I know that "Platform SDK" is an obscure part of the entire msdn knowledge base, but I can assure that it is the basic core of Windows programming .) For example, for how to use a mouse file in a Windows program, see/Platform SDK/user interface services/user input/mouse input ."

"The kernel interface is in/Platform SDK/Windows base services. The user interface function is in/Platform SDK/user interface services, and GDI is in/Platform SDK/graphics and multimedia services/GDI."

C program helloworld

#include <stdio.h>int main (){           printf ("hello, world/n") ;           return 0 ;}

The first Windows program

/*------------------------------------------------------------------HelloMsg.c -- Displays "Hello, Windows 98!" in a message box    (c) Charles Petzold, 1998--------------------------------------------------------------------*/#include <windows.h>int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,                   PSTR szCmdLine, int iCmdShow){MessageBox (NULL, TEXT ("Hello, Windows 98!"), TEXT ("HelloMsg"), 0);return 0 ;}
"Just as the entry point in the C program is the function main, the entry point in the Windows program is winmain. This entry point is described in/Platform SDK/user interface services/Wing/Windows/window reference/window functions ."

"I also changed the names of two parameters in the winmain declaration. Variable names in many Windows programs use a naming system called Hungary notation, which adds a short prefix before the variable name to indicate the variable data type, I will discuss this concept in more detail in chapter 3. Now, you only need to remember that prefix I represents int and Sz represents "string ending with zero 」."

"The first parameter of winmain is called" execution entity handle 」. In Windows programming, a handle is only a number used by an application to identify something. In this case, the handle uniquely identifies the program and needs to be used as a parameter in other Windows function calls. In earlier versions of Windows, when you run the same program multiple times at the same time, you created the program's "multiple instances )」. All implementing entity sharing programs and read-only memory for the same application (usually resources such as menus and dialog box templates ). By checking the hprevinstance parameter, the program can determine whether other execution entities of the program are running. Then it can skip some complicated work and move some data from the preceding execution entity to its own data area ."
"In 32-bit windows, this concept has been abandoned. The second parameter passed to winmain is always null (defined as 0 )."
"The third parameter of winmain is the command column used to execute the program. Some Windows applications use it to load files into memory when the program starts. The fourth parameter of winmain indicates the method in which the program is initially displayed. It can be normally or fully filled with the entire screen, or minimized in the work column ."
"The first parameter of MessageBox is usually a window handle. We will introduce its meaning in Chapter 3. The second parameter is the string displayed in the message box body, and the third parameter is the string displayed in the message box title column. In hellmsg. C, each of these character strings is encapsulated in a text macro. Generally, you do not have to encapsulate all strings in a text macro, but it is a good idea to convert your program into a Unicode Character Set.

The fourth parameter of MessageBox can be a set of constants defined in winuser. H that have previously started with MB"

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.