I have recently learned more about the process of selecting Resources in the dialog box.
In the general style, the MFC dialog box usually has such a line:
Enum {IDD = XXXXX };
In this dialog box, the constructor usually writes
View Source Code
Print help
1 |
Invoicedialog: invoicedialog (cwnd * pparent /* = NULL */ ): |
2 |
Cdialog (invoicedialog: IDD, pparent ), |
5 |
// {Afx_data_init (invoicedialog) |
6 |
// Note: The classwizard will add member initialization here |
8 |
Theapp. applicationwindow ()-& gt; m_pactivehelphandler = This ; |
However, many people may not understand how the project binds a cdialog to a dialog box resource based on this IDD number.
Sometimes there are more than one project and more than one resource. How does ide select the resource location?
Because my recent aplanet project involves multiple languages
Each Language Pack DLL is a bunch of dialog resources and resources are available in the main project.
After painstaking exploration, I found several key global functions of afx:
Afxgetresourcehandle ()
Afxsetresourcehandle ()
AfxGetInstanceHandle ()
Afxgetresourcehandle () and afxsetresourcehandle () constitute a temporary storage system (also can be understood as a stack with a height of only 1). When we specify to use the dialog box Resources of the current project, you can write it like this:
View Source Code
Print help
1 |
Hinstance H = afxgetresourcehandle (); |
2 |
Afxsetresourcehandle (AfxGetInstanceHandle ()); |
3 |
Invoicedialog ST ( This ); |
5 |
Afxsetresourcehandle (h ); |
AfxGetInstanceHandle () ensures that the resource handle in the main project is obtained.
Both afxgetresourcehandle () and afxsetresourcehandle () ensure that this process is not affected.ProgramOther parts obtain the resource location