I am trying to load the icon associated with the application that called my function.
The way I am solving the problem for GUI applications is this:
AfxGetApp()->LoadIcon(128); // 128 is the IDR_MAINFRAME icon
However, the Afx functions, upon looking up the resource, fail for some non-gui applications, since afxCurrentResourceHandle
is NULL.
What would be a better way to fi开发者_如何学编程nd the mainframe icon?
PS. currently I can work around it by testing afxCurrentResourceHandle != NULL
... wish I could do better.
It sounds like you're assuming that only MFC applications will be calling your function. If so, how about:
HICON hIcon = AfxGetMainWnd()->GetIcon( TRUE );
精彩评论