Conditionals and RC files
-
I have a code base that can produce two separate programs with different functionality. This functionality is controlled via #defines in the main code. I would like to use the same #define to control the program’s icon, and the wording in a few menus. I found that the following code will allow me to control the icon:
#if defined(APSTUDIO_INVOKED) IDR_MAINFRAME ICON "..\\res\\MAIN.ico" #else #if defined(MAIN_PROG) IDR_MAINFRAME ICON "..\\res\\MAIN.ico" #else IDR_MAINFRAME ICON "..\\res\\SECONDARY.ico" #endif #endif
The problem is that as soon as someone actually edits a file with the resource editor, all of the conditional code is removed. Is it actually possible to conditionally change the icon of a program, and if so what is the recommended method. I’m trying to avoid going to multiple rc files, since we will have to keep them in sync from this point on. -
I have a code base that can produce two separate programs with different functionality. This functionality is controlled via #defines in the main code. I would like to use the same #define to control the program’s icon, and the wording in a few menus. I found that the following code will allow me to control the icon:
#if defined(APSTUDIO_INVOKED) IDR_MAINFRAME ICON "..\\res\\MAIN.ico" #else #if defined(MAIN_PROG) IDR_MAINFRAME ICON "..\\res\\MAIN.ico" #else IDR_MAINFRAME ICON "..\\res\\SECONDARY.ico" #endif #endif
The problem is that as soon as someone actually edits a file with the resource editor, all of the conditional code is removed. Is it actually possible to conditionally change the icon of a program, and if so what is the recommended method. I’m trying to avoid going to multiple rc files, since we will have to keep them in sync from this point on.Yeah, I've noticed that in MSVC6. Bloody annoying and bloody stupid of Microsoft. Steve
-
Yeah, I've noticed that in MSVC6. Bloody annoying and bloody stupid of Microsoft. Steve
An RC File is Automatically maintained by the MFC Editor. That's the whole Idea behind IDE, and ofcourse it will wipe it.This is an MFC Feature since the days of Windows 3.1, and NOT a feature of MFC 6.0(or earlier or later) If you want resource code, not edited by the IDE, handwrite it in the .RES File (which is a Text File Similar to the RC File) found in your resource directory(underneath Debug and Release) Tip, If you do not know the Syntax, create it first in the Resource Editor, then copy the entire text to the .Res File, and then delete the item from your resource editor window. It will still be in the res File, The Resource Editor does no know about that File and will leave it alone) regards LateNightsInNewry
-
An RC File is Automatically maintained by the MFC Editor. That's the whole Idea behind IDE, and ofcourse it will wipe it.This is an MFC Feature since the days of Windows 3.1, and NOT a feature of MFC 6.0(or earlier or later) If you want resource code, not edited by the IDE, handwrite it in the .RES File (which is a Text File Similar to the RC File) found in your resource directory(underneath Debug and Release) Tip, If you do not know the Syntax, create it first in the Resource Editor, then copy the entire text to the .Res File, and then delete the item from your resource editor window. It will still be in the res File, The Resource Editor does no know about that File and will leave it alone) regards LateNightsInNewry
The whole idea of the IDE is not to destroy information but to make it easier to author/modify it. And it has nothing to do with MFC; it's the resource editor where the fault lies and it manifests itself whether MFC is used or not. I used the word "fault" intentionally because it is a fault: There is nothing to stop the resource editor getting the current defines from the project settings for the currently selected configuration and only editing the relevant subset. Steve
-
Yeah, I've noticed that in MSVC6. Bloody annoying and bloody stupid of Microsoft. Steve
hi, use CStudioFile Instead of the CFile, because there is One Method called ReadLine(...) which will solve your problem. also to Read use only ReadHuge(...). good luck. thanks, uday. uday kiran
-
hi, use CStudioFile Instead of the CFile, because there is One Method called ReadLine(...) which will solve your problem. also to Read use only ReadHuge(...). good luck. thanks, uday. uday kiran
I think this reply might be in the wrong thread? Steve
-
An RC File is Automatically maintained by the MFC Editor. That's the whole Idea behind IDE, and ofcourse it will wipe it.This is an MFC Feature since the days of Windows 3.1, and NOT a feature of MFC 6.0(or earlier or later) If you want resource code, not edited by the IDE, handwrite it in the .RES File (which is a Text File Similar to the RC File) found in your resource directory(underneath Debug and Release) Tip, If you do not know the Syntax, create it first in the Resource Editor, then copy the entire text to the .Res File, and then delete the item from your resource editor window. It will still be in the res File, The Resource Editor does no know about that File and will leave it alone) regards LateNightsInNewry
LateNightsInNewry wrote:
...the .RES File (which is a Text File Similar to the RC File)...
No it's not. It's a temporary binary file that the resource compiler creates.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
-
I have a code base that can produce two separate programs with different functionality. This functionality is controlled via #defines in the main code. I would like to use the same #define to control the program’s icon, and the wording in a few menus. I found that the following code will allow me to control the icon:
#if defined(APSTUDIO_INVOKED) IDR_MAINFRAME ICON "..\\res\\MAIN.ico" #else #if defined(MAIN_PROG) IDR_MAINFRAME ICON "..\\res\\MAIN.ico" #else IDR_MAINFRAME ICON "..\\res\\SECONDARY.ico" #endif #endif
The problem is that as soon as someone actually edits a file with the resource editor, all of the conditional code is removed. Is it actually possible to conditionally change the icon of a program, and if so what is the recommended method. I’m trying to avoid going to multiple rc files, since we will have to keep them in sync from this point on.How about:
IDR_MAINFRAME1 ICON "..\\res\\MAIN.ico"
IDR_MAINFRAME2 ICON "..\\res\\MAIN.ico"
IDR_MAINFRAME3 ICON "..\\res\\SECONDARY.ico"
...
CMyDlg::CProgressTestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMyDlg::IDD, pParent)
{
#if defined(APSTUDIO_INVOKED)
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME1);
#elif defined(MAIN_PROG)
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME2);
#else
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME3);
#endif
}
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
-
How about:
IDR_MAINFRAME1 ICON "..\\res\\MAIN.ico"
IDR_MAINFRAME2 ICON "..\\res\\MAIN.ico"
IDR_MAINFRAME3 ICON "..\\res\\SECONDARY.ico"
...
CMyDlg::CProgressTestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMyDlg::IDD, pParent)
{
#if defined(APSTUDIO_INVOKED)
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME1);
#elif defined(MAIN_PROG)
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME2);
#else
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME3);
#endif
}
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
DavidCrow wrote:
How about: IDR_MAINFRAME1 ICON "..\\res\\MAIN.ico" IDR_MAINFRAME2 ICON "..\\res\\MAIN.ico" IDR_MAINFRAME3 ICON "..\\res\\SECONDARY.ico" ... CMyDlg::CProgressTestDlg(CWnd* pParent /*=NULL*/) : CDialog(CMyDlg::IDD, pParent) { #if defined(APSTUDIO_INVOKED) m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME1); #elif defined(MAIN_PROG) m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME2); #else m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME3); #endif }
If I'm reading the above correctly, this will cause the program to use the correct icon when it is running, but not when the executable is being displayed in explorer, folder browser, etc. It would appear that windows uses the icon with the lowest ID number for for this.