how to use the constants in afxres.h

This is a discussion on how to use the constants in afxres.h within the Windows Programming forums, part of the Platform Specific Boards category; Hi,can someone help? I am aware that many constants like ID_FILE_NEW is defined in "afxres.h". I tried to use ID_FILE_NEW ...

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    133

    how to use the constants in afxres.h

    Hi,can someone help? I am aware that many constants like ID_FILE_NEW is defined in "afxres.h". I tried to use ID_FILE_NEW constant in my menu, but it came out with the error shown below.

    Code:
    Deleting intermediate files and output files for project 'xWrite - Win32 Debug'.
    
    --------------------Configuration: xWrite - Win32 Debug--------------------
    Compiling resources...
    Compiling...
    mainFrame.cpp
    c:\documents and settings\edmund\my documents\my ebooks\my expt files\windows workspace\xwrite\mainframe.cpp(129) : error C2065: 'ID_FILE_NEW' : undeclared identifier
    c:\documents and settings\edmund\my documents\my ebooks\my expt files\windows workspace\xwrite\mainframe.cpp(129) : error C2051: case expression not constant
    skeleton.cpp
    winMain.cpp
    Error executing cl.exe.
    
    xWrite.exe - 2 error(s), 0 warning(s)
    I am using VC++. Here is my resource.h and resource.rc:

    Code:
    //Microsoft Developer Studio generated resource script.
    //
    #include "resource.h"
    
    #define APSTUDIO_READONLY_SYMBOLS
    /////////////////////////////////////////////////////////////////////////////
    //
    // Generated from the TEXTINCLUDE 2 resource.
    //
    #include "afxres.h"
    /////////////////////////////////////////////////////////////////////////////
    #undef APSTUDIO_READONLY_SYMBOLS
    
    /////////////////////////////////////////////////////////////////////////////
    // English (U.S.) resources
    
    #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
    #ifdef _WIN32
    LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
    #pragma code_page(1252)
    #endif //_WIN32
    
    /////////////////////////////////////////////////////////////////////////////
    //
    // Menu
    //
    
    IDR_MAIN MENU DISCARDABLE 
    BEGIN
        POPUP "&File"
        BEGIN
            MENUITEM "&New\tCtrl+N",                ID_FILE_NEW
            MENUITEM "E&xit",                       ID_FILE_EXIT
        END
    END
    
    
    #ifdef APSTUDIO_INVOKED
    /////////////////////////////////////////////////////////////////////////////
    //
    // TEXTINCLUDE
    //
    
    1 TEXTINCLUDE DISCARDABLE 
    BEGIN
        "resource.h\0"
    END
    
    2 TEXTINCLUDE DISCARDABLE 
    BEGIN
        "#include ""afxres.h""\0"
    END
    
    3 TEXTINCLUDE DISCARDABLE 
    BEGIN
        "\r\n"
        "\0"
    END
    
    #endif    // APSTUDIO_INVOKED
    
    
    /////////////////////////////////////////////////////////////////////////////
    //
    // String Table
    //
    
    STRINGTABLE DISCARDABLE 
    BEGIN
        IDR_MAIN                "mainFrame class"
        IDS_MAINTITLE           "Main Frame"
        ID_EDIT                 "edit control identifier"
    END
    
    #endif    // English (U.S.) resources
    /////////////////////////////////////////////////////////////////////////////
    
    
    
    #ifndef APSTUDIO_INVOKED
    /////////////////////////////////////////////////////////////////////////////
    //
    // Generated from the TEXTINCLUDE 3 resource.
    //
    
    
    /////////////////////////////////////////////////////////////////////////////
    #endif    // not APSTUDIO_INVOKED

    Code:
    //{{NO_DEPENDENCIES}}
    // Microsoft Developer Studio generated include file.
    // Used by resource.rc
    //
    #define IDR_MAIN                        101
    #define IDS_MAINTITLE                   102
    #define ID_EDIT                         103
    #define MAX_RESOURCESTRING              255
    #define ID_FILE_EXIT                    40001
    
    // Next default values for new objects
    // 
    #ifdef APSTUDIO_INVOKED
    #ifndef APSTUDIO_READONLY_SYMBOLS
    #define _APS_NEXT_RESOURCE_VALUE        103
    #define _APS_NEXT_COMMAND_VALUE         40002
    #define _APS_NEXT_CONTROL_VALUE         1000
    #define _APS_NEXT_SYMED_VALUE           101
    #endif
    #endif

    Using the ID_FILE_NEW in this function call in a wndProc where WM_COMMAND is received:

    Code:
    void mainFrame::mainWindow_onCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
    {
    
    	switch(id)
    	{case ID_FILE_EXIT:	DestroyWindow(hwnd);
    						break;
    	case ID_FILE_NEW: Edit_SetText(hEditCntl,NULL);
    		              break;  
    	default: FORWARD_WM_COMMAND(hwnd,id,hwndCtl,codeNotify,DefWindowProc);
    	}
    
    }

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Try #include "afxres.h" in mainframe.cpp
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    133
    Thanks it worked

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 11-12-2008, 10:00 AM
  2. define constants
    By shuo in forum C++ Programming
    Replies: 6
    Last Post: 09-07-2007, 03:17 PM
  3. COnstants
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 09-01-2007, 04:59 AM
  4. Constants
    By shuo in forum C++ Programming
    Replies: 6
    Last Post: 07-29-2007, 11:51 PM
  5. Help with Constants and enum constants. Newbie learning C++.
    By UnregJDiPerla in forum C++ Programming
    Replies: 5
    Last Post: 01-07-2003, 07:29 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21