C++ resource file(.rc)

Bevan Thomas 60 Reputation points
2024-12-02T13:44:17.6266667+00:00

Hi,

So, I have a .rc resource file, i need to add some resource based on some conditional macro(#ifdef),
I have defined the macros in configuration property->Resource->General->Preprocessor definitions.
But still the macro is not getting identified.I checked the rc file in resource view and that particular resource is not being defined.Do i have to define the macro at some place else? I am on visual studio 2022.

Developer technologies | C++
0 comments No comments
{count} votes

Accepted answer
  1. RLWA32 49,636 Reputation points
    2024-12-02T14:39:13.1733333+00:00

    For a Win32 C++ project define the macro in the resource.h file.

    For example --

    From the .rc file

    #ifdef TWODIALOGS
    IDD_DIALOG1 DIALOGEX 0, 0, 309, 176
    STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
    CAPTION "Dialog"
    FONT 8, "MS Shell Dlg", 400, 0, 0x1
    BEGIN
        DEFPUSHBUTTON   "OK",IDOK,198,155,50,14
        PUSHBUTTON      "Cancel",IDCANCEL,252,155,50,14
    END
    #endif
    

    resource.h file

    //{{NO_DEPENDENCIES}}
    // Microsoft Visual C++ generated include file.
    // Used by WindowsProject3.rc
    //
    #define IDC_MYICON                      2
    #define IDD_WINDOWSPROJECT3_DIALOG      102
    #define IDS_APP_TITLE                   103
    #define IDD_ABOUTBOX                    103
    #define IDM_ABOUT                       104
    #define IDM_EXIT                        105
    #define IDI_WINDOWSPROJECT3             107
    #define IDI_SMALL                       108
    #define IDC_WINDOWSPROJECT3             109
    #define IDR_MAINFRAME                   128
    #define IDD_DIALOG1                     129
    #define IDC_STATIC                      -1
    
    #define TWODIALOGS
    
    // Next default values for new objects
    // 
    #ifdef APSTUDIO_INVOKED
    #ifndef APSTUDIO_READONLY_SYMBOLS
    #define _APS_NO_MFC                     1
    #define _APS_NEXT_RESOURCE_VALUE        130
    #define _APS_NEXT_COMMAND_VALUE         32771
    #define _APS_NEXT_CONTROL_VALUE         1000
    #define _APS_NEXT_SYMED_VALUE           110
    #endif
    #endif
    

    With macro defined -

    enter image description here

    With macro commented out

    OneDialog


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.