Windows Getting Started Basics: 2.vs2013 in icon display

Source: Internet
Author: User

The first step: " Resource View ", right click, " Add Resources ", select "icon" (new is to create a blank icon to paint their own; Import is to add an icon file to the project). After that, you can see the result of the third icon.

So, we've added the icon, and the icon has a default ID as well. Then we can use the custom icon. Use the following code:

Wndclass Wndclass;wndclass.hicon = LoadIcon (hinstance, idi_icon1); ....

After we run, the code has wavy lines underneath the idi_icon1, prompting undefined identifiers.


Inexperienced don't know what's going on, experienced knows that this ID is not defined in the location. Because, when you add a resource, VS helps you create a resource.h header file that defines these resource IDs. Then the problem is solved because the resource ID is not defined. Now that we have a defined header file, we can include it in it. Look at the code:

#include "resource.h"

However, the problem remains unresolved because there are wavy lines underneath the idi_icon1. Place your cursor over it and indicate "error: the argument of type int is not compatible with LPCWSTR type". Do you know what the problem is? The argument passed to the function is of the wrong type. Because the Idi_icon1 defined in resource.h is an integral type, see the code defined below:

#define Idi_icon1  103

So, that's the problem. Then we need to know what the type is. LPCWSTR is a type alias for const WCHAR *LPCWSTR, const is a const type alias, WCHAR is an alias of wchar_t type, wchar_t is a character type of wide character, Char is a character type of narrow character. Wide characters Use Unicode encoding, and narrow characters use multibyte encoding. For the extended reading of this section, see the detailed analysis of the relationship between character sets and character encodings, the easy and thorough understanding of symbols, characters, and character sets (ASCII, Unicode). So, LPCWSTR is actually this type: the const wchar_t*, which is a pointer type that points to a constant wide character. However, here you just need to know, because Windows has already prepared the tool for us, that is, to convert the integral type to this type of macro Makeintresource. The ID of the integral type passed in the macro brackets. Finally, the result of the macro conversion is the LPCWSTR type. This is the gaocheng of working. The code is as follows:

Wndclass Wndclass;wndclass.hicon = LoadIcon (hinstance, Makeintresource (Idi_icon1));

Look at my Custom icon:

Windows Getting Started Basics: 2.vs2013 in icon display

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.