0

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 find the mainframe icon?

PS. currently I can work around it by testing afxCurrentResourceHandle != NULL... wish I could do better.

xtofl
  • 40,723
  • 12
  • 105
  • 192

1 Answers1

-1

It sounds like you're assuming that only MFC applications will be calling your function. If so, how about:

HICON hIcon = AfxGetMainWnd()->GetIcon( TRUE );
Bukes
  • 3,668
  • 1
  • 18
  • 20
  • I specifically run into trouble for console apps. Not sure what makes them an "MFC" app or not. Thanks for the attempt, but `TRUE` is a macro indicating boolean logic, and the `GetIcon` specifically asks for a `UINT` argument. In other words: this should not compile; it only does by grace of the `TRUE` macro being defined as an integer. – xtofl Sep 08 '10 at 22:10
  • You are incorrect, sir. AfxGetMainWnd() returns a CWnd pointer. The signature for CWnd::GetIcon is: HICON CWnd::GetIcon( BOOL bBigIcon ). Check the docs. Thanks for the minus 1, dude. – Bukes Sep 09 '10 at 17:28