views:

44

answers:

1

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.

A: 

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
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
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