[MFC Landscaping] MFC uses Skinmagic-1

Source: Internet
Author: User

"Skinmagic Use Process"

1. Project configuration Skinmagic Related documents

2. Initialize skinmagic skin file, form load skin

3. Releasing Skin resources

1. Project configuration Skinmagic Related documents

When loading the skin for a form or dialog box, the related DLLs,. h files, and Lib that are used to use Skinmagic are included in the project directory first:

SkinMagicLib.h: Put it in the root directory of the project

SkinMagic.lib: Put it in the root of the project or put it in a different directory, which requires the project to add an existing item and add it to the resource file

SkinMagic.dll: Put to debug Debug directory

Finally, place the associated. SMF skin files in the root directory, such as the root directory under the Skinmagic folder. Path: SKINMAGIC/CORONA.SMF.

The following versions of compiled programs are no longer dependent on SkinMagic.dll when they are run

SkinMagicLibMD6.lib static link library for VC6 release version compilation

SkinMagicLibMT6.lib static link library for debug version compilation of VC6

2. Initialize skinmagic skin file, form load skin

The steps are as follows:

1. SkinMagicLib.h and SkinMagic.lib are included in the stdafx.h of the project, as far as possible in the final include, to prevent errors

" SkinMagicLib.h " #pragma comment (lib, "Skinmagic")// can also be set in dependencies

Or:

1. Place the SkinMagic.dll in the debug directory
2. Set the library file directory and add the library to the [additional dependencies] in the project [linker] SkinMagic.lib
3, add the header file in the project's stdafx.h file #include "SkinMagicLib.h"

2. Initializing the Skinmagic Library

This step is necessary to use skinmagic. Add code to initialize the Skinmagic resource before the InitInstance () function of the app class creates the main window.

Initcommoncontrolsex (&initctrls);
to initialize the skin library, the key is to get the instance handle in the first one. The other can be null. VERIFY (1 = = Initskinmagiclib (AfxGetInstanceHandle (), NULL, NULL, NULL));

dialog box:

Initcommoncontrolsex (&initctrls); add after this

Single Document:

Find the Cxxxapp class in ClassView. Then find the InitInstance () function, and then

M_pmainwnd->showwindow (Sw_show);

M_pmainwnd->updatewindow (); add before this

Description
int Initskinmagiclib (//Initialize Skinmagic tool Library
HINSTANCE hinstance,//application handle
char* szapplication,//skin file defined in the application name, set to NULL
char* Szregcode,//skinmagic Use the registration code. If NULL is not placed
char* szReserved2//reserved bit, NULL
);

3. Load the skin file.

It can also be loaded in the InitInstance () function of the app (application) class in the dialog OnInitDialog ().

There are two types of loading: (1) Adding skin files to the resources and compiling them into the program.

(2) The program dynamically loads skin files at run time.

static loading: For example, add CORONA.SMF, set the resource type to "Skinmagic" and the resource ID to Idr_skin_corona

VERIFY (1"skinmagic"));

Dynamic loading: such as the root directory under the Skinmagic folder. Path: SKINMAGIC/CORONA.SMF.

VERIFY (1 = = Loadskinfile ("skinmagic/corona.smf"));

Description

Resource name with double quotation marks
int Loadskinfromresource (
Hmodule hmodule,//module handle containing skin file, if null surface in this module
char* Lpskinname,//name of the skin resource
char* Lptype); Types of resources

4. Add skin to the window:

1) Add Skins for standard Windows (with features such as title bar, system menu, variable size, such as document/view structure and menu-like dialogs), usually for the main window.

Add the following code at the bottom of the InitInstance () function of the application class

1 " MainFrame " ) ; m_pMainWnd-ShowWindow (sw_show); m_pMainWnd->updatewindow ();

Description
int Setwindowskin (
HWND hwnd,//window handle to use skin
char* lpskinname//name specified for Skinframewnd object
);

2) Add skin to the dialog box
Called before the dialog box is displayed, usually in the application initialization function.

Cnetworkdlg dlg;    = &dlg;   1 " MainFrame " 1 " Dialog "  = dlg. DoModal ();  

Description

int Setdialogskin (
char* lpskinname//name specified for Skinframewnd object
);
After you use this function, the dialog box that is created by the program will use the skin, but the dialog box size is immutable.

3) Adding skins to a single dialog window

For example, in the dialog view: The CREATE function OnCreate of the overloaded dialog view, add the following code:

1 " Dialog "  ) ); Enablewindowscrollbarskin (M_hwnd, sb_both);

Description
int Setsingledialogskin (
HWND hwnd,//window handle to use skin
char* lpskinname//name specified for Skinframewnd object
);
int Enablewindowscrollbarskin (//Add skin for scroll bar
HWND hwnd,//window handle to use skin
int* Fnbar//To use the skin's scrollbar, sb_both indicates that the skin is all the way
);

3. Releasing Skin resources

Reload the application's ExitInstance () function in the app (application) class,

can be manually added as InitInstance () or In the Cxxxapp class, right-click Addvirtualfunction and Add the ExitInstance () function, which adds:

// Releasing Skinmagic Resources Exitskinmagiclib ();

Reference Links:

http://blog.csdn.net/colinchan/article/details/1572182

Http://www.cnblogs.com/tianlangshu/archive/2011/03/20/1989436.html

http://blog.csdn.net/nonecode/article/details/7951975

Precautions:

1. skinmagic cannot display the menu when the dialog is beautified

When using the Skinmagic skin Library, the app class's InitInstance function loaded the skin library successfully, but found that their menu does not display properly!

Workaround: The load skin file type is implemented in the InitInstance function, loaded in the Dlg class when the skin name is loaded.

In the InitInstance () function of the app class, you only need to enter:

1 = = Initskinmagiclib (AfxGetInstanceHandle (), null , NULL, NULL  ))  ; 1 = = Loadskinfromresource (AfxGetInstanceHandle (), _t ("idr_skinmagic"), _t (  "skinmagic")));   

In the Dlg class, in the OnInitDialog () class, enter:

" Dialog " );  // This is the point, m_hwnd is the window handle of your main dialog box " Dialog " );  // is to add skin to your future dialog box!

2. You do not need to rely on DLL files for project publishing

When using a DLL, the program needs to be skinmaigc.dll with the program when it is published, and if you use a static library, you do not need to rely on DLL files.

Specific settings:

1). General: Right-click Project, Properties--, configuration properties, general, and in the "Project Defaults" section on the right, select "Use MFC in Static Library" in the "Default for MFC" option.

2). Multithreaded Debugging: Right-click the project--Properties--Configuration Properties->c/c++-> code generation, run-time library->MTD or MT

If you are debugging "using MFC in a static library", do not use MDD instead of MTD, and then compile to pass.

If it is release version "use MFC in Static Library", do not use MD, use MT;

[MFC Landscaping] MFC uses Skinmagic-1

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.