Use the program to get CPU information

zhaozj2021-02-08  246

Multi-software can be self-reliant for different processing. For example, Photoshop 5 can detect whether the CPU has a MMX support and a different processing function. The "Golden Mountain Words" issued an existing MMX support to produce a semi-translated translation report, and many software can be distinguished by INTEL, CYRIX, AMD CPU ...

---- Now, let me make a thin way to get the CPU information in your own program.

---- The main can be used in the CPUID compilation (machine code: 0FH A2H, if your compiler does not support the CPUID instruction, only the EMIT machine code) This instruction can be used as a CPU

Intel 486 CPU above,

CPU above Cyrix M1,

CPU above AMD AM486

(1) Take the CPU OEM string, sentenced the CPU factory

Let EAX = 0 first, then call CPUID

Inel's CPU will return:

EBX: 756E6547H 'Genu'

EDX: 49656E69H 'INEI'

ECX: 6C65746EH 'ntel'

EBX, EDX, ECX will be "Genuineintel", true Intel.

Cyrix's CPU will return:

EBX: 43797269H

EDX: 78496E73H

ECX: 74656164H

"Cyrixinstead", "Cyrix is ​​replaced".

AMD's CPU will return:

EBX: 41757468H

EDX: 656E7469H

ECX: 63414D44H

"Authenticamd", trusted AMD.

---- In Windows98, use the right to click "My Computer", select "Properties - General" to see the CPU OEM string in the calculation program.

(2) CPU to the bottom is a few 86, is it supported by MMX?

Let Eax = 1 first, then call CPUID

EAX's 8 to 11 tables is a few 86

3 - 386

4 - i486

5 - Pentium

6 - Pentium Pro Pentium II

2 - Dual Processors

EDX 0 digits: no fpu

EDX 23rd: CPU is expensive to hold IA MMX, very important! If you want to use the 57 new instructions, check this one, and wait for the "The process of the" the program to be closed ".

(3) Special inspection Yes No P6

Let Eax = 1 first, then call CPUID

If Al = 1 is Pentium Pro or Pentium II

(4) Specialize detecting AMD CPU information

Let EAX = 80000001H, then call CPUID

If eax = 51h is AMD K5

If eax = 66h is K6

EDX 0th: Yes No FPU

EDX 23rd, the CPU is supported by MMX,

The procedure is as follows: It is the control station of C Builder to give your "heart" information. If this technique is used in DLL, you can know the "heart" information in the DLL. File: // ------ CPUID Instruction Demo Program ------------ #include #include #pragma hdrstop file: // --- ---------------------------------------------

#pragma inline #pragma argsused

Int main (int Argc, char ** argv) {char Oemstring [13]; Int IEaxValue, IEbxValue, IECxValue, IEDXVALUE

_ASM {MOV EAX, 0 CPUID MOV DWORD PTR Oemstring, EBX MOV DWORD PTR Oemstring 4, Edx Mov DWORD PTR Oemstring 8, ECX MOV BYTE PTR Oemstring 12,0}

COUT

_ASM {MOV Eax, 1 CPUID MOV IEAXValue, EBX MOV IEbxValue, EBX MOV IECXVALUE, ECX MOV IEDXVALUE, EDX}

"ipvalue & 0x800000) Cout

INT ICPUFAMILY = (0xF00 & IEaxValue)>> 8;

COUT <"CPU Family IS:"

_ASM {MOV EAX, 2 cpuid}

IF (_al == 1) cout <<"Pentium Pro or Pentium II Found";

Getch ();

Return 0;

} ShowMessage ("Could Not Makecurrent");

How do I use an Enter key to transfer,?

1 In the Windows environment, you can get a control to get the focus, and you can use the mouse on the control to move the focus to the control with the Tab button. This control focus switch is not convincing. As shown in the figure, users will hope with Enter keys, and the control focus is switched from Edit1 to Edit2. To realize this, the function can be completed by helping the WinAPI function SendMessage. The method is: first set up the keypreview attribute of Form1 as true, then add the following code in the Form1 onkeyPress event. In this way, the user can move by pressing the ENTER, the key control focus is moved by definite Taborder order! Void __fastcall tform1 :: formypress (tobject * sender, char & key) {if (key == vk_return) {sendMessage (this-> handle, wm_nextdlgctl, 0,0); key = 0;}} 2 in Edit1 onkeyPress (Event) Add IF (Key == VK_RETURN) EDIT3-> setfocus ();

