VC + + API Invoke Dialog resource

Source: Internet
Author: User

Key technologies:

There are several API functions required for loading resources, and the following are some of these API functions.

A) FindResource is used to locate the referred resource in a specified module, such as the following syntax:

Hrsrc FindResource (hmodule hmodule, Lpcrstr lpname, LPCTSTR lptype);

Description of the parameters:

(1) hmodule: A module handle that includes the required information. If the program itself, it can be set to null;

(2) Lpname: The ability to make a resource name or resource ID.

(3) Lptype: Resource type. This is also the type of resource that you specify.

b) LoadResource is used to load all the resources into memory. The syntax is as follows:

Hglobal LoadResource (hmodule hmodule, hrsrc hresinfo);

Description of the parameters:

(1) hmodule: A module handle that includes the required information. The assumption is the program itself. can be set to null;

(2) Hreinfo: The resource handle that needs to be loaded. This is also the return value of FindResource;

c) The Lockresource is used to lock the resource data block in memory, and the return value is the pointer to the resource data that is to be used, such as the following syntax:

LPVOID Lockresource (Hglobal hresdata);

Description of the parameters:

Hresdata: Points to the resource data block in memory to be locked. This is also the return value of LoadResource.

Effects such as the following:

Design process:

1) Use VC6.0 to create a dialog-based application.

2) Add a static text control to the window. Right-click the dialog box. In the Popup shortcut menu, select the Properties command, set the window's Caption property to "API Invoke Dialog Resource", (2) See,

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvc2fucwltyq==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">

Figure (2) Import resource

3) in the resource View , click the right mouse button and Select the Import command from the shortcut menu that pops up. To eject the Import Resource dialog box, select a TXT file and click "Import".

4) Set a custom resource type in the "Define Resource Type" dialog box that pops up, enter "Text" here. (3) What is seen,

Figure (3) New Class wizard

5) Press Ctrl+w to enter the Class Wizard , add variables to the text control, (4) See,

Figure (4) Associating a variable with a control

6) Set the properties of the text box so that it has multiple lines of display and be able to display the scroll bar, (5) What you see,

Figure (5) sets the multi-line display and displays the horizontal vertical scroll bar

7) Click event to add "Load resource" button, dynamic load text resource appears in text box, code such as the following:

void Capiresourcedlg::onloadresource () {hrsrc hrsrc = FindResource (Null,makeintresource (IDR_TEXT1), text ("text")); (NULL = = HRSRC) return;//Gets the size of the resource DWORD dwsize = Sizeofresource (NULL,HRSRC); if (0 = = dwsize) return;//load resource hglobal Hglobal = L Oadresource (NULL,HRSRC); if (null = = Hglobal) return;//lock resource LPVoid pbuffer = Lockresource (hglobal); if (null = = pbuffer) return; m_edit = (char *) Pbuffer;this->updatedata (false); Unlockresource (HGLOBAL);//resource Unlocking FreeResource (HGLOBAL); Free resources}


VC + + API Invoke Dialog resource

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.