Text authentication on screen implementation (C code)

xiaoxiao2021-03-06  78

Text authentication on screen implementation (C code)

Recently, I thought about it, I want to write a small game "Mahaby music" (download address: http://ggg82.rase.net/soft/migong.rar), the game is written, always feel too monotonous, head At the beginning, set a problem for the screen on the screen, and wondered for a long time, finally completed the task, and shared it with you.

To the text, you want to calculate the width of each text, and then perform the appropriate delay after outputting a word. The effect is coming out. Pure text narrative is not the best show, let the code talk!

Void StepText (HDC HDC, Rect * RC, Char * STR) // Text word typed word display {INT LEN = Strlen (STR); // Calculate the length INT POSX; // Current character position INT POSY = RC-> Top; size size; // Store the wide high setTextAlign (HDC, TA_UPDATECP | TA_LEFT | TA_TOP) of each character; // Set the automatic update text location while (len> 0) {POSX = rc-> left; MoveToex (HDC, RC-> LEFT, POSY, NULL); // Move to Law WHILE (LEN> = 0) {INT T; IF ((Str [0]) <0) T = 2; // Chinese Western character identification else t = 1; GetTextExtentPoint32 (HDC, STR, T, & Size); // Get character width IF (POSX SIZE.CX> RC-> Right) Break; // If you exceed the boundary POSX = size.cx; // Update the current location Textout (HDC, 0, 0, Str, T); // Output Character Str = T; // Update Character LEN- = T; / / Update Character Length IF (Len <= 0) Break; // If the character output is completed SLEEP (60 * t); // Time} POSY = size.cy; // For movement processing IF ((POSY SIZE.CY SIZE.CY)> = rc-> bottom) // The next line cannot be written, Screen {Rect RECT = * RC; Rect.top = size.cy; // Rolling screen position scrolldc (HDC, 0, -Size.cy, & Rect, null, null, null); POSY- = size.cy; // Restore Movement processing}}}}}}}

Ok, it's so simple, generate a Hello Word program instance with the VC, join the code, and the execution command calls, the effect is satisfactory!

Welcome to my profile: http://ggg82.126.com E-mail: ggg82@126.com

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

New Post(0)