VC sculptor small technology set (1)

zhaozj2021-02-16  51

VC sculptor small technology set (1)

He Zhidan

1. Avoid the same amount of random, you can take the current time, read the file, read any memory (if there is no variable, there is a danger).

CTIME T = CTIME :: getcurrenttime ();

INT n = t.getminute () * 60 t.getSecond ();

While (n--> 0)

{

Rand ();

}

Const int n = 100;

int result = rand ()% n;

2, string and number conversion

Sprintf, SSCANF, in fact, there are many other functions, but only the two functions are the most easily remembered. Because they are similar to Printf, Scanf, Fprint, FSCANF usage.

Char Str [100];

INT x = 5;

Sprintf (STR, "% D", X);

SSCANF ("10", "% x", & x);

3. Look at whether a button is in the prescription and whether it is pressed.

Short key = getasynckeyState (vk_f11);

0x8001 is in a state

1 call getasyncKeyState (VK_F11) between two times, F11 is pressed.

GetasyncKeyState, getKeyState Specifies whether the virtual code is vk_lbutton, vK_rbutton can determine if the mouse is pressed

4, how to delete a class.

method one:

1. Remove the file.

2. Open the Class Wizard (Ctrl W) Class Wizard can't find a file, and a dialog remouse will be popped up.

Method Two:

1. Remove in FileView .2, physical deletion.

5, the custom class is gone:

Project-> Add to Project -> Files

6, use PI

INCLUDE MATH.H

#define _USE_MATH_DEFINES

#include "math.h"

then

M_PI is PI

7. How can I get the volume of the partition? ?

Char buf [max_path];

GetVolumeInformation ("C: ///", BUF, MAX_PATH, NULL, NULL, NULL, NULL, NULL);

AfxMessageBox (BUF);

8, open a web page

Shellexecute (:: getdesktopwindow (), _ t ("open"), // SK Modified for Unicode

_T ("http://www.sohu.com"), NULL, NULL, // SK MODIFIED For Unicode

SW_MAXIMIZE);

9. When you turn it off, the pop-up dialog allows the user to confirm

Void cmainframe :: onClose ()

{

IF (iDok! = messagebox ("Do you want to exit? Click to exit", "Do you want to exit?", MB_OKCANCEL))

Return;

CframeWnd :: onClose ();

}

10, menu small problem

ID_FILE_OPEN

In the resource accelerator:

ID Key

ID_FILE_OPEN CTRL O

Indicates that pressing the Ctrl O combination key in the program to activate the open menu (if the file menu is opened, it is invalid).

In the resource MENU:

ID_FILE_OPEN's title is open (& O) ... / tctrl O

& O means that when its parent menu (file menu) is opened, the O activation file menu.

11, SIZEOF has a problem??

Class B

{

BOOL A;

BOOL C;

INT B;

}; // sizeof (b) == 8

layout:

1 2 3 4

Bool Bool Fill Filled 1 2 3 4

Int .............

At a glance. :)

At this time, the compiler is only inserted into two padding bytes after C, because B is four bytes, so automatic fill in one word binary.

This is an alignment problem of the compiler, as long as it is joined in front

#pragma 1

Make it in one byte.

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

New Post(0)