API skill assembly (1) 1. Drag no title form: Contains header file: #include "winuser.h" Add the following code in the onmousedown event of the form or component: if (Button == Mbleft) {ReleaseCapture () SendMessage (Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);} II, pop-up and close the optical drive: including header files: #include "mmsystem.h" Add: McIndstring ("Open Cdaudio Alias Cd Wait Shareable" 0, 0, 0); 1, use when pop-up: McISendString ("SET CD Door Open", 0, 0); 2. Use when to turn off the optical drive: McISendString ("Set Cd Door Closed", 0 , 0, 0); 3, extraction icons: includes header files: #include "shellapi.h" example: ticon * icon = new ticon (); Ansistring filename = "c: //windows/system/shell32.dll "; int totalicon; // Get the total icon of the file shell32.dll Totalicon = (int) extracticon (form1-> handle, filename.c_str (), -1); // Extract the first icon, 0 is the first One, 1 is second, class push ... icon-> handle = extracton (form1-> handle, filename.c_str (), 0); // Save icon icon-> savetofile ("C: //1.ico "); 4, set the top window (Yong on top): Contains header files: #include" winuser.h "1, set the top window setWindowPos (Handle, Hwnd_topmost, 0, 0, 0, 0, swp_nomove || swap_nosize); 2. Cancel the top window setWindowPos (Handle, Hwnd_notopmost, 0, 0, 0, 0, SWP_NOMOVE || SWP_NOSIZE);
API skills set (2) 12/3/2000 0: 0: 0 · · "East Liang ·· Yesky (1) The irregular window Windows is just a standard rectangular window. To create an irregular window, you need to call the API function. to fulfill. Building an irregular window, typically establish an irregular area with the API function of the creating area, and then use the API function setWindowRGN to change the area of the window. These API functions are included in the C Builder in the header file Wingdi.h and Winuser.h, so use these API functions, you must first add statements that contain the header file in the program head: include "Wingdi.h" Include " Winuser.h "setWindowRGN function can change the area of a window, the function has three parameters, the first parameter hWnd is the window handle of the area, the second parameter hrgn is the area that wants to set, the third parameter BredRaw is generally set True, an immediate redraw window. There are several API functions used to create a region, and there are three most commonly used: 1. CreateRectrGN functions to create a rectangular area determined by X1, Y1, and X2, Y2 coordinate points. When the coordinate points X1 and Y1 are equal, X2 and Y2 are also equal, and a square is created. Example: // Create a rectangular hrgn hRect = CreateRectrGN (0,0,400,200); setWindowRgn (Handle, HRECT, TRUE); // Create a square hRGN HRECT = CreateRectrGN (0, 0, 300, 300); setWindowRgn (Handle, HRECT, TRUE); 2, The CreateellLipTicRGN function is used to create an ellipse of the rectangle determined by X1, Y1, and X2, Y2 coordinate points. Similarly, X1, Y1, and X2, the rectangle determined by the Y2 coordinate point is a square, the created is a circular shape.
Examples: // Create oval HRGN hElliptic = CreateEllipticRgn (0,0,400,250); SetWindowRgn (Handle, hElliptic, true); // Create a circular HRGN hElliptic = CreateEllipticRgn (0,0,400,400); SetWindowRgn (Handle, hElliptic, true); 3 The CombinerGN function can combine two zones into a new area. It has four parameters. The first parameter hrgndest saves the merged new area, the second parameter hrgnsrc1, three parameters hrgnsrc2 for the two areas to merge , The fourth parameter fncombinemode is a regional combination, and its value is one of the following combination modes: combined manner, RGN_and, establish two regions, RGN_COPY builds the copy RGN_DIFF to establish two regign of two regions, uncharged part of the part of the two regign A part of the area of the area RGN_XOR establishes some examples other than two areas: // Creating a combined shape of a circular and rectangular intersection hrgn hRect = CreateRectrGN (0, 0, 300, 300); hrgn helliptic = CreatellipticRGN (0,0,400,250) Combinergn (HRECT, HRECT, HELLIPTIC, RGN_OR); setWindowRgn (Handle, HRECT, TRUE); When the window is required to be restored to a standard Windows rectangular window, just set the SETWINDOWRGN function to 0, such as: setWindowRgn Handle, 0, true); API skill set (2) (2) Get the number of system sound cards When we write a multimedia program (such as a player), sometimes you need to detect whether the sound card is installed in your computer, if not The sound card program will terminate. Here, we should use the API functionWaveoutGetNumDevs to call this function to return to the number of sound cards installed in the system. In C Builder 5.0, it is included inside the header file "mmsystem.h". Example: 1. First, add the code containing the header file in the program head: #include "mmsystem.h" 2, add the following code in the oncreate event: int Num; // Num = WaveoutGetNumDevs (); if (num) showMessage ("You have installed" INTOSTR (NUM) "block sound card"); else {showMessage ("You don't have the sound card! / n program termination!"); close (); } 3, compile the running program. API Skills Set (2) (3) Obtaining, setting the interval between the mouse double-clicked within the specified interval, the continuous mouse click operation is called double-click, and the time to double-click interval can be changed in the mouse properties in the control panel. To get or set up the interval time of the mouse in your self-compiled application, we only need to use the two API functions of Windows GetDoubleClickTime and SetDouBleClickTime. Calling getDoubleClicktime can return the interval time of the mouse to double-click, and use SetDoubleClickTime, you can set the time of the mouse to double click.
Let us make a simple program for obtaining and setting up the mouse double-break interval: First, create a new project in Borland C Builder 5.0, add two Button components to the form Form1, and change their CAPTION attributes to " Get Dangent Interval Time "and" Set Double-click Interval Time ", add an EDIT component, change the Text property of Edit1 to" 200 ", add a Label component, change the CAPTION property to" milliseconds ". Then, double-click button button1, add the following code in its OnClick event: // Return to the mouse Double-click interval ShowMessage ("Double-click time is" INTSTOSTR (getDoubleClickTime ()) "milliseconds"); Double-click button button2, also add code in its OnClick event: // Set the mouse Double-click time SETDOUBLECLICKTIME (STRTOINT (Edit1 - $ # @ 62; text)); Finally, press F9 to compile run the program. Click the "Get Danger Interval" button in the window to pop up a time to display the current system mouse, if you want to set the mouse double-click interval, just change the value in the text box, such as 300, then click "to double click The interval time button is OK. It should be noted that the unit of the mouse double-hit interval is milliseconds, the smaller the value of the setting, the smaller the interval, the faster the speed of the double click, the system default is 400 milliseconds, but don't set it too little, otherwise "My Computer" will not beaten (your speed is not fast enough, ^ _ ^). API Tips (II) (4) Start Control Panel Console Applications There are a lot of control panel projects in the control panel, which is console applications, they are all standard DLLs (dynamic link libraries) files, we often Windows needs to be configured by them. Rundll32.exe is dedicated to calling a DLL file. In C Builder programming, we can use the API function WINEXEC to run external programs Rundll32.exe calling DLL to implement the console application of the launch control panel.
The following is some examples of collecting some calling DLL launch console applications: 1. Open the control panel Winexec ("Rundll_Rundll", SW_SHOWNORMAL); 2. Open mode dialog box Winexec ("Rundll32.exe shell32. dll, OpenAs_RunDLL "c: //autoexec.bat" ", SW_SHOWNORMAL); 3, adding ModemWinExec (" rundll32.exe shell32.dll, Control_RunDLL modem.cpl ,, add ", SW_SHOWNORMAL); 4, Add printer WinExec (" rundll32 .exe shell32.dll, SHHelpShortcuts_RunDLL AddPrinter ", SW_SHOWNORMAL); 5, copy disk WinExec (" rundll32.exe diskcopy.dll, DiskCopyRunDll ", SW_SHOWNORMAL); 6, mouse WinExec (" rundll32.exe shell32.dll, Control_RunDLL main.cpl ", SW_SHOWNORMAL); 7, network WinExec (" rundll32.exe shell32.dll, Control_RunDLL netcpl.cpl ", SW_SHOWNORMAL); 8, password WinExec (" rundll32.exe shell32.dll, Control_RunDLL password.cpl ", SW_SHOWNORMAL); 9 , game controllers WinExec ( "rundll32.exe shell32.dll, Control_RunDLL joy.cpl", SW_SHOWNORMAL); 10, date / time WinExec ( "rundll32.exe shell32.dll, Control_RunDLL timedate.cpl", SW_SHOWNORMAL); 11, Internet Property Winexec ("Rundll_Rundll INETCPL.CPL", SW_SHOWNORMAL); 12, Add / Remove Programs / / Installation / Uninstall Winexec ("Rundll32 .exe shell32.dll, Control_RunDLL appwiz.cpl ,, 1 ", SW_SHOWNORMAL); // Windows installation WinExec (" rundll32.exe shell32.dll, Control_RunDLL appwiz.cpl ,, 2 ", SW_SHOWNORMAL); // boot disk WinExec ( "Rundll32.exe shell32.dll, control_rundll appwiz.cpl, 3", sw_shownormal); 13, zone setting // region set WINEXEC ("Rundll_Rundll Intl32.dll, Control_Rundll INTL.CPL, 0", SW_SHOWNORMAL); // Digital Winexec ("Rundll_Rundll INTL32.DLL, Control_Rundll INTL.CPL, 1", SW_SHOWNORMAL); / / Money WINEXEC ("Rundll_Rundll Intl32.dll, Control_Rundll INTL.CPL, 2", SW_SHOWNORMAL); // Time Winexec ("Rundll_Rundll 32.dll, Control_Rundll INTL.CPL, 3", SW_SHOWNORMAL); // Date Winexec ("
Rundll32.exe shell32.dll, control_rundll INTL.CPL, 4 ", SW_SHOWNORMAL); 14, auxiliary option // Keyboard Winexec (" rundll32.exe shell32.dll, control_rundll access.cpl, 1 ", sw_shownormal); // Sound Winexec ("Rundll32.exe Shell32.dll, Control_Rundll Access.cpl, 2", SW_SHOWNORMAL); // Displays Winexec ("Rundll_Rundll Access.cpl, 3", SW_SHOWNORMAL); // mouse WinExec ( "rundll32.exe shell32.dll, Control_RunDLL access.cpl ,, 4", SW_SHOWNORMAL); // General WinExec ( "rundll32.exe shell32.dll, Control_RunDLL access.cpl ,, 5", SW_SHOWNORMAL); 15, // audio Display WinExec ( "rundll32.exe shell32.dll, Control_RunDLL mmsys.cpl ,, 0", SW_SHOWNORMAL); // video WinExec ( "rundll32.exe shell32.dll, Control_RunDLL mmsys.cpl ,, 1", SW_SHOWNORMAL) ; // MIDIWinExec ( "rundll32.exe shell32.dll, Control_RunDLL mmsys.cpl ,, 2", SW_SHOWNORMAL); // CD music WinExec ( "rundll32.exe shell32.dll, Control_RunDLL mmsys.cpl ,, 3", SW_SHOWNORMAL) ; // Equipment WINEXEC ("Rundll_Rundll MMSys.cpl, 4", SW_SHOWNORMAL); 16, System // General Winexec ("Rundll32.exe shell32.dll, control_rundll sysdm.cpl, 0" , SW_SHOWNORM Al); // Device Manager Winexec ("Rundll_Rundll Shell32.dll, Control_Rundll Sysdm.cpl, 1", SW_SHOWNORMAL); / / Hardware Profile WINEXEC ("Rundll32.exe shell32.dll, control_rundll sysdm.cpl, , 2 ", SW_SHOWNORMAL); // Performance WINEXEC (" Rundll_Rundll SHell32.dll, Control_Rundll Sysdm.cpl, 3 ", SW_SHOWNORMAL); 17, Display / / Background Winexec (" Rundll32.exe shell32.dll, control_rundll desk .cpl, 0 ", sw_shownormal; // screen protection Winexec (" Rundll_Rundll Desk.cpl, 1 ", SW_SHOWNORMAL); // Appearance Winexec (" Rundll32.exe shell32.dll, control_rundll Desk.cpl, 2 ", sw_shownormal); // Set WINEXEC (" Rundll_Rundll Desk.cpl, 3 ", SW_SHOWNORMAL);
These examples can be used in Windows 98 and Windows 2000, provided that the project is installed in the control panel. API skill collection (3)
(1) The title bar of the scintillation program is in some professional applications, and when the program needs to remind the user or to cause the user's attention, the title bar of the program is kept. To implement this feature, only one TIMER component and use an API function - FlashWindow. Using the API function flashWindow can flash to display the specified window, let the window switches between activities and non-active status, it has two parameters: hwnd and binvert, the header file is "Winuser.h". Where the parameter hWnd is a window handle to flash. When the parameter binvert is a BOOL variable, when the program window title bar is switched from the active state, or switch, when set to false, the window title bar is restored. For the initial state. If you work with a time component (Timer component), execute statement at a certain time interval: FlashWindow (Form1 - $ # @ 62; handle, true); the title bar of the program window is in the event, non-active status Switch. If you specify hWnd to become an application's handle (Application - $ # @ 62; handel), the program bar will be blocked on the taskbar. Let's take a blinking window title bar and program on the taskbar. First, add three buttton button1, button2, button3 to Form1, the properties of the "flash window title bar", "Flashing Task Title Bar", "Blinking Task Title Bar", and "Stopping Flash", add two time components Timer1 and Timer2, Setting the Enabled attribute of the two Timer components to false, setting the interval property to 500 (ie, half;), changing the value of this property can modify the frequency of the flicker. Then, double-click Timer1, add: FlashWindow (FLASHWINDOW (Form1 - $ # @ 62; Handle, True); Double-click Timer2, add: FlashWindow (Application - $ # @ 62; Handton1 Add: Timer1 - $ # @ 62; enabled = true; Double-click Button2, add: Timer2 - $ # @ 62; enabled = true; Finally, double click Button3, in Button3 Onclick event Add: Timer1 - $ # @ 62; enabled = false; Timer2 - $ # @ 62; enabled = false; FlashWindow (Form1 - $ # @ 62; handle, false); FlashWindow (Application - $ # @ 62; Handel, false); This, a simple example is completed. Press F9 to compile the running program, you can flash the window title bar or the flashing task bar? The title bar. (2) Drag the current Windows application now, mostly use the graphical interface, irregular window technology, so that the program interface is more beautiful. However, using the interface, you should first remove the title bar of the form (in BCB, set the Border attribute of the form to bsnone, you can remove the title bar of the form), so you can't use the original title bar, There is a problem that the window cannot move.
How do you use a mouse to drag the form without the title bar? We can use Windows's API function sendMessage to solve this problem. First, create a new project, set the Border attribute of the form to BSnone to remove the form of the form, press the F12 key to switch to the code editing window, add the code containing the header file "Winuser.h": #include $ # @ 60; Winuser.h $ # @ 62; then add the following code in the form of the onMouseDown event: if (Button == Mbleft) // Decisive whether the left mouse button is pressed {ReleaseCapture (); // Release the mouse Operation SendMessage (HTCAPTION, 0);} This, you can implement the window with the left mouse button to drag without the title. An assembly can also be added to the form, and then add the above code in the onmousedown event of the component, which can also sit in the component drag window. You can also modify the first parameter of the SendMessage function to this component's handle, such as: Add a Button component to the form, add the above code in its OnMouseDown event, which change the sendMessage to: SendMessage Button1 - $ # @ 62; Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0); This allows you to move Button1 with a mouse when running in the program. (3) Hiding program In the taskbar icon Using the API function showWindow can hide a program in the taskbar icon, which is included inside the header file "Winuser.h". 1. The code of hiding the task bar icon is: showWindow (Application - $ # @ 62; handle, sw_hide); 2, use when you want to redish: showwindow (Application - $ # @ 62; handle, sw_show); however, If the program is minimized, the icon at the taskbar will reappear. To minimize the program restore, the program is re-hidden in the taskbar of the taskbar, you can join the hidden program in the form's onpaint event, so that the program is only the taskbar when the program is minimized. An icon will appear, and the icon will be re-hidden when the program restore is minimized.
API skills (3) (4) Restart, turn off Windows When users modify some settings in Windows, Windows often ask if the computer is to restart, when the user points YES, the computer will automatically restart. This is a typical application of the API function exitwindowsex. EXITWINDOWSEX, as the name refers to exiting the Windows function, there are two parameters, the first is to exit the Windows option, commonly used: EWX_REBOOT, EWX_SHUTDOWN, EWX_LOGOFF (Logout Current User), Second The parameter system is not used, can be set to 0. In a self-compiled program (such as a registry modification program), when the user modifies a setting to restart the computer, use the EWX_REBOOT option to restart the computer. Such as: EXITWINDOWSEX (EWX_REBOOT, 0); use wx_shutdown options to implement shutdown. Such as: EXITWINDOWSEX (EWX_SHUTDOWN, 0); use the EWX_LOGOFF option when you need to log out. Such as: EXITWINDOWSEX (EWX_LOGOFF, 0);
API skill set (4) function name: setWindowPos header file: WinUser.h function prototype: BOOL SETWINDOWPOS (HWND HWND, // Window Handle HWND HWNDINSERTAFTER, / / Arrangement Handle INT X, // Level Coordinate Int Y, // Vertical Coordinate INT CX, // Wide INT CY, / / High Uint UFLAGS // Window Positioning Identity); Description: This function can change the size of the window, position, and setup sub-windows, pop up the window, or the top window. Return Value: BOOL, if the return value is non-zero means success, return zero means failed. For error messages, see the getLastError function. Parameter Table: Parameter Type and Description HWND HWnd, want to locate the window handle HWndInsertAfter HWnd, placed in the window handle in front of HWnd. This parameter must be one handle of the window or one of the following values: HWND_BOTTOM places the window in the bottom of other windows HWND_NOTOPMOST to place the window at the top of all other windows and located behind any top window. If this window is not top window, this tag does not generate the window to put the window to top the window in all the windows to place the window on the top of all the other windows and located in front of any top window. Even if this window is not an active window, it also maintains the top state x: int, specifies window new X coordinate Y: int, specified window new Y coordinate cx: int, specified window new width cy: int, the new height of the specified window WFLAGS: UINT, specify the tag of the window status and location. This parameter uses the combination of the following value: SWP_DRAWFrame The window draws a box SWP_FRAMECHANGED sends a WM_NCCALCSIZE message to enter the window, even if the size of the window does not change. If this parameter is not specified, the message wm_nccalcsize only sends SWP_HIDEWINDOW Hidden Window SWP_NOACPyBITS Mask Customer Area SWP_NOWNOMOVE to keep the current location (X and Y parameters) SWP_NOOWNOWNOWNOMDER does not change all windows. Location and arrangement order SWP_NOREDRAW window does not automatically redraw SWP_NOREPOSITION the SWP_NOOWNERZORDER numerals r> SWP_NOSENDCHANGING prevent the window receiving WM_WINDOWPOSCHANGING message SWP_NOSIZE holding current size (cx and cy are ignored) the SWP_NOZORDER holding window current position in the list (hWndInsertAfter are ignored) SWP_SHOWWINDOW display window Remarks: If a SWP_SHOWINDOW or SWP_HIDEWINDOW tag is set, this window does not move or change the size. After the window becomes the top window, all of its sub-windings will also enter the top. Once it is set to non-top, all of its sub-windings will also turn to non-top.
Related functions: MoveWindow, SetActiveWindow, SetForegroundWindow example: // Set top window SetWindowPos (Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE || SWP_NOSIZE); // cancel topmost window SetWindowPos (Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE ||; AP_NOSize); API Skill Set (4) Super Link Effects in Many Shared Software About dialogs with some hyperlinks, such as homepage URL or E-mail, mouse shift When it is above it, the text turns red. When the mouse is left, the text changes back to the original blue. If you click this link with the mouse, you will pop up the browser window open the specified URL or run the default E-mail. The program writes a new message, just like the true hyperlink. Do you want to do one in your program? In fact, we only need to call the API function shellexecute and change the color of the text when the mouse moves, you can have this effect in your own program. First create a new project, add two Label components on the form FORM1, and their Name property uses the default Label1 and Label2. Then add code in the oncreate event in Form1: label1 - $ # @ 62; cursor = crhandpoint; label2 - $ # @ 62; cursor = crhandpoint; label1 - $ # @ 62; font - $ # @ 62; color = CLBLUE; Label2 - $ # @ 62; font - $ # @ 62; color = CLBLUE; Label1 - $ # @ 62; caption = "Home: Beginner House"; label2 - $ # @ 62; caption = "e-mail : Fdlweb@sina.com "; Add: // Blue word in Label1, please change to your home address shellexecute (handle, null," http://fdlweb.myrice.com / "NULL, NULL, SW_SHOWNORMAL); Add: Label1 - $ # @ 62; font - $ # @ 62; color = CLRED; Add: // Blue word in Label2 on the onclick event Cheng Yellexecute (Handle, NULL, "Mailto: fdlweb@sina.com", null, null, sw_shownormal; add: label2 - $ # @ 62; color = CLRED Finally, in the ONMOMOVE event in Form1: Label1 - $ # @ 62; font - $ # @ 62; color = CLBLUE; Label2 - $ # @ 62; font - $ # @ 62; color = CLBLUE; code input, Press the F9 compilation to run the program to see the effect. The copy screen Bitblt function can copy a bitmap from a device scenario to another, which is often used in the graphic program and game programming, or can be used to do a desktop-based screen saver.
Let us use the Bitblt function to make a false desktop program: First, add an image component to the form, set the Border of the form FORM1 to: bsnone. Then the oncreate event in the form is added to the program code: left = 0; TOP = 0; width = screen - $ # @ 62; width; height = screen - $ # @ 62; height; image1 - $ # @ 62; left = 0; image1 - $ # @ 62; TOP = 0; Image1 - $ # @ 62; width = screen - $ # @ 62; width; image1 - $ # @ 62; height = screen - $ # @ 62; height; / / This code is to copy the desktop to the component image1 to store, // where getDC (0) returns the handle of the desktop device (HDC) Bitblt (image1 - $ # @ 62; canvas - $ # @ 62; handle, 0, 0, Screen - $ # @ 62; Width, Screen - $ # @ 62; Height, Getdc (0), 0, 0, Srccopy); Press F9 to run, a fake desktop comes out, on this "desktop" How to make a react according to the mouse, can be used to catch people! . Some desktop games are also doing, you can add more features on this program, such as adding the Label components and Timer components on the form, using the TIMER component to control the Label components on the form In addition, the code "close ();" close (); finally, the extension of the translated program is changed to SCR, and finally, a text is chaotic on the desktop. The moving screen saver is. Take the total space of the disk and the remaining space to get the total space and remaining space, the simplest and straightforward method is to call the API function getDiskFreespace. The getDiskFreespace function has 5 parameters. The first parameter is to determine the drive name of the available space. The second parameter is a variable that stores the number of sectors per cluster. The third parameter is a variable that stores each segment of the number of fields. The fourth parameter is a variable that stores the number of remaining clusters, and the fifth parameter is a variable that stores total clusters. The total space or remaining space of the specified drive can be obtained with the formula of the corresponding calculation disk space. The calculation formula of the total space of the disk and the remaining space is: the remaining space (byte) = the number of sectors of the cluster * sector number * The total space (byte) of the remaining cluster (bytes) = cluster sector Number of sectors * The total number of characters in the sector is the total space and the total space of the C disk and the remaining space: unsigned long secondors, Bytes, Free, Total; GetDiskFreespace ("C: ///", & Sectors, & Bytes, & Free , & Total); // Available Space (Unit: MB) INT FreeKB = BYTES * SECTORS * Free / 1024; // Total Space (Unit: MB) Int Totalkb = BYTES * SECTORS * TOTAL / 1024; ShowMessage ("C Dish The available space is: " INTOSTR (freekb) " MB, the total space is: " INTSTR (TOTALKB) " MB "); API skills set (5)
Extract Icon Tune API Function Extractic You can extract icons in the program file, its header file is shellapi.h, prototype: HiCon Extracticon (Hinstance Hinst, // Example Handle LPCTSTR LPSZEXEFILENAME, // To extract the icon of the icon File name uint niconIndex // The index of the icon to extract); when calling the function, the parameter Hinst is generally set to the current application instance handle, such as form1 - $ # @ 62; handle. The parameter lpszexefilename is a full path to the program file that needs to extract the icon. This program file can be an Exe file, a DLL file, an ICO file, and the like, as long as it is a file containing the icon resource, you can extract icons. When the parameter niconIndex specifies an index of an icon to return the handle of the icon, if there is no icon in the specified file, return zero, return zero, when the parameter niconIndex is set to -1, the function returns the total number of icons. The handle returned by the function can assign a variable that is declared with a TICON class, and then saves the icon to save the icon using the savetofile method of this variable. Example: ticon * icon = new ticon (); Ansistring filename = "c: //windows//system//shell32.dll"; int totalicon; // Get file shell32.dll's total icon total icon Totalicon = (int) extracticon (Form1-> Handle, FileName.c_STR (), -1); // Extract the first icon, 0 is the first, 1 is the second, the class push ... icon-> handle = extracton (Form1-> Handle, filename.c_str (), 0); // Save Icon Icon-> SaveTofile ("C: //1.ico"); below gives a complete icon extraction program source code. This program requires four button controls (Button), four text tab control (Label), two text box controls (Edit), a horizontal scroll bar control (Scrollbar), an open file dialog control (OpenDialog), a save File dialog control (Savedialog) and a picture control (Image), and a Panel control is decorated. The interface is shown in the figure: the various controls are arranged, then modify one of the four Label controls, the final input program code, run the program, a program extracted the icon, you will not have an icon in the future. Resources can be used and worried.
Program list (Unit1.cpp): // --------------------------------------- --------------------- # c @ 60; vcl.h $ # @ 62; #pragma hdrstop # include "unit1.h" // -------------------------------------------------- ------------ # pragma package (smart_init) #pragma resource "* .dfm" TFORM1 * FORM1; ANSISSIING FILENAME; TICON * icon = new ticon (); int totalicon; // --- -------------------------------------------------- -----------__ fastcall tform1 :: tForm1 (tcomponent * oowner: tform (oowner) {} // -------------------- ------------------------------------------- void __fastcall tform1 :: formcreate (TOBJECT * SENDER) {CAPTION = "Icon thief 1.0"; button1 - $ # @ 62; caption = "Select File"; Button2 - $ # @ 62; caption = "Save Icon"; Button3 - $ # @ 62; CAPTION = "Save all"; Button4 - $ # @ 62; caption = "exit"; edit1 - $ # @ 62; text = 0; edit2 - $ # @ 62; text = 0; image1 - $ # @ 62; width = 32; Image1 - $ # @ 62; height = 32; OpenDialog1 - $ # @ 62; filter = "executable file (* .exe, *. Dll) | * .exe; *. Dll | icon file (* .ico ) | *. *. *) | *. * "; Savedialog1 - $ # @ 62; filter =" icon file | *. "; scrollbar1 - $ # @ 62; enabled = false; button2- $ # @ 62; enabled = false; Button3 - $ # @ 62; enabled = f Alse;} // --------------------------------------------- ------------------- void __fastcall tform1 :: button1click (tobject * sender) {IF (OpenDialog1 - $ # @ 62; execute ()) {Totalicon = (int) EXTRACTICON (Form1 - $ # @ 62; Handle, OpenDialog1 - $ # @ 62; filename.c_str (), -1); if (Totalicon $ # @ 62; 0) {IF (Totalicon $ # @ 60; 2) Scrollbar1 $ # @ 62; enabled = false; Elsescrollbar1 - $ # @ 62; max = Totalicon-1; button2 - $ # @ 62; enabled = true; button3 - $ # @ 62; enabled = true; filename = OpenDialog1- $ # @ 62; filename; Edit1 - $ # @ 62;
Text = Totalicon; Icon - $ # @ 62; handle = extracticon (Form1 - $ # @ 62; handle, filename.c_str (), 0); Image1 - $ # @ 62; picture - $ # @ 62; icon = icon ; Edit2 - $ # @ 62; text = 1;} else {showMessage ("This file is not icon");}}} // ---------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------- void __fastcall tform1 :: button2click (TOBJECT * Sender) {if (Savedialog1 - $ # @ 62; execute ()) {// Save icon icon - $ # @ 62; savetofile (Savedialog1 - $ # @ 62; filename);}} // --- -------------------------------------------------- ----------- void __fastcall tform1 :: button3click (TOBJECT * Sender) {IF (Savedialog1 - $ # @ 62; execute ()) // Abstract all icon for (int i = 0; i $ # @ 60; Totalicon-1; i ) {icon - $ # @ 62; handle = extracton (form1 - $ # @ 62; handle, filename.c_str (), i); icon - $ # @ 62; savetofile Savedialog1 - $ # @ 62; filename (ANSISTRING) i ". ICO");}} // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------ Void __fastcall tform1 :: button4click (TOBJECT * Sender) {Close } // --------------------------------------------- ------------------- void __fastcall tform1 :: scrollbar1change (TOBJECT * Sender) {Edit2 - $ # @ 62; tex T = Scrollbar1 - $ # @ 62; position 1; icon - $ # @ 62; handle = extracton (Form1 - $ # @ 62; handle, filename.c_str (), scrollbar1 - $ # @ 62; position1 - $ # @ 62; Picture - $ # @ 62; icon = icon;} // -------------------------------------------------------------------------------------------------------------------------- ----------------------------------
Determining the type of drive using the API function getDriveType can determine the type of drive, the function returns an INT type value, when the return value is 2, is a floppy disk; 3, it is a hard disk; 4, it is a network map; When 5, it is a CD-ROM. At 6, it is a RAM disk; when it is other value, it is an illegal drive letter. This API function is included in the winbase.h header file, first add statement in the program header: include $ # @ 60; winbase.h $ # @ 62; contain the header file, then add the following code to the program to judge the drive Type: int DRV; // Here "C: //" is the drive letter DRV = getDriveType ("C: //"); Switch (DRV) // determines the value of the DRV {CASE 2: // DRIVE_REMOVABLEShowMessage ( "floppy disk"); break; case 3: // DRIVE_FIXEDShowMessage ( "hard"); break; case 4: // DRIVE_REMOTEShowMessage ( "network map disk"); break; case 5: // DRIVE_CDROMShowMessage ( "CD-ROM") Break; Case 6: // Drive_ramdiskShowMessage ("RAM Disk"); Break; Default: ShowMessage ("This disk does not exist!"); Break;} Note: The value after the CASE statement can also be replaced with the constant after the comment. Such as 2 can be replaced with constant drive_removable. API skills set (7)
The window minimizes, maximizes and restores, by calling the API function showWindow to control the status of the specified window, minimize the window, maximize or restore the original state, and so on. Although the window can also minimize, maximize or restore the control buttons on the window title bar, but the showWindow function can achieve more features, and the window minimizes the window to the desktop, these are standard control The button can't do. Here is an example of a showwindow function. This example demonstrates how to minimize a window to the desktop or minimize the taskbar and maximize, and restore the original state. First, create a new project in C Builder, in order to facilitate demonstration, the project requires two windows. The method of adding the second window FORM2 is: Select "New Form" under the "File" menu. After adding a new window, select "Include Unit HDR ..." under the "File" menu contains the header file "Unit2.h" of the window FORM2, or add "#include" directly in the head of the code editing window of Form1. "Unit2.h" statement. Then put four buttons on Form1, their CAPTION attributes are "maximized", "minimize desktop", "recovery", and "minimize the taskbar and restore". Next, double-click the window piece form1, add: void __fastcall tform1 :: form __fast * sender) {// Set Form1 is top window Form1 - $ # @ 62; formstyle = fsstayontop;} Double-click button Button1, Add: void __fastcall tform1 :: button1click (TOBJECT * Sender) {// Maximize ShowWindow (Form2 - $ # @ 62; Handle, SW_MAXIMIZE);} Double-click button button2, join in its OnClick event : Void __fastcall tform1 :: Button2click (TOBJECT * Sender) {// Minimizes to Desktop ShowWindow (Form2 - $ # @ 62; Handle, SW_MINIMIZE);} Double-click Button3, add: void __fastcall tform1 in its OnClick event: void __fastcall TFORM1: : Button3Click (TOBJECT * Sender) {// Restore minimization showWindow (Form2 - $ # @ 62; handle, sw_restore);} {{秪峈 秪峈 郔 苤 赵 赵 恄魊 ◆ ◆ ◆ 棠 棠 棠 ◆ ◆ ◆ ◆ ◆ ◆ ◆ ◆ 棠 棠 棠;;;;;;;;;;;;;;;;;;;;;;;;;;;;;芼硌斯 譬 賱 阭 阭 utton4 cavity onclick 岈 笢 笢 笢 [峈? 虴 珆ㄛ 笢 笢 楼? 珨跺晊奀 珨跺晊奀 测 测 ㄩ Void __fastcall tform1 :: Button4click (Tobject * sender) { / / Minimize the taskbar showWindow (Application - $ # @ 62; handle, sw_minimize); // delay 1 second sleep (1000); // Restore minimization showWindow (Application - $ # @ 62; handle, sw_restore) At the end, compile the running program. Get the disk serial number, the volume and file system type Use the API function GetVolumeInformation, you can get information about a disk, such as the serial number of the disk, the volume, the file system type. Some software is encrypted using the serial number of the disk.
When you need to get the disk information, add the following code. You can: // Define the volumetric string variable buffer with a length of 255: ansistring volume = Ansistring :: stringofchar (", 255); // Serial number unsigned long SerialNumber; // Define file system type string buffer with a length of 20 Type string buffer ANSISTRING SystemName = Ansistring :: StringOfchar (", 20); // Get Disk Information GetVolumeInformation (" C: /// ", Volumename.c_STR (), 255, & serialnumber, 0, 0, systemname.c_str (), 20); showMessage ("Volumen of the C disk:" Trim (Volumename)); showMessage ("Serial number of the C disk:" INTOSTR (SerialNumber)) ShowMessage ("C-Document System Type:" Trim (SystemName)); Screen Magnifier You must have used the screen that comes with Windows98, you don't want to do it? Others, the key to this program is to use the API function Stretchblt. Call the API function stretchBLT can put a bitmap specified in a device from copy to another device, during copying, can also zoom bitmap as needed. The following is its prototype and parameter description: BOOL Stretchblt (HDC HDCDEST, / / Target Handle INT NXORIGINDEST, / / Target Rectangle X Coordinate INT NYORIGINDEST, // Target Rectangular Y coordinate int nwidthDest, // Target Rectangular width int NHEIGHTDEST, / / Target Rectangle High HDC HDCSRC, // Source Equipment Handle INT NXORIGINSRC, // Source Toleral X Coordinate INT NYORIGINSRC, // Source Rollength Left upper corner Y coordinate int NWIDTHSRC, / source The rectangular width int NHEIGHTSRC, / / source rectangular height DWORD DWROP / / raster calculation operation); the header file of the StretChblt function is "Wingdi.h". Among them, its DWROP parameters have 15 operations, the most commonly used copying operation SRCCOPY. When the rectangular size specified by the source device and the target device is not equal, the function is enlarged or reduced according to the size ratio of the source rectangle and the target rectangle, copies to the target device. Below is a rectangular bitmap that is 0x0, wide and high of 100 to 0x0, width and height of 100: Stretchblt (image1 - $ # @ 62; canvas - $ # @ 62 Handle, 0, 0, 50, 50, getDC (0), 0, 0, 100, 100, Srccopy; this code's GETDC (0) statement is the handle of the desktop device. If you continue to use the above code, put the screen to image1, which is a "screen shrinkage". Of course, the reduction screen does not have actual use, we can make "screen magnifying glass" as long as we change it. To do this "screen magnifying glass", first run Borland C Builder, put a picture control image1 and a time control Timer1 on the form form1.
Double-click Form1, add code in its oncreate event: void __fastcall tform1 :: form, @ 62; width = 200; image1 - $ # @ 62; height = 200; Timer1- $ # @ 62; interval = 10; // Set the top window setWindowPos (Handle, Hwnd_topmost, 0, 0, 0, 0, SWP_NOMOVE || Swp_nosize);} Double-click Time Control Timer1, add the following code in its ONTIMER event: Void __fastcall tform1 :: timer1timer (TOBJECT * Sender) {Int x, y; point curpos; // get the current coordinate getCursorpos (& curpos); // Guaranteed copy image is not on the screen IF (Curpos.x $ # @ 62 Screen - $ # @ 62; width - 100) x = screen - $ # @ 62; width - 100; Else IF (Curpos.x $ # @ 60; 50) x = 0; elsex = curpos.x-50; IF (curpos.y $ # @ 62; screen - $ # @ 62; height-100) y = screen - $ # @ 62; height-100; Else IF (curpos.y $ # @ 60; 50) y = 0 Elsey = curpos.y-50; caption = "coordinate:" INTTOSTR (curpos.x) "," INTOSTR (curpos.y); Image1 - $ # @ 62; canvas - $ # @ 62; fillRect RECT (0,0,200,200)); // copy magnificent image Stretchblt (image1 - $ # @ 62; canvas - $ # @ 62; handle, 0, 0, 200, 200, getdc (0), x, y, 100 , 100, srcopy;} The code is complete, press F9 or click the Run button to run the program. how about it? It's almost the same as Windows comes! It should be noted that: C Builder is like VB. The picture control can be non-persistent. In C Builder, it is not possible to directly call the StretchBLT function to get a coherent image, but must first use the picture control FillRect method to populate The picture box (equivalent to the empty picture frame), then call the StretChblt function. Time delay delay is very meaningful in programming! For example, the wait picture at the time of the program, or you need to wait for the completion of a process to run the code below, then use the time delay. But there is generally no ready-made delay function in many programming languages. In DOS's C era, when the program needs to be delayed, many people use for loop: for (int i = 0; I $ # @ 60; 10000; i ); now there may be people now. In the WIN32 era, a function of time delay has been provided in the system's API library, it is the SLEEP function. Of course, in Windows programming, you can also use the Timer control, but use the SLEEP function more convenient and fast. We only need to simply call the SLEEP function, you can realize the delay of time.
The SLEEP function has only one parameter cmilliseconds that specifies the time you need to delay, and its unit is millisecond. Let's look at the example below, please add the following code in a button: Sleep (3000); // Delay three second showMessage ("This dialog has been delayed for three seconds!"); This The example demonstrates a delayed dialog box, click the button, the dialog that is immediately popped up is delayed for three seconds. Transfer from http://www.xici.net/