Menu

Problem with resource files

2004-06-06
2012-09-26
  • Mahendar Pratap Singh

    I am new to DevC++ so please bare with me.

    I have been reading the tutorial Win32 API Tutorial
    by theForger.

    According to the Chapter Menus and Icons in the tutorial, I have created a .c file, .h file and .rc file containing MENNU definition and ICON definition.
    Just to inform you I created all this without creating any project.

    When I complied the code , it compiles and runs but it does not show the menu and the icons.

    So, I thought I have to create a project. So I created a project in the directory where I had my files. And I included the .c, .h and .rc file. And when I complied it gave me this error
    ###################################
    Compiler: Default compiler
    Building Makefile: "F:\Cygwin\home\mahen\Personal\cpp\Makefile.win"
    Executing  make...
    make.exe -f "F:\Cygwin\home\mahen\Personal\cpp\Makefile.win" all
    windres.exe -i Learning_private.rc -I rc -o Learning_private.res -O coff

    windres.exe: can't popen `gcc -E -xc -DRC_INVOKED  Learning_private.rc': Invalid argument

    make.exe: *** [Learning_private.res] Error 1

    Execution terminated
    ##################################

    This is the content of the .h file

    #################################
    #define IDR_MYMENU 101
    #define IDI_MYICON 201

    #define ID_FILE_EXIT 9001
    #define ID_STUFF_GO 9002

    ##################################

    This is the content of .rc file

    ##################################
    #include "resource.h"

    IDR_MYMENU MENU
    BEGIN
        POPUP "&File"
        BEGIN
            MENUITEM    "E&xit", ID_FILE_EXIT
        END
       
        POPUP "&Stuff"
        BEGIN
            MENUITEM "&Go", ID_STUFF_GO
            MENUITEM "G&o Somewhere else", 0, GRAYED
        END
    END

    IDI_MYICON ICON "menu_one.ico"
    ##################################

    and this the code of .c file

    #################################
    #include <windows.h>

    #include "resource.h"

    const char g_szClassName[] = "myWindowClass";

    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
        switch(msg) {
            case WM_CLOSE:
                    DestroyWindow(hwnd);
                break;
            case WM_DESTROY:
                    PostQuitMessage(0);
                break;
            case WM_MOUSEWHEEL : {
                 char szFileName[MAX_PATH];
                 HINSTANCE hInstance = GetModuleHandle(NULL);
                
                 GetModuleFileName(hInstance, szFileName, MAX_PATH);
                 MessageBoxA(hwnd, szFileName, "Mahen Testing", MB_OK | MB_ICONINFORMATION);
             }   
                break;
            default:
                return DefWindowProc(hwnd, msg, wParam, lParam);       
        }   
    }   
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
        WNDCLASSEX wc;
        HWND hwnd;
        MSG Msg;

        wc.cbSize = sizeof(WNDCLASSEX);
        wc.style = 0;
        wc.lpfnWndProc = WndProc;
        wc.cbClsExtra = 0;
        wc.cbWndExtra = 0;
        wc.hInstance = hInstance;
        wc.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
        wc.hCursor = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE);
        wc.lpszMenuName  = MAKEINTRESOURCE(IDR_MYMENU);
        wc.lpszClassName = g_szClassName;
        wc.hIconSm       = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON), IMAGE_ICON, 16, 16, 0);
       
        if(!RegisterClassEx(&wc)) {
            MessageBox(NULL, "Window Registration Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
            return 0;
        }
       
        hwnd = CreateWindowEx(
                WS_EX_CLIENTEDGE,
                g_szClassName,
                "Testing Window",
                WS_OVERLAPPEDWINDOW,
                CW_USEDEFAULT,
                CW_USEDEFAULT,
                240, 120,
                NULL, NULL, hInstance, NULL);
               
        if(hwnd == NULL) {
            MessageBox(NULL, "Window Creation Failed!", "Error!",
            MB_ICONEXCLAMATION | MB_OK);
            return 0;
        }
       
        ShowWindow(hwnd, nCmdShow);
        UpdateWindow(hwnd);
       
        while(GetMessageA(&Msg, NULL, 0, 0) > 0) {
            TranslateMessage(&Msg);
            DispatchMessage(&Msg);
        }   
       
        return Msg.wParam;

       
    }   
    #################################

    And this is the text of the Makefile.win which DevC++ created

    ################################
    # Project: Learning
    # Makefile created by Dev-C++ 4.9.8.9

    CPP  = g++.exe -D__DEBUG__
    CC   = gcc.exe -D__DEBUG__
    WINDRES = windres.exe
    RES  = Learning_private.res
    OBJ  = simple_window.o $(RES)
    LINKOBJ  = simple_window.o $(RES)
    LIBS =  -L"D:/Dev-Cpp/lib"  -lgmon -pg -g3
    INCS =  -I"D:/Dev-Cpp/include"
    CXXINCS =  -I"D:/Dev-Cpp/include/c++"  -I"D:/Dev-Cpp/include/c++/mingw32"  -I"D:/Dev-Cpp/include/c++/backward"  -I"D:/Dev-Cpp/include"
    BIN  = Learning.exe
    CXXFLAGS = $(CXXINCS)  -pg -g3
    CFLAGS = $(INCS)  -pg -g3

    .PHONY: all all-before all-after clean clean-custom

    all: all-before Learning.exe all-after

    clean: clean-custom
        rm -f $(OBJ) $(BIN)

    $(BIN): $(OBJ)
        $(CC) $(LINKOBJ) -o "Learning.exe" $(LIBS)

    simple_window.o: simple_window.c
        $(CC) -c simple_window.c -o simple_window.o $(CFLAGS)

    Learning_private.res: Learning_private.rc menu.rc
        $(WINDRES) -i Learning_private.rc -I rc -o Learning_private.res -O coff
    ##################################

    Please help me as I want to learn this Win32API and am new to it.

    Thanx
    Mahendra

     
    • Nobody/Anonymous

      The problem is in the generated _private.rc file.  Try removing the *_private files and rebuilding.

       
    • Mahendar Pratap Singh

      Thanx for responding ...
      But I tried by removing the _privates files but when I rebuild, the editor again creates the _private files and then gives the same error

      "can't popen `gcc -E -xc -DRC_INVOKED  Learning_private.rc': Invalid argument"

       
    • Mahendar Pratap Singh

      Please Help!! Anybody has any clue why its not working

       
    • Nobody/Anonymous

      I can't tell if this is your problem, but I've found that Dev-C++ doesn't like it when I use BEGIN and END in my resource, try to use { and } instead and then rebuild all, cause Dev will not recompile .rc or .h files if you don't.  This very well may not be your problem though.

      Let me know how how it works out
      See Ya
      Butch

       
      • Mahendar Pratap Singh

        Thanks Butch for you reply. I tried changing BEGIN with {and END with}. But again same error. I have been fighting with this thing for nearly 2 days now.

        But there is one finding I would like to share with you guys. With the guidance of Damien, since windres was giving error i tried it like this from command prompt.

        windres -o menu.o menu.rc

        It gave me the same error, which I got in from DevC++. But menu.rc in place of Learning_private.rc in the error message. :-(

        Also, then it tried the same stuff with windres which comes with Cygwin and guess what it ran. and then used gcc in Cygwin and I was able to generate exe.

        But I would like to know what is wrong with my DevC++. Please help me with this.

        Cheers

         
    • Nobody/Anonymous

      Instead of putting

      IDR_MYMENU MENU

      Try

      101 MENU

       
      • Mahendar Pratap Singh

        No Luck Still same error

         
    • Liviu Nicolescu

      Liviu Nicolescu - 2004-06-07

      Your example compiles, links and runs for me.

      What version of gcc and tools are you using?

      Type "gcc -v" and "windres -V" in a command window to find out gcc and windres versions.

      Liviu

       
      • Mahendar Pratap Singh

        GNU windres 2.15.90 20040222

        and gcc version 3.4.0 (mingw special)

        just updated after not to able to run it with the versions which come with DevC++ but still without luck

         
    • Nobody/Anonymous

      Your program worked for me too. I'm using Dev-C++ 4.9.8.9.  The only change I made was I copied MAINICON.ico from the Dev-Cpp Icon folder  and used it instead, since I don't have a copy of your icon.  Try copying any icon from the Icon folder and see if it works.
      See Ya
      Butch

       
      • Mahendar Pratap Singh

        Sorry its not working the way you have suggested. But I would like bring to your notice again that I am able to compile it perfectly using Cygwin. Also the error is due to windres which comes with DevC++(or I have some problem with configuring it on my machine)

         
    • Nobody/Anonymous

      When you compile, why are you using RC_INVOKED.  And how is it getting passed to windres?
      What are the parameters in your Project Options?

       
      • Mahendar Pratap Singh

        I am not using RC_INVOKED. I simply call windres -o menu.o menu.rc and windres pass this RC_INVOKED to gcc

         
    • Jim W.

      Jim W. - 2004-06-08

      OP --

      "I am new to DevC++ so please bare (sic) with me."

      Not the best situation to play on the "bleeding edge".

      Your code compiles (here) in MinGW GCC 3.2.0 through 3.4.0, and in Cygwin GCC 3.3.1.

      Your compile options are pretty much "insane".

      Tip:  Slow down and get it right...

      -- Jim.

       
    • Liviu Nicolescu

      Liviu Nicolescu - 2004-06-08

      It seems that you have an installation problem.

      There might be some interference between Cygwin and Dev-cpp/MingW.

      I don't know how Cygwin works. Does it add some directory to the PATH? If so, remove it, try to compile your example and see what happens.

      Check the "compiler options" in the "tools" menu too.

      Liviu

       
    • Jim W.

      Jim W. - 2004-06-08

      Tip for anyone playing with GCC 3.4.0:  You willl need to update your binutils.

      -- Jim.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.