In writing international applications, strings in different languages are often used. For example, the Chinese menu is called "file", but the English menu is called "File ". The functions of developing such software are the same, but the text displayed on the interface is different. To facilitate the development of such software, the commonly used method in Windows is to replace the display string, for example, specifying that the "file" is displayed in Chinese ", the "file" is displayed in English. It is implemented by loading different strings from different resources through the loadstring function. In fact, all variable strings can be loaded to display strings from resources using the loadstring function.
The information of images is very convenient for people to remember. Like a traffic signal, it is to use various icons, and everyone will understand what it is, therefore, use icons in the program to identify the program. As long as you see this icon, you will know what the software is used. For example, if the icon is displayed in the upper left corner of the program, you need to call the loadicon function to load the icon from the resource to the memory and then display it.
The cursor is the most commonly used icon and can be seen all the time. When editing a file, the cursor is displayed as an I-shaped icon, and an arrow is displayed when you operate the file on the desktop. The changed cursor is because different icons are set. The use of the cursor is to give different indications according to different regions. The function for changing the cursor is loadcursor.
The loadstring function declaration is as follows:
Winuserapi
Int
Winapi
Loadstringa (
_ In_opt hinstance,
_ In uint uid,
_ Out_ecount (cchbuffermax) lpstr lpbuffer,
_ In int cchbuffermax );
Winuserapi
Int
Winapi
Loadstringw (
_ In_opt hinstance,
_ In uint uid,
_ Out_ecount (cchbuffermax) lpwstr lpbuffer,
_ In int cchbuffermax );
# Ifdef Unicode
# Define loadstring loadstringw
# Else
# Define loadstring loadstringa
# Endif //! Unicode
Hinstance is the application instance handle.
UID is the string number in the resource.
Lpbuffer is the buffer that receives the string copied from the resource.
Cchbuffermax indicates the buffer size.
The loadicon function declaration is as follows:
Winuserapi
Hicon
Winapi
Loadicona (
_ In_opt hinstance,
_ In lpcstr lpiconname );
Winuserapi
Hicon
Winapi
Loadiconw (
_ In_opt hinstance,
_ In lpcwstr lpiconname );
# Ifdef Unicode
# Define loadicon loadiconw
# Else
# Define loadicon loadicona
# Endif //! Unicode
Hinstance is the application instance handle.
Lpiconname indicates the name of the icon.
The loadcursor function declaration is as follows:
Winuserapi
Hcursor
Winapi
Loadcursora (
_ In_opt hinstance,
_ In maid );
Winuserapi
Hcursor
Winapi
Loadcursorw (
_ In_opt hinstance,
_ In maid );
# Ifdef Unicode
# Define loadcursor loadcursorw
# Else
# Define loadcursor loadcursora
# Endif //! Unicode
Hinstance is the application instance handle.
Lpcursorname is the name of the cursor.
An example of calling these three functions is as follows:
#001 //
#002 // function: myregisterclass ()
#003 //
#004 // purpose: register a window type.
#005 //
#006 // Cai junsheng 2007/07/12
#007 //
#008 atom myregisterclass (hinstance)
#009 {
#010 wndclassex wcex;
#011
#012 wcex. cbsize = sizeof (wndclassex );
#013
#014 wcex. Style = cs_hredraw | cs_vredraw;
#015 wcex. lpfnwndproc = wndproc;
#016 wcex. cbclsextra = 0;
#017 wcex. cbwndextra = 0;
#018 wcex. hinstance = hinstance;
#019 wcex. hicon = loadicon (hinstance, makeintresource (idi_testwin ));
#020 wcex. hcursor = loadcursor (null, idc_arrow );
#021 wcex. hbrbackground = (hbrush) (color_window + 1 );
#022 wcex. lpszmenuname = makeintresource (idc_testwin );
#023 wcex. lpszclassname = szwindowclass;
#024 wcex. hiconsm = loadicon (wcex. hinstance, makeintresource (idi_small ));
#025
#026 return registerclassex (& wcex );
#027}
Row 3 is the loaded display icon. The macro makeintresource is used to convert it to an appropriate type. Its definition is as follows:
# Define is_intresource (_ r) (ulong_ptr) (_ r)> 16) = 0)
# Define makeintresourcea (I) (lpstr) (ulong_ptr) (Word) (I ))))
# Define makeintresourcew (I) (lpwstr) (ulong_ptr) (Word) (I ))))
# Ifdef Unicode
# Define makeintresource makeintresourcew
# Else
# Define makeintresource makeintresourcea
# Endif //! Unicode
Rows 20th are displayed by the cursor that loads the arrow.
// Load the global string.
Loadstring (hinstance, ids_app_title, sztitle, max_loadstring );
Loadstring (hinstance, idc_testwin, szwindowclass, max_loadstring );
The above two lines call the loadstring function to obtain the displayed string from the resource.