Several small applications of C ++ Builder

zhaozj2021-02-08  236

This is the first post, looking for it online. The following is the original text.

Several small applications in C Builder (Wang Yue, September 19, 2001 19:00)

Borland C Builder (BCB) is an object-oriented, visualized fast application development environment. When the tool is built, you don't have to write a program to describe the appearance and configuration of the input or output interface, as long as the tool box is used, you can implement it in the program design phase, it belongs to a "what you see what you get "Intuitive design concept. With this programming tool, you can use the least manual programming code, create an efficient 32-bit window application that provides test, debugging, and application configuration tools that need to be developed, including large-scale application component libraries, design Tools, applications and form templates, and programming wizards. In order to explain the powerful development capabilities of C Builder, the author will list a small application of C Builder in development procedures.

1. Call the image in the program to assume that we need to call an image in advance, and its name is tx.bmp, we can call as follows: First open the Borland C Builder program, in the window Place an image control image1, which is time to be empty; then place a popup menu on the form, edit the menu item Add "close" item (add the program code to turn off the application when the pop-up menu is activated), The original code is:

Void __fastcall tform1 :: formcreate (TOBJECT * Sender) {image1-> Picture-> LoadFromFile (".// TX.BMP"); // Use the loadFromfile function to call image width = image1-> width; height = image1- > Height; repaint ();

2. Start the screen save program If we set the screen saver to your computer, then the computer will automatically screen saver in our specified time. Do you know how this calling process is implemented? Here, we can use the C Builder program to implement such functions. As long as we use the SendMessage Function to send a broadcast message to the system in the C Builder program, the specific original code is:

Void __fastcall tform1 :: button1click (TOBJECT * Sender) {sendMessage (hwnd_broadcast, wm_syscommand, sc_screensave, 0);}

3, Dynamic Call Procedure If we need to implement a dynamic calling program function, you must use the loadLibrary () and getProcAddress () methods in the Windows API function, and pointed out the function position in the library, for example, the following is the calling program. General code:

Hinstance Dd; INT _STDCALL (* DDD); DD = loadingLibrary ("xxx.dll"); ddd = getProcaddress (DD, "TEST"); caption = INTOSTR (DDD ()); FreeElibrary (DD);

4. Query the memory information, you know that you can reasonably allocate the use of memory, allow your computer to reach a high running efficiency; how can you reasonably use allocation memory? As long as you know the capacity of current memory at any time, you can provide possible allocation of memory to accurately and reasonably. To this end, the author uses C Builder here to help everyone, accurately obtain memory information in the computer, below is part of the program's original code: void __fastcall tform1 :: Button1click (Tobject * sender) {MemoryStatus Meminfo; meminfo.dwlength = Sizeof (MEMORYSTATUS); GlobalMemoryStatus (& MemInfo); // GlobalMemoryStatus main function is to obtain memory IntToStr (MemInfo.dwMemoryLoad); // display the currently used memory IntToStr (MemInfo.dwTotalPhys); // show all physical memory IntToStr (MemInfo. dwavailphys); // Displays unused physical memory INTOSTR (Meminfo.dwtotalVirtual); / / Displays virtual memory space size INTOSTR (Meminfo.dwavailVirtual); / / Displays unused virtual memory space size}

5. Get the IP address in your computer If you are a system administrator, you may want to view the IP address information of each computer, follow the general method to see more cumbersome, so we can use the following code to implement the IP The function of the address:

Void __fastcall tform1 :: button1click (TOBJECT * Sender) {hostent * p; char s [128]; char * p2; gethostname (s, 128); // Get the name of the specified computer P = gethostByName (s); memo1-> LINES-> add (p-> h_name); p2 = inet_ntoa (* (in_addr *) p-> h_addr)); // Get the IP address of the specified computer Memo1-> Lines-> Add (p2);

6. Take MEMO rows and columns If we want to use C Builder to get MEMO row and column information, you can follow the steps: First re-establish an app in C Builder, and add two TLabel on the form Form1 The component name is label1, label2; then add two TBUTton components named Button1, Button2, and add a TMEMO component named MEMO1, and finally enter the original code below the code editor:

void __fastcall TForm1 :: Button1Click (Tobject * Sender) {Label1 → Caption = SendMessage (Memo1 → Handle, EM_LINEFROMCHAR, -1,0) 1;} void __fastcall TForm1 :: Button2Click (Tobject * Sender) {Label2 → Caption = Memo1 → SELSTART-SendMessage (Memo1 → Handle, EM_LINEINDEX, -1, 0) 1;

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

New Post(0)