Win32 Learning Notes Chapter 6 Procedure 6-3 Typer Description

zhaozj2021-02-16  47

"Win32 learning notes"

Author: Jiang Xuezhe (netsail0@163.net)

Textbook: Windows Program Design (Fifth Edition) Peking University Press [United States] Charles Petzold Co., Ltd. ¥: 160

Environment: Windows2000 PRO Visual C 6.0

Tint Jiang Computer Program Group Copyright, Reprint, please explain the source ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ -------------------------------- [Chapter 6 Procedures 6-5 Typer]

It is more difficult to see this book. The sixth chapter is like this. There is not much explanation on the program in the book. Rely on your own understanding. so tired. This program can spend a lot of brains. So I want to write this program. Just study hard, so the level is not limited. If you have any improper places, you will yell.

The Typer program uses all the content discussed in this chapter. We can think Typer is a particularly simple text editor. In the window, you can enter the character, move the cursor with the cursor, and press the ESCAPE to erase the content in the window.

Winmain is not used. I have never changed from the third chapter. I think you should have a collimator. What? Haven't n't lived? What are you waiting for? Hurry back!

WM_INPUTLANGCHANGE:

There is no explanation in the book. But let's take a look at it. Whenever we change the keyboard layout, he will receive this message. Because there is such a sentence:

DWcharset = WPARAM;

The DWcharset is stored in the character set id-> default_charset. The sole possible reason for re-paying the value is that the keyboard layout has changed. And we can see that there is a new character set ID in the WPARAM field of the message.

WM_CREATE:

Then set the font for the selected keyboard layout. This is a logical font.

SelectObject (HDC, CreateFont (0, 0, 0, 0, 0, 0, 0, 0, dwcharset, 0, 0, 0, fixed_pitch, null);

Then get the width of the height of the character, save it in cxchar cychar.

Please pay attention to a detail here. Starting from the WM_INPUTLANGCHANGE message until the end of the WM_SIZE message, there is no BREAK or RETURN statement. This means that even if the program receives the WM_INPUTLANGCHANGE message, it will also be executed to the WM_SIZE message.

The number of rows and columns that can be displayed in the client area in CXBuffer and Cybuffer.

Then create a CXBuffer * Cybuffer dynamic character array according to the number of lines and columns.

When the program size changes or changes the keyboard layout, the program releases the dynamic array and reassign an array. But there is a problem here because

Free (PBuffer)

In front of the Malloc function, it will eventually cause the dynamic array to be released. I have heard that the wild pointer is, I don't know if this is. So I am

WM_DESTROY

Add a sentence in the news

Free (PBuffer);

at

PostquitMessage (0);

Behind. I may also be wrong, welcome to discuss.

There is a macro definition at the beginning of the program:

#define buffer (x, y) * (PBuffer Y * CXBuffer X)

This macro gives the position of the first line X-x.

FOR (y = 0; y

The above statement fills the customer area with spaces. We can change space to what other, such as buffer (x, y) = 'a';

See what the result will be.

Xcaret Ycaret is the location of the cursor. The function getFocus returns a window handle with input focus.

SetCareTPOS (Xcaret * CxChar, Ycaret * cychar);

The above statement moves the cursor to the upper left corner of the client area. Then the function is to refresh the entire client area:

InvalidateRect (HWND, NULL, TRUE);

Return 0;

When we change the keyboard layout (WM_INPUTLANGCHANGE), or create a window (WM_CREATE), or change the window size (WM_SIZE), our changes to the window customer area will disappear. The window will become the same time, that is, a large space.

WM_SETFOCUS WM_KILLFOCUS messages are written in the book very well. So don't say it.

The WM_KEYDOWN section is only vk_delete to talk.

This Delete is the same as the DELETE in the Notepad program. That is to delete the character of the current location, then the subsequent column moves one unit to fill the space out. The last list is a space.

For (x = xcaret; x

Buffer (cxbuffer - 1, ycaret) = '';

Although the content of the variable has been changed, the content of the customer area has not changed, so it is displayed in textout ().

Textout (HDC, Xcaret * CxChar, Ycaret * cychar, & buffer (xcaret, ycaret), cxbuffer - xcaret;

WM_CHAR: FOR (i = 0; i <(int) loword (lparam); i )

Loword (LPARAM) is the number of repetitions of the button.

Case '/ b':

First, move the insertion left one unit, then the VK_DELETE section of WM_KeyDows.

Case '/ t':

Do {sendMessage (hwnd, wm_char, '', 1);} while (Xcaret% 8! = 0); Break;

Now open the program Typer.exe. The position of the insertion character is (0) when the position is just opened. When we press the Tab button to become (8, 0), that is, move 8 characters to the right. Do you say that the function of the Tab key is to use the insert to move 8 characters to the right? End must.

We now use the cursor mobile key to remove the insertion (2, 0), now press the Tab button again, this time the position of the insert is still (8, 0). Pressing the Tab key behind the inserts Yes: (i * 8, 0).

SendMessage (hwnd, wm_char, '', 1);

Make the program execute the default portion of WM_CHAR.

Buffer (Xcaret, Ycaret) = (tchar) WPARAM;

SendMessage () passed a space, so the content of the Ycaret line Xcaret column turns a space. Then use textOut () to display the changed content.

Textout (HDC, Xcaret * Cxchar, Ycaret * cychar, & buffer (xcaret, ycaret), 1)

Until now only changed a word.

Then the insertion is one.

Xcaret Xcaret is included in an IF:

IF ( xcaret == cxbuffer) {xcaret = 0; if ( ycaret == cybuffer ycaret = 0;}

Xcaret == CXBuffer The role of CXBuffer is that when the insert is already reached the rightmost right of the client area, it cannot be removed to the next line. This program uses two statements to do this:

Xcaret = 0; ycaret

This Ycaret is also included in an IF. When the insert is reached the last line, the program will shift the insertion (0, 0).

WM_PAINT:

For (y = 0; y

The above code outputs the content in all dynamic arrays to the client area. If there is no such code, during WM_SIZE

FOR (y = 0; y

There is no use. However, I really don't understand what the two FOR statements above are used. Is it more? Or I didn't understand?

转载请注明原文地址:https://www.9cbs.com/read-27625.html

New Post(0)