[VC programming skills] dynamic link library? 1.1 call an icon in the Dll

Source: Internet
Author: User
Introduction I have been a programmer for almost three years, but I have not learned much about programming. Since the company's project team has been maintaining products of the 70 or 80 s, the amount of new regulation development in one year is limited, and more is maintenance and materials, and gradually began to become unfamiliar with programming. As a programmer who does not write a program, I think this is a sorrow,

Introduction I have been a programmer for almost three years, but I have not learned much about programming. Since the company's project team has been maintaining products of the 70 or 80 s, the amount of new regulation development in one year is limited, and more is maintenance and materials, and gradually began to become unfamiliar with programming. As a programmer who does not write a program, I think this is a sorrow,

Introduction

I have been a programmer for almost three years, but I have not learned much about programming. Since the company's project team has been maintaining products of the 70 or 80 s, the amount of new regulation development in one year is limited, and more is maintenance and materials, and gradually began to become unfamiliar with programming.

As a programmer who does not write a program, I think this is a kind of sorrow, because when we were young, we had to accumulate a piece of things on the road, and the subsequent life would not be empty. So I decided to pick up the technology again. I hope you can give me support and help.

Over the past two years of maintenance, I feel that technology can only be used in projects. Because our time is limited after all, I chose the technologies that I often encounter in my work to start my own development.


Main Content
  1. Dynamic Link Library
  2. File
  3. Form
  4. Widget
  5. Network
  6. System


Let's start with the dynamic link library!

Dynamic Link Library

The Dynamic Link Library (DLL) is short for Dynamic Link Library. DLL is a Library that contains code and data that can be used by multiple programs at the same time, its advantage lies in data and resource sharing. It is easier to modularize the project and improve the project development efficiency. When the dll content is changed, as long as the interface remains unchanged, the original modules that call and change the dll do not need to be re-compiled, which is easy to maintain, it also saves costs. It is easy to implement the multi-language version of the software, skin replacement, and so on.


Dynamic Link Library? Call an icon in the Dll

1. Create MFC RegularDLL. Project name: VCDll25

2. Insert the Icon resource. The ID is the default IDI_ICON1. view the resource. h file (remember the resource ID)

//{{NO_DEPENDENCIES}}// Microsoft Developer Studio generated include file.// Used by VCDll25.rc//#define IDI_ICON1                       1000

3. compile the project to generate the dynamic link library "VCDll25.dll ".

4. Create the test Dialog Box program VCDemo and test VCDll25.dll under the project directory. (Function: Click OK to change the Icon of the default dialog box .)

5. In the file VCDemoDlg. h, add the handler m_hLib for saving the Dll (VCDll25.dll) and the handler m_hLibIcon for saving the Icon:

// CVCDemoDlg dialogclass CVCDemoDlg : public CDialog{// Constructionpublic:CVCDemoDlg(CWnd* pParent = NULL);// standard constructorprotected:HICON m_hLibIcon;HINSTANCE m_hLib;...};

6. The OnInitDialog () function in the VCDemoDlg. pp file loads the Dll:
BOOL CVCDemoDlg::OnInitDialog(){CDialog::OnInitDialog();        ...        m_hLib = AfxLoadLibrary("VCDll25.dll");return TRUE;  // return TRUE  unless you set the focus to a control}

7. Add the message response function OnDestroy to VCDemoDlg and release the Dll:
void CVCDemoDlg::OnDestroy() {CDialog::OnDestroy();// TODO: Add your message handler code hereAfxFreeLibrary(m_hLib);}

8. In the OnOK function of the dialog box, load the Icon and change the Icon of the application.
Void CVCDemoDlg: OnOK () {// TODO: Add extra validation hereif (m_hLib! = NULL) {AfxSetResourceHandle (m_hLib);} // zookeeper 1000 DLL contains zookeeper = LoadIcon (AfxGetResourceHandle (), MAKEINTRESOURCE (1000); if (m_hLibIcon! = NULL) {m_hIcon = m_hLibIcon;} SetIcon (m_hIcon, TRUE); // Set big iconSetIcon (m_hIcon, FALSE); // Set small icon // CDialog :: onOK ();}

:

I should have clearly stated the steps. If you have any questions or have any mistakes, please leave a message to indicate them. Thank you!

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.