Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Conditionals and RC files

Conditionals and RC files

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionlearning
9 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rentzk
    wrote on last edited by
    #1

    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.

    S D 2 Replies Last reply
    0
    • R rentzk

      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.

      S Offline
      S Offline
      Stephen Hewitt
      wrote on last edited by
      #2

      Yeah, I've noticed that in MSVC6. Bloody annoying and bloody stupid of Microsoft. Steve

      B K 2 Replies Last reply
      0
      • S Stephen Hewitt

        Yeah, I've noticed that in MSVC6. Bloody annoying and bloody stupid of Microsoft. Steve

        B Offline
        B Offline
        Bram van Kampen
        wrote on last edited by
        #3

        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

        S D 2 Replies Last reply
        0
        • B Bram van Kampen

          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

          S Offline
          S Offline
          Stephen Hewitt
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • S Stephen Hewitt

            Yeah, I've noticed that in MSVC6. Bloody annoying and bloody stupid of Microsoft. Steve

            K Offline
            K Offline
            kiran janaswamy
            wrote on last edited by
            #5

            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

            S 1 Reply Last reply
            0
            • K kiran janaswamy

              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

              S Offline
              S Offline
              Stephen Hewitt
              wrote on last edited by
              #6

              I think this reply might be in the wrong thread? Steve

              1 Reply Last reply
              0
              • B Bram van Kampen

                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

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                • R rentzk

                  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.

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  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

                  R 1 Reply Last reply
                  0
                  • D David Crow

                    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

                    R Offline
                    R Offline
                    rentzk
                    wrote on last edited by
                    #9

                    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.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups