请问在ATL控件如何获得应用程序实例句柄?

firmbird 2002-06-26 01:05:06
请问在ATL控件如何获得应用程序实例句柄?
我用AfxGetApp()->m_hInstance方法在运行总会出错,有没有其他办法应用程序实例句柄啊,或者告诉我该怎么改。
说明:我要在控件中加载光标,LoadCursor()方法中要用这个实例句柄。
...全文
148 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
firmbird 2002-06-27
  • 打赏
  • 举报
回复
I know, because I forget to call ShowCursor function

Present the Score THK U!
masterz 2002-06-27
  • 打赏
  • 举报
回复
23. I've created a 16x16 icon for my app. Why does Windows insist on squishing up the 32x32 version ?


You've created an MFC app. Taking a dialog-based app as an example, look at the source for your main window(dialog) and check out the constructor. You'll see this:

m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

But LoadIcon can only load icons which are SM_CXICON x SM_CYICON pixels big, which is nearly always the 32x32 version. When it needs a 16x16 version, such as for your titlebar, it squishes that up. Yuck. Instead, replace the code above with this :

m_hIcon = (HICON) LoadImage (AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDR_MAINFRAME),
IMAGE_ICON,
16, 16,
LR_DEFAULTCOLOR);

masterz 2002-06-27
  • 打赏
  • 举报
回复
23. I've created a 16x16 icon for my app. Why does Windows insist on squishing up the 32x32 version ?


You've created an MFC app. Taking a dialog-based app as an example, look at the source for your main window(dialog) and check out the constructor. You'll see this:

m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

But LoadIcon can only load icons which are SM_CXICON x SM_CYICON pixels big, which is nearly always the 32x32 version. When it needs a 16x16 version, such as for your titlebar, it squishes that up. Yuck. Instead, replace the code above with this :

m_hIcon = (HICON) LoadImage (AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDR_MAINFRAME),
IMAGE_ICON,
16, 16,
LR_DEFAULTCOLOR);

firmbird 2002-06-26
  • 打赏
  • 举报
回复
呵呵,THK U,我已经知道了_pModule->GetModuleInstance();来获取应用程序实例句柄,不过我还是很感谢你,还想再问一个问题,为什么用SetCursor()设定一个32X32的光标可以显示,但是设定一个系统光标或者显示一个自己做的16X16的光标就是不能显示呢?
masterz 2002-06-26
  • 打赏
  • 举报
回复
use GetModuleFileName to retrieve file name of the host application,
The GetModuleHandle function retrieves a module handle for the specified module if the file has been mapped into the address space of the calling process.

3,245

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