The window of the network ants disappears ?? Timer-> Intrval = 10; void __fastcall tform1 :: Timer1Timer (TOBJECT * Sender) {FORM1-> Width- = 20; Form1-> height- = 20; if (Form1-> width == 108 && form1-> height == 27) {form1-> close ();} form1-> top = 10; Form1-> Left = 10;

(2) TDATETIME T1; FORM1-> CAPTION = "Today is:" DateTostr (date ()) "The time is:" Timetostr (Time ()); (3) Ansistring S; s = "; if (SelectDirectory ("SELECT DIRECTORY", S)) SetPath (s); (4) ANSISTRING S; InputQuery ("Title", "Tips", S);

Window background public: graphics :: tbitmap * bitmap; file: // ------------------------------- Void __fastcall TFORM1 :: Formcreate (TOBJECT * Sender) {bitmap = new graphics :: tbitmap; bitmap-> loadingfromfile ("arc.bmp");} file: // --------------- -------------------------------------------------- ------------

Void __fastcall tform1 :: formpaint (TOBJECT * Sender) {INT X, Y; Y = 0; While (Y DRAW (x, y, bitmap) ; X = x bitmap-> width;} y = y bitmap-> height;}} How to transfer JPG files to BMP files? ? ? First use TIMAGE control image1-> Picture-> LoadFromfile (your JPEG file) then graphics :: tbitmap * tmp = new graphics :: tbitmap (); tmp-> assign (image1-> picture-> graphic); TMP-> Savetofile (filename);

