MFC 中切换资源的两种方式

方法一:

AFX_MANAGE_STATE(AfxGetAppModuleState());// MFC扩展dll
AFX_MANAGE_STATE( AfxGetStaticModuleState());//常规Regular dll
方法二:
<pre class="line mt-10 q-content" name="code" style="white-space: pre-wrap; word-wrap: break-word; margin-top: 10px; margin-bottom: 0px; padding: 0px; font-family: arial, 'courier new', courier, 宋体, monospace; word-break: break-all;">HMODULE hDLL=GetModuleHandle("SourceChange.dll");  
 HINSTANCE hEXE=AfxGetResourceHandle();  
 AfxSetResourceHandle((HINSTANCE)hDLL); //设定资源模块句柄,指定为DLL模块。
...// 资源的加载
 AfxSetResourceHandle(hEXE); // 切换到EXE资源

 
<pre class="line mt-10 q-supply-content" name="code" style="white-space: pre-wrap; word-wrap: break-word; font-size: 14px; margin-top: 10px; margin-bottom: 0px; padding: 0px; font-family: arial, 'courier new', courier, 宋体, monospace; word-break: break-all; color: rgb(51, 51, 51); line-height: 24px; background-color: rgb(255, 255, 255);">【注意1】;
有些资源加载函数需要指定资源句柄,请注意使用<span style="color: rgb(68, 68, 68); font-size: 16px;">AfxGetInstanceHandle()、</span>AfxGetResourceHandle()的使用
如:
LoadCursor()、LoadImage()等等。
<pre class="line mt-10 q-supply-content" name="code" style="white-space: pre-wrap; word-wrap: break-word; margin-top: 10px; margin-bottom: 0px; padding: 0px; font-family: arial, 'courier new', courier, 宋体, monospace; word-break: break-all;"><pre class="line mt-10 q-supply-content" name="code" style="white-space: pre-wrap; word-wrap: break-word; margin-top: 10px; margin-bottom: 0px; padding: 0px; font-family: arial, 'courier new', courier, 宋体, monospace; word-break: break-all;">【注意2】;
<span style="color: rgb(68, 68, 68); font-size: 16px;">GetModuleHandle()、<span style="orphans: 2; widows: 2;">AfxGetInstanceHandle()和CWinApp->m_hInstance的区别:</span></span>
<span style="color: rgb(68, 68, 68); font-size: 16px; orphans: 2; widows: 2;"></span><div style="widows: 2; font-size: 16px; orphans: 2; color: rgb(68, 68, 68);">1.GetModuleHandle(LPCTSTR lpModuleName)
  If this parameter is NULL, GetModuleHandle returns a handle to the file used to create the calling process (.exe file).
  如果参数为空,那么获取的就是调用这个DLL 的exe的 句柄,也即application句柄,而不是DLL的句柄</div><div style="widows: 2; font-size: 16px; orphans: 2; color: rgb(68, 68, 68);">  如果要获得当前DLL的句柄,要传入DLL的名称即可。</div><div style="widows: 2; font-size: 16px; orphans: 2; color: rgb(68, 68, 68);">
</div><div style="widows: 2; font-size: 16px; orphans: 2; color: rgb(68, 68, 68);">2.AfxGetInstanceHandle()
   An HINSTANCE to the current instance of the application. If called from within a DLL linked with the USRDLL version of MFC, an HINSTANCE to the DLL is returned.
   返回的是一个application的句柄,但是如果这个函数是从一个MFC的USRDLL版本DLL的内部被调用,那么返回的就是这个DLL的句柄</div><div style="widows: 2; font-size: 16px; orphans: 2; color: rgb(68, 68, 68);">
</div><div style="widows: 2; font-size: 16px; orphans: 2; color: rgb(68, 68, 68);">3.CWinApp->m_hInstance
  The m_hInstance data member is a handle to the current instance of the application running under Windows. This is returned by the global function AfxGetInstanceHandle. m_hInstance is a public variable of type HINSTANCE.
  因为它是从 AfxGetInstanceHandle()返回来获得的,所以跟AfxGetInstanceHandle()的返回值一样。</div>
 
 

 
 

                
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值