How to call Windows applications in C ++ Builder

Source: Internet
Author: User
Generally, Windows programmers often call various windows resources, such as paint brushes and tablets, to reduce programming difficulty and shorten programming time when writing Windows programs. For other programming languages, we generally use API functions to implement a function. How can we implement it in Borland C ++ builder? Recently, when I wrote the e-screen display software, I used the API function to implement this function.

The following describes how to use an API function to call a Windows paint brush:

1. Start c ++ builder and enter the menu file | new application to create a new project. Save the project to a project that contains the main window. In the main window, add the openpicturedialog1 and button1 controls to open the image dialog box.

2. Add # include in the file header of the Master File & Lt; shellapi. H & gt;

3. Add char BMP exec [100] to the private part of the header file.

4. Add the following code to the ondbclick event of button1:

Void _ fastcall tmainform1: button1click (tobject * sender)

{

Ansistring tempname;

Fileclose (filecreate ("testest.bmp "));

Findexecutable ("testest.bmp", null, BMP Exec); // return the handle to the executable file name //

Deletefile ("testest.bmp"); // delete a file //

Openpicturedialog1-> defaultext = string ("BMP ");

Openpicturedialog1-> filter = "image file (*. BMP) | *. BMP ";

Openpicturedialog1-> filename = "*. BMP ";

If (openpicturedialog1-> execute ())

{

If (openpicturedialog1-> filename. ansipos (".") & Lt; 1)

Openpicturedialog1-& gt;Filename = openpicturedialog1-> filename + ". BMP ";

// Add an extension to a file without an extension. In this case, filename is the full name of the file name //

Closehandle (createfile (openpicturedialog1-> filename. c_str (), // parameter 1 is the file name //

Generic_write, // parameter 2 File Access Mode: Set to file writable and file pointer //

File_into_write, // File Sharing Mode of parameter 3: The file can be modified if write access is allowed //

Null, // parameter 4 Security Attribute: use the default operator //

Open_always, // parameter 5: how to create a file if the file does not exist: if it is set to exist, it is opened. If it does not exist, it is created //

File_attribute_normal, // parameter 6, attributes and flag of the file. The file has no other attributes //

); // Close the opened transaction handle //

// The above Code sets the file to be shared, so that the following code can be smoothly executed //

Tempname = ansistring (BMP Exec); // convert Char to ansistring //

Tempname = tempname + "" + openpicturedialog1-> filename; // Application name + corresponding file to be processed //

Winexec (tempname. c_str (), sw_shownormal); // run the application //

}

}

5. Compile and execute. When the double-click button button1 is displayed, the program opens the image file dialog box, select the BMP file to open, you can call the Windows paint brush to open the selected BMP file.

After each statement, the author adds comments. If you are interested, try again.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.