Document reading write INT i = 0; char SN [] = "123"; if (! FileExists ("aaa.txt")) {i = filecreate ("aaa.txt"); FileWrite (I, SN, STRLEN (SN)); FileClose (I); showMessage ("OK");

{Char BUF [3]; ANSISSIING STR; INT I; I = FileOpen ("D: //aaa.txt", FMopenReadwrite; FileRead (I, BUF, 3); FileClose (i); if (Edit1-> Text == Ansistring (BUF, 3)) {ShowMessage ("OK '");

Press button #include Ansistring SoundFile = "D: //ding.wav"; SNDPLAYSOUND (SoundFile.c_STR (), SND_ASYNC);

How to make Win98 Sleep SetSystemPowerState (True, true); the first parameter specifies whether to sleep or hang (True: the former; false: the second parameter specifies whether it is forced.

How to transfer floating point to ANSISTRING to control it only to keep two decimal waat aa = 9032.569; Ansistring BB = FormatFloat ("0.00", AA);

Can you transfer A = "ff"; turn A into 10 advanced? This is simpler: the front of the 16 credit flag 0X redirect, ANSISTRING S = "ff"; s = "0x" S; int X = S.Toint ();

How to get the resolution of the screen? The system automatically defines a global variable Screen, which can use Screen-> Height, Screen-> Width anywhere, Screen-> Width to get the current screen resolution.

Who knows how dynamic arrays must be dynamically changed during program operations. Use malloc (): assign space and realloc (): Dynamic Adjustment Pointer Assignment Space. Note To include STDLIB.H. Examples are as follows: #include #include #include int main (void) {char * str; str = (char *) malloc (10); strcpy (Str, " Hello "); Printf (" String IS% S / N Address IS% P / N ", STR, STR); Str = (Char *) Realloc (STR, 20); Printf (" String IS% S / N New Address IS% P / N ", STR, STR); Free (STR); Return 0;} How to display random numbers? Timer-> interval = 150, effect is good void __fastcall tform1 :: Timer1Timer (TOBJECT * Sender) {label1-> CAPTION = Random (100);

Void __fastcall tform1 :: button1click (TOBJECT * Sender) {Timer1-> Enabled =! Timer1-> enabled;} Do not use threads, Timer is small, does not affect the response of the program. If you have to stop for a while: (for example 1 minute = 60 second = 60000ms = 400 times * 150ms / time int Timeout = 400; file: // Timer-> Interval = 150, the effect is good void __fastcall tform1 :: Timer1Timer Tobject * sender) {label1-> caption = random (100); if (- timeout == 0) Timer1-> Enabled =! Timer1-> enabled;} Timer's minimum resolution is 55ms is 18.2 times a second, Like the frequency of 8253/8254. The minimum interval can reach 1ms using the of Windows to re-confirm the call once every 20 ms.

TQuery parameter setting 1 After writing, the data type of the variable can be modified in the parameter properties. 2. Assignment of variables: query1-> Active = false; query1-> params-> items [0] -> asstring = edit1-> text; query1-> active = true; // Find records that match variables 3. Use DBGRID shows the result of DBGRID DataSource and DataSource1, and DataSource1's DataSet is connected to the TQuery1. Second, the extracted SQL language is easier and more efficient than Table. Use a simple code to explain how to create a query program: For example, the program to create a book name book 1 in Table 1 is placed on the form to add DBGRID, DataSource, Query three controls: dbgrid1-> DataSource = Datasource1 DataSource1-> dataset = tqery1; query1-> close (); query1-> sql-> clery (); query1-> sql-> add ("SELECT * FROM table where (book name = 'book1'"); Query1 -> EXECSQL (); query-> active = true; you can see all names BOOK1 records in the generated table.

Window Gradient Background Color Tcolor StartColor, EndColor; // Global Variable File: // Get Start Color IF (ColorDialog1-> Execute ()) StartColor = Colordialog1-> Color; File: // Get End Color IF (ColorDialog1-> Execute )) EndColor = ColorDialog1-> Color; float pwidth; int redstart, greenstart, bluestart, redend, greenend, blueend; float redinc, greeninc, blueinc; pwidth = float (PaintBox1-> Width); file: // through Get (X Value function to get the beginning of the color of red, blue, green redstart = GtrValue (startColor); GreenStart = getGValue (StartColor); Bluestart = getBValue (startColor); file: // Get the end of the Get (X) Value function Color red, blue, green rednd = GtrValue (endColor); GREENEND = getGValue (endColor); BlueEnd = getBValue (endColor); file: // Set color change rate redinc = (rednd-redstart) / PWidth; greeninc = (GREENEND -greenstart) / PWidth; Blueinc = (BlueInc = (blue) / pWidth; for (int i = 0; i width; i ) {file: // Define brush color PaintBox1-> canvas-> Pen-> Color = TCOLOR (RGB (RedStart INT (RedInc * i), GreenStart Int (Greeninc * i), Bluestart Int (BlueInc * i))); File: // Mobile Brush to PaintBox1-> Canvas-> Moveto (i , 0); File: // Painted by PANITBOX1 PainTBox1-> CAN Vas-> Lineto (I, PaintBox1-> Height);

How do I make a background color of DBGRID and SRTINGRID? TFORM1 :: DBGRID1DRAWCOLUMNCELL () IF (column-> field-> dataset-> recno% 2) {dbgrid1-> canvas-> brush-> color = ClyEllow; dbgrid1-> canvas-> fillRect (Rect);} DrawText (dbgrid1 -> Canvas-> Handle, Column-> Field-> text.c_str (), - 1, (rect *) & review, dt_singleline | dt_vcenter | dt_center); How to change the background color of DBGRID and SRTINGRID? Query1-> close (); query1-> sql-> clear (); query1-> sql-> add (memo1-> text); query1-> open (); for (int i = 0; i Column-> count; i ) {if (i% 2 == 0) DBGRID1-> column-> items [i] -> color = claqua; else dbgrid1-> columns-> items [i] -> color = clinfobk; } How to get the current month?

TDATETIME TIME = NOW (); Ansistring Time = Time.FormatString ("YYYY-MM-DD"); Ansistring Month = Time.Substring (6, 2); Label1-> CAPTION = Month; Ansistring Smont; Smonth = now () .Formatstring ("mm"); // Remove the current month Label2-> Caption = SMONTH;

Field Title Blinking Timer () {FlashWindow (Form1-> Handle, True):}

Like StarCraft starts from large to small subtitles, add a Timer (label), label (label), label (label), label1-> automation = 歪歪 VB tutorial "label1-> font-> name = "Arial" Label1-> Font-> Size = 150 Label1-> Fore-> Color = vbGreen Label1-> Visible = true Time1-> Interval = 1 Time1Enabled = true void __fastcall TForm1 :: Timer1Timer (TObject * Sender) { IF (label1-> font-> size> = 2) {label1-> font-> size = label1-> font-> size-2; label1-> left = (Form1-> width-form1-> width) / 2 ; Label1-> TOP = (Form1-> Height -Label1-> Height) / 2;} else {label1-> visible = false; timer1-> enabled = false;}}

Cpuid getcpuid (void) {asm {push ebx file: // {save affected register} Push Edi Mov Edi, Eax File: // {@resukt} MOV EAX, 1 dw 0xa20f file: // {cpuid command} stosd file: // {cpuid [1]} file: // CPU name MOV EAX, EBX stosd file: // {cpuid [2]} // 无用 的 m,, ECX Stosd file: // {cpuid [3]} // useless Mov Eax, Edx Stosd File: // {CPUID [4]} // CPU No. Pop Edi file: // {rest}} Pop EBX}} File: // ------------- -------------------------------------------------- ------------ Void __fastcall tform1 :: button1click (TOBJECT * Sender) {Label1-> CAPTION = (ANSISTRING) getcpuid ();

Automatically call the browser or mail program Windows provides the shellexecute function to invoke an external program or a file associated with a program.

The prototype is as follows:

Hinstance shellexecute

HWND HWND, // Handle To Parent Window

LPCTSTR LPOPERATION, / / ​​POINTER TO STRING THAT SPECIFIES OPERATION TO PERFORM

LPCTSTR LPFILE, / / ​​POINTER TO FileName or Folder Name String

LPCTSTR LPPARETERS, / / ​​POINTER TO STRING THAT SPECIFIES EXECUTABLE-FILE Parameters

LPCTSTR LPDIRECTORY, / / ​​POINTER TO STRING THAT SPECIFIES DEFAULT DIRECTORY

Int nshowcmd // WHETHER FILE IS SHOWN WHEN OPENED

);

If you want to automatically access my homepage, the program code is as follows:

Shellexecute (Handle, NULL, "http://lmq.4y.com.cn", null, null, sw_shownormal);

To start the system default mail program, write to me, the program code is as follows:

Shellexecute (Handle, NULL, "Mailto: lmq@4y.com.cn", null, null, sw_shownormal;

The acquisition printer function in the BCB is Printer (); its return value is a TPrinter object, you can find the help of the Tprinter object. You need to add a referenced header file is #include where printer () - >printers-> count is the number of printers () - >printers-> strings [] is the name of the printer () -> Begindoc () Start Print Preparing Printer () -> Enddoc () End Print Preparation, Start True Print Printer () -> Abortdoc () Terminate Print Preparation. You can use Printer ()-> Canvas to draw a page after Begindoc () and EndDoc () to draw a page after you can use Printer () -> NewPage () Printer () -> Handle Is an HDC, using getDeviceCaps (Printer () -> Handle, ...) can get a lot of properties such as the current printer, without begindoc () (if using printer () -> canvas-> handle BeginDoc () to get accurate information) to take a screen color void __fastcall TForm1 :: Button1Click (TObject * Sender) {int BitsPerPixel = GetDeviceCaps (Canvas-> Handle, BITSPIXEL); int Planes = GetDeviceCaps (Canvas-> Handle, PLANES); BitsPerpixel * = Planes; Bool UseSpalettes = (BOOL) (canvas-> Handle, RasterCaps) & rc_palette; if (useespalettes) label1-> caption = "screen use Hungry palette"; Else Label1-> CAPTION = " The screen does not use the palette;

Switch (BitsPerpixel) {case 32: label2-> caption = "32-bit true color"; Case 24: label2-> caption = "24-bit true color"; Break; Case 16: label2-> caption = "16- High color; break; case 8: label2-> caption = "256 color mode"; Break; case 4: label2-> caption = "16 color mode"; Break; case 1: label2-> caption = "Monochrome Mode "; break; default: label2-> caption =" screen support " INTTOSTR (1 << bitsperpixel) " Different Colors "; BREAK;}

Use your own library: New-> CPP Int jia (int A, int b) {RETURN (A B);} save to file1.cpp at unit.cpp #include "file1.cpp" int C = jia (a , b);

How to make the text on the statusbar roll up? ? The following can make the strings in Statusbar to left motion statusbar1-> simpletext = statusbar1-> simpletext.substring (2, statusbar1-> simpletext.length () - 1) statusbar1-> simpletext.substring (1, 1); File: // ------------ Design timpanel = true; simpletext = love you sizegrip = false; How do you display Double type in the TSTRINGGRID control? Double AAA = 1.1; Ansistring Str = floattostr (AAA); StringGrid1-> Cells [1] [2] = Str; StringGrid1-> Cells [1] [1] = FormatFloat ("0.00000", 3.1415926);

Table1 Query Table1-> Filtered = false; table1-> filter = edit1-> text; table1-> filter = true; edit1-> text = content is: Field is character name = 'zzz' and age> 18 and SEX! = 'Male' FilterOption << FocaseInSensitive (Size) << FonopArtialCompare (full match)

Database input can only modify the content of the table you entered (like entering the monthly salary can modify the input error does not modify the wage of the previous month CreateButtonClike () {if (! Table1-> EXISTS) {table1- > Active = false; table1-> DatabaseName = "msaccess1"; // Established the same table structure table1-> TableType = TTDEFAULT; table1-> TableName = "scadd"; table1-> fielddefs-> clear (); table1-> FieldDefs-> Add ("SNO", FTINTEGER, 0, FALSE); // field name, type, small number or length, is the only table1-> fielddefs-> add ("cno", ftinteger, 0, false); Table1 -> Fielddefs-> Add ("grade", ftinteger, 0, false); table1-> createTable ();} table1-> active = true;} exitbuttonclik () {Table2-> Batchmove (Table1, BataPpend); Batupdate / / Use the original list of records to update the target table's record; BATAPPPDATE // Add the original table to the last record of the target table to the end of the target table BATDELETE // Remove the original table Duplicate record in the target table BATCOPY // Put the original table Copy to Target Table1-> Active = False; Table1-> DatabaseName = "msaccess1"; table1-> TableType = TTDEFAULT; table1-> TableName = "scadd"; table1-> deleteTable ();} I, C Builder design you Browser

C Builder5 provides a browser control CPPWebBrowser, which is located in the Internet Control Bar, and its main methods are:

Navigate function, used to browse the resources of the given URL

Goback (), browse the previous page

Goforward (), Browse Next

STOP (), stop browsing

Refresh (), refresh the current page

Create a new application, save the engineer as Myie, set the Form1's name to main_form, join a CPPWebBrowser control on the main_form, put it in this Toolbar control into a combox box, and add five Toolbutton, set it The Name property is "CPPWebBrowser1", "Toolbar1", "CB_URL", "TB_Prior, TB_Forward, TB_Stop, TB_FRESH, TB_NAVIGATE".

TB_NAVIGATE's onclick event code is as follows:

Void __fastcall tmain_form :: navigateExecute (TOBJECT * Sender)

{

CPPWebBrowser1-> Navigate (widestring) CB_URL-> Text, Tnoparam (), Tnoparam (), TNOParam (), Tnoparam ());

Combox1's onkeypress event code is as follows:

Void __fastcall tMain_form :: CB_URLKEYPRESS (TOBJECT * Sender, Char & Key)

{

IF (key == 13) file: // If the button presses is the Enter key

NavigateExecute (Sender);

}

The rest of the code is similar ...

Compilation operation, a browser with basic browsing features is generated.

2. Get the source file of the HTML file

When we use IE to browse the homepage, if you click Right-click, select View Source File, and the system will automatically start the source file of this HTML. When programming, you sometimes analyze the source file of the HTML file, and you can easily solve this problem with the NMHTTP control of C Builder.

New project, drag a NMHTTP control from the FASTNET control bar to the form, then drag a MEMO control to the form, assume the source file of my home page (http://lmq.4y.com.cn), in Form1 Oncreate event Type code:

Void __fastcall tform1 :: formcreate (TOBJECT * SENDER)

{

Memo1-> clear (); file: // Empty Memo1

NMHTTP1-> GET ("http://lmq.4y.com.cn");

MEMO1-> text = nmHttp1-> body;

}

The source file of the home page immediately displays the source file in the MEMO1 box.

In addition, the NMHTTP control also supports proxy proxy, its properties proxy and port refer to IP addresses and port numbers of the proxy server, respectively.

Third, automatically call your browser or mail program

Windows provides a shellexecute function that calls an external program or a file associated with a program.

The prototype is as follows:

Hinstance shellexecute

HWND HWND, // Handle To Parent Window

LPCTSTR LPOPERATION, / / ​​POINTER TO STRING THAT SPECIFIES OPERATION TO PERFORM

LPCTSTR LPFILE, / / ​​POINTER TO FileName or Folder Name String

LPCTSTR LPPARETERS, / / ​​POINTER TO STRING THAT SPECIFIES EXECUTABLE-FILE Parameters

LPCTSTR LPDIRECTORY, / / ​​POINTER TO STRING THAT SPECIFIES DEFAULT DIRECTORY

Int nshowcmd // WHETHER FILE IS SHOWN WHEN OPENED

);

If you want to automatically access my homepage, the program code is as follows:

Shellexecute (Handle, NULL, "http://lmq.4y.com.cn", null, null, sw_shownormal);

To start the system default mail program, write to me, the program code is as follows:

Shellexecute (Handle, NULL, "Mailto: lmq@4y.com.cn", null, null, sw_shownormal;

The above procedures run in PWIN98 BCB5. File: // ---------------------------------------------- -------------------------------------------------- ---------------

How to change the HTML content of CPPWebBrowser under BCB

Void __fastcall tform1 :: sethtml (tcppWebBrowser * Webbrowser, Ansistring HTML) {istream * stream; hglobal hhtmltext; ipersiststreaminit * psi;

IF (webbrowser-> docuument == null) return; hhtmltext = GlobalAlloc (gptr, html.length () 1); if (0 == hhtmltext) {ShowMessage ("GlobalAlloc Error"; Return;}

CopyMemory (hhtmltext, html.c_str (), html.length ());

Olecheck (CreateStreamonhglobal (HHTMLText, True, & Stream);

Try {olecheck (WebBrowser-> Document-> queryinterface (__UUIDOF (iPersistStreaminit), (void **) & psi); try {olecheck (psi-> initnew ()); olecheck (psi-> load (stream));} Catch (...) {delete psi;}} catch (...) {delete stream; delete stream;

CPU usage

#ifndef fmtesth # define fmtesthfile: // ----------------------------------------- ---------------------------------- # include #include #include #include #include file: // --------------------------- ---------------------------------------------- Class TTestForm : public TForm {__ published: // IDE-managed Components TLabel * LbAldynUrl; TMemo * MInfo; TTimer * Timer; void __fastcall LbAldynUrlClick (TObject * Sender); void __fastcall FormCreate (TObject * Sender); void __fastcall TimerTimer (TObject * Sender) ; private: // user declarationspublic: // user declarations __fastcall ttestform (tComponent * Owner);}; file: // ------------------------ -------------------------------------------------- -Extern package ttestform * Testform; File: // --------------------------------------- ------------------------------------ # endiffe: // --------- -------------------------------------------------- ----------------

#include #pragma HDRSTOP

#include "fmtest.h" #include "adcpuusage.hpp" file: // -------------------------------- ------------------------------------------ # prgma package (smart_init) # Pragma resource "* .dfm" TTESTFORM * TESTFORM; File: // ----------------------------------- ----------------------------------------__ fastcall ttestform :: TTestForm (tComponent * Owner) : TFORM (OWNER) {} file: // --------------------------------------- ----------------------------------- void __fastcall ttestform :: lbaldynurlclick (tobject * sender) {SHELLEXECUTE Application-> Handle, "Open", "http://www.Aldyn.ru/", null, null, sw_showdefault);} file: // ---------------- -------------------------------------------------- --------- void __fastcall ttestform :: formcreate (TOBJECT * Sender) {INT i; minfo-> lines-> clear ();

Minfo-> Lines-> Add ("TheRe Are% D Total CPU IN Your System", ArrayOfconst ((getcpucount ())))))))))))))))))))))))))))))

