Menu

Problem with using resources.

2007-08-10
2012-09-26
  • Nobody/Anonymous

    I've just entered the world of Windows programming, and trying to get resources to work. I'm using Dev C++ 4.9.9.2

    I've created the win_d.rc with ResED:

    define ID_MENU1 10000

    define ID_MFILE 10001

    define ID_MDIALOG 10002

    ID_MENU1 MENU
    BEGIN
    POPUP "File"
    BEGIN
    MENUITEM "dialog",ID_MDIALOG
    END
    END

    The win_d.cpp is the same has the default windows programme except for:

    Line 2:

    include "win_d.rc"

    line 30:
    wincl.lpszMenuName = MAKEINTRESOURCE(ID_MENU1);

    Now this seems simple, but i keep getting the following errors:
    2 C:\Dev-Cpp\win_d.cpp In file included from win_d.cpp
    4 C:\Dev-Cpp\win_d.rc expected unqualified-id before numeric constant
    4 C:\Dev-Cpp\win_d.rc expected ,' or;' before numeric constant

    Then it gives a load of WindowProcedure undeclared errors.

    It doesn't matter if i include the rc file in the project or not, nothing is working!

    Thanks in advance

     
    • Osito

      Osito - 2007-08-10

      I think line 30 should be: wincl.lpszMenuName = "some_menu_name";
      And ID_MENU1 MENU should be: some_menu_name MENU

       
    • Nobody/Anonymous

      Nope. Same error messages. And if i do
      undefined_menu_name MENU, says i need to name a type.

       
      • Osito

        Osito - 2007-08-10

        Maybe it's something else then? This is how my .rc file looks:

        include "chamber.h"

        MAINMENU MENU
        {
        POPUP "&File"

        ... etc ...

        And my window initialization:

        int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
        {
        WNDCLASSEX WndClass;
        HWND hwnd;
        MSG Msg;

        ... stuff deleted ...

        WndClass.lpszMenuName = "MAINMENU";
        WndClass.lpszClassName = g_szClassName;

        Those are the only two places in my project where the MAINMENU text shows up, so it's not a #define or anything, just a text string. Note that in the c file you put quotes around it like a string, but in the resource file you don't.

         
    • Nobody/Anonymous

      include "chamber.h"

      what does chamber.h include? Do you define MAINMENU in there?

      No matter what i call it i sill get the same error messages, either saying it doesnt name a type, or expected unqualified id if i define it. The .cpp file works if i change line 30 to not point to any menu, aka i don't call on the rc file except to include it. So either something is wrong with my resource, or the DEV C++ settings aren't allowing resources or something?

      Thanks for sticking with me :)

       
      • Osito

        Osito - 2007-08-10

        My chamber.h has the ID number defines, and like I said MAINMENU is not defined any where. It only shows up in those two places.

         
        • Wayne Keen

          Wayne Keen - 2007-08-10

          It would really help if, as Clifford asked, you would post your full compile log.

          It is on the tab labeled "Compile Log", and the right mouse button brings up the copy menu

          Please do NOT excerpt the error messages, the value of the log goes FAR beyond that.

          If you have a lot of errors, copy from the beginning of the log through the first 5 or so errors.

          Wayne

           
    • Anonymous

      Anonymous - 2007-08-10

      You have included the .rc file in a .cpp file, but it is not C++ code - the C++ compiler won't know what to do with that! You give the .rc code to the Resource Compiler not the C++ compiler.

      You need the resource file for the resource compiler and a separate header (.h) with just the #define macro definitions in for the C++ compiler.

      Note that this problem was harder to spot because you did not post the "Compile Log". You posted the text from the "Compiler" tab which filters out a lot of useful information. For example it would have been obvious that this was a g++ error message and not a windres error message.

      Clifford

       
    • Nobody/Anonymous

      Ok, I kept out all that stuff to keep my post concise (I've seen posts that are filled with unimportant information.

      Well here is the compile log:

      Compiler: Default compiler
      Building Makefile: "C:\Dev-Cpp\Makefile.win"
      Executing make...
      make.exe -f "C:\Dev-Cpp\Makefile.win" all
      g++.exe -c win_d.cpp -o win_d.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"

      In file included from win_d.cpp:3:
      win_d.rc:2: error: expected unqualified-id before numeric constant
      win_d.rc:2: error: expected ,' or;' before numeric constant
      win_d.cpp: In function int WinMain(HINSTANCE__*, HINSTANCE__*, CHAR*, int)': win_d.cpp:24: error:WindowProcedure' undeclared (first use this function)
      win_d.cpp:24: error: (Each undeclared identifier is reported only once for each function it appears in.)
      win_d.cpp:32: error: invalid conversion from int' toconst CHAR*'

      win_d.cpp: In function LRESULT WindowProcedure(HWND__*, UINT, WPARAM, LPARAM)': win_d.cpp:78: error:LRESULT WindowProcedure(HWND__*, UINT, WPARAM, LPARAM)' used prior to declaration

      make.exe: *** [win_d.o] Error 1

      Execution terminated

      Hopefully this will help :)

       
    • Anonymous

      Anonymous - 2007-08-11

      Are my posts invisible or something!?

      You cannot #include a .rc file in a .cpp file.

      A few more times for the hard of thinking:

      You cannot #include a .rc file in a .cpp file.
      You cannot #include a .rc file in a .cpp file.
      You cannot #include a .rc file in a .cpp file.
      You cannot #include a .rc file in a .cpp file.

      Despite the fact that you have not posted any code I know that in win_d.cpp you have a line:

      include "win_d.rc"

      but resource scripts ARE NOT C++, you cannot expect the C++ compiler to understand your resource script.

      >> I kept out all that stuff to keep my post concise
      But since you are the one with the problem, you are hardly qualified to decide what is necessary and what is not. What is expected is clearly described in the "PLEASE READ BEFORE POSTING A QUESTION" thread.

      I am no great Win32 programmer, but there are examples supplied with Dev-C++ that use resource scripts take a look at those. But you should move the #define macros to a separate header file then include that in both the .cpp file and the .rc file. The .rc file should then be separately added to your project so that Dev-C++ will compile it with windres.exe not g++.exe.

      Clifford

       

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.