For (i = 0; i lines-> add ("");} file: // ------------------- -------------------------------------------------- ------ Void __fastcall ttestform :: timertimal (TOBJECT * Sender) {INT i;

Collectcpudata ();

Minfo-> lines-> beginupdate ();

For (i = 0; i lines-> strings [i 1] = format ("CPU #% D -% 5.2F ​​%%", Arrayofconst ((i, getcpuusage) ) * 100)));

Minfo-> lines-> endupdate ();

How to save the program to run information to the INI file

Many software now saves the data needed in the program in the registry, so when the software has more and more software, the registry is increasing, and the system is easier to make the system error. Of course, Microsoft also recommends saving data in the registry, but when we need to save data, you can save data in Win.ini for a while, which can be easily maintained, and the implementation is relatively simple. Here are how to do with Borland C Builder as an example. The principle is actually very simple, just call the API's WriteProfileString and getProfileint functions. The prototypes of these two functions is: BOOL WriteProfileString (LPCTSTR lpAppName, LPCTSTR lpKeyName, LPCTSTR lpString); UINT GetProfileInt (LPCTSTR lpAppName, LPCTSTR lpKeyName, INT nDefault); wherein means lpAppName WIN.INI middle name, i.e. with [] The string, lpkeyname refers to the name of each item in this section, and lpstring means the value of this project, the number after "=", NDEFAULT is the value returned when LPROFILEIN is not found, that is, the default value The former returns to the Boolean value (TRUE or FALSE), the latter returns to the unsigned shaping value. When LPKEYNAME is empty (NULL) in the WriteProfileString function, the content of this section is cleared, the content of this project will be cleared. The following example will illustrate the usage of these two functions. Create a new application, put two Edit and three button on Form1, where edit's text is empty, and the three Button's CAPTION is "Add", "View", "Clear". Double-click the "Add" button to join the following code: WriteProfileString ("Example", "Project", Edit1 → Text.c_STR ()); Double-click the "View" button to join the following code: unsigned int Temp; temp = getprofileint ("example program" , "Project", 100); Edit2 → Text = INTOSTR (TEMP); Double-click the "Clear" button to join the following code: WriteProfileString ("Examples", NULL, NULL; then press the F9 key to run the program. You can check the correctness of the program. Enter a number in Edit1, such as "3265", press the "Add" button, then run "Sysedit" to view the last side of the "win.ini" file, you can see the following: [Examples] item = 3265 Where "[]" and "=" are the function of the function. Press the "View" button, "3265" appears in Edit 2, when pressing the Clear button to clear the added part. Viewing the desired purpose has been achieved. Friends who love programming can apply the above methods into their own programs to achieve the role of saving data information. When you do save information to the registry, you can define an object of a Tregistry class in C Builder to perform related operations, or call the Windows API function. Get the local Internet machine's name and IP address to get the local Internet machine Name and IP address

First, the following example uses the Winsock API to get the name and address of the local host and address void __fastcall tform1 :: button1click (Tobject * sender) {hostent * p; char s [128]; char * p2; file: // Get the Computer Name gethostname (s, 128); p = gethostbyname (s); memo1-> lines-> add (p-> h_name); file: // get the ipaddress p2 = inet_ntoa (* (in_addr *) P-> h_addr)) ; Memo1-> Lines-> Add (p2);} void __fastcall TForm1 :: FormCreate (TObject * Sender) {WORD wVersionRequested; WSADATA wsaData; file: // Start up WinSock wVersionRequested = MAKEWORD (1, 1); WSAStartup (wVersionRequested , & wsadata);} void __fastcall tform1 :: formdestroy (TOBJECT * Sender) {wsacleanup ();} Modify display mode:

File: // ---------------------------------------------- -----------------------------

#ifndef unit1H #define unit1h file: // ---------------------------------------- ----------------------------------- #include #include # Include #include #include "myedit.h" #include #include #include #include file: / / -------------------------------------------------------------------------------------------- --------------------------- Class TForm1: Public TForm {__published: // Ide-management Components TPANEL * PANEL1; TBUTTON * Button1; TLabel * Label1; TButton * Button2; TListBox * ListBox1; TButton * Button3; void __fastcall Button1Click (TObject * Sender); void __fastcall Button2Click (TObject * Sender); void __fastcall Button3Click (TObject * Sender); private: // User declarations public: // user declarations __fastcall tform1 (tComponent * Owner; devmode table [400]; bool listed;}; file: // ----------------------- ----------- ----------------------------------------- EXTERN PACKAGE TFORM1 * FORM1; File: / / --------------------------------------------------- -------------------------- # endifunit.cpp file: // ---------------- -------------------------------------------------- ---------

#include #include #pragma HDRSTOP

#include "unit1.h" file: // -------------------------------------- ------------------------------------ #pragma package (smart_init) #pragma link "myedit" #pragma Resource "* .dfm" TFORM1 * FORM1; File: // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------- __fastcall tform1 :: tform1 (tComponent * Owner): TFORM (OWNER) {listed = false; button2-> enabled = false; button3-> enabled = false;} file: // ---------------------- -------------------------------------------------- ---

void __fastcall TForm1 :: Button1Click (TObject * Sender) {DWORD index = 0; bool flag; do {flag = EnumDisplaySettings (NULL, index, & table [index]); if (flag) {if (table [index] .dmPelsWidth <640); Else IF (Table [Index] .dmbitsperpel <8); Else IF (Table [Index] .dmdisplayFrequency> 85); Else IF (Table [INDEX] .dmpelswidth> 1024); else {Ansistring st ;st = INDEX; ST = ""; St = Table [index] .dmpelswidth; st = "x"; st = Table [index] .dmpelsheight; st = "x"; st = table [index] .dmbitsperpel; st = "x "; ST = Table [index] .dmdisplayfrequency; listbox1-> items-> add (st);}} index ;} while (Flag & INDEX <300);

Ansistring T; T.SPrintf ("% D modes found", index); label1-> caption = T; listed = true; button2-> enabled = true;} file: // ------------ -------------------------------------------------- ---------------

Void __fastcall tform1 :: button2click (TOBJECT * Sender) {file: // getDeviceCapsint i; if (! listed) {label1-> caption = "List Display modes first."; return;}

For (i = 0; i items-> count; i ) {if (listbox1-> selected [i]) {Int x; string st, st1; st = listbox1-> items-> strings [i] ; X = st.pos (""); ST1 = st.Substring (1, x-1); x = st1.toint (); label1-> caption = x; ChangeDisplaySettings (& Table [x], 0); Break }}} If (i == listbox1-> items-> count) label1-> caption = "SELECT A Modes first."; Button3-> enabled = true; int r = messagebox (0, "can you see anything?" , "Display", MB_okcancel; if (r == idcancel) Button3Click (sender); elseButton3-> setfocus ();} file: // ---------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------- ------- void __fastcall tform1 :: button3click (TOBJECT * Sender) {changeisplaySettings (null, 0); button3-> enabled = false;} file: // ------------ -------------------------------------------------- -------------

How to implement printing MEMO's text information

TPrinter * pprinter = printer (); pprinter-> title = "Print data in Memo1"; pprinter-> begindoc (); int y = 10; for (int i = 0; i lines-> count; i ) {pprinter-> canvas-> textout (10, y, memo1-> lines-> strings [i]); y = pprinter-> canvas-> textheight ("a");} pprinter-> enddoc ();

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

New Post(0)