resources

This is a discussion on resources within the Windows Programming forums, part of the Platform Specific Boards category; I'm just starting Windows programming using C, and have been going through a tutorial - http://www.winprog.org/tutorial/index.html - however, I'm having ...

  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    18

    resources

    I'm just starting Windows programming using C, and have been going through a tutorial - http://www.winprog.org/tutorial/index.html - however, I'm having trouble getting my compiler to include the resource file i want to include. I'm using Bloodshed Dev-C++. The error message I get is
    C:\Dev-Cpp\Makefile.win [Build Error] No rule to make target `files/resource.rc"', needed by `Project1_private.res'. Stop.
    I'm sure this is very much a rookie mistake, but a quick solution would be useful as I can't find anything about it in the documentation.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,262
    Does your resource script (resource.rc) file generate a header (like maybe resource.h)? If so, include that instead.

  3. #3
    Registered User
    Join Date
    Nov 2004
    Posts
    18
    Yeah, I have a resource.h file as well, and that is the only one that's included with the actual file. The complete project contains the files simplewindow.c, resource.h and resource.rc. Maybe it'll help if I post the actual code.

    Code:
    #include <windows.h>
    
    #include "resource.h"
    
    const char g_szClassName[] = "myWindowClass";
    
    // Step 4: the Window Procedure
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
        switch(msg)
        {
            case WM_LBUTTONDOWN:   
            {
                char szFileName[MAX_PATH];
                HINSTANCE hInstance = GetModuleHandle(NULL);
    
                GetModuleFileName(hInstance, szFileName, MAX_PATH);
                MessageBox(hwnd, szFileName, "This program is:", MB_OK | MB_ICONINFORMATION);
            } 
            break;        
            case WM_CLOSE:
                DestroyWindow(hwnd);
            break;
            case WM_DESTROY:
                PostQuitMessage(0);
            break;
            default:
                return DefWindowProc(hwnd, msg, wParam, lParam);
        }
        return 0;
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
        LPSTR lpCmdLine, int nCmdShow)
    {
        WNDCLASSEX wc;
        HWND hwnd;
        MSG Msg;
    
        //Step 1: Registering the Window Class
        wc.cbSize        = sizeof(WNDCLASSEX);
        wc.style         = 0;
        wc.lpfnWndProc   = WndProc;
        wc.cbClsExtra    = 0;
        wc.cbWndExtra    = 0;
        wc.hInstance     = hInstance;
        wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
        wc.lpszMenuName  = MAKEINTRESOURCE(IDR_MYMENU);
        wc.lpszClassName = g_szClassName;
        wc.hIcon  = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
        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;
        }
    
        // Step 2: Creating the Window
        hwnd = CreateWindowEx(
            WS_EX_CLIENTEDGE,
            g_szClassName,
            "The title of my window",
            WS_OVERLAPPEDWINDOW,
            125, 140, 600, 400,
            NULL, NULL, hInstance, NULL);
    
        if(hwnd == NULL)
        {
            MessageBox(NULL, "Window Creation Failed!", "Error!",
                MB_ICONEXCLAMATION | MB_OK);
            return 0;
        }
    
        ShowWindow(hwnd, nCmdShow);
        UpdateWindow(hwnd);
    
        // Step 3: The Message Loop
        while(GetMessage(&Msg, NULL, 0, 0) > 0)
        {
            TranslateMessage(&Msg);
            DispatchMessage(&Msg);
        }
        return Msg.wParam;
    }
    Code:
    #define IDR_MYMENU 101
    #define IDI_MYICON 201
    
    #define ID_FILE_EXIT 9001
    #define ID_STUFF_GO 9002
    Code:
    #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"

    Edit: I changed some of the code in the first section above here when I realised it was the wrong thing. Basically the program should be displaying a menu with the details I get from the resource file. I took the .rc file out of the project and this time it compiles, but it doesn't show the menu, or use the correct icon.
    Last edited by richardfish; 11-16-2004 at 02:06 PM.

  4. #4
    </life>
    Join Date
    Oct 2004
    Posts
    83
    You might want to check out the MinGW Developer Studio as it comes with a resource editor, and imho is better than dev-c++.

    MinGW Developer Studio Hompage
    Microsoft is merely an illusion, albeit a very persistant one.

  5. #5
    Registered User
    Join Date
    Nov 2004
    Location
    Slovenia, Europe
    Posts
    115
    I guess you're using Winprog.org tutorials...

    I found my way out with observing the defined constants, and using only the numbers to define menu, menu selections, etc..

    So the code looks like that:

    Code:
     101 MENU 
    BEGIN
    ...
    END
    And when you use the menu, you should define an integer for substitution for IDR_MYMENU....

    Code:
    wc.lpszMenuName = MAKEINTRESOURCE(101);

  6. #6
    Registered User
    Join Date
    Nov 2004
    Posts
    18
    Isn't it the case that it will just make things more complicated and it's bad programming practice to use the actual numbers rather than the identifiers? I mean keeping tracking of the numbers alone is going to get very difficult with larger programs. Maybe I might have more luck trying to use MinGW -- I'll give it a go, thanks.

  7. #7
    Registered User
    Join Date
    Nov 2004
    Location
    Slovenia, Europe
    Posts
    115
    the other reason is that Dev-CPP doesn't compile the resource files, which you created in a project, but a resource files in a project folder (ex. C:\project\) which are most possible outdated. So try to change this files and try to compile once again and than report what happened.

    So, on short:

    You have a resource file in Dev-C++ project, called resource.h and you try to compile a project with identifiers, which are declared in project file resource.h. You have to copy the project file resource.h to file resource.h on the hard disk.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Resources in Dev C++
    By JJFMJR in forum Windows Programming
    Replies: 7
    Last Post: 08-27-2007, 06:14 AM
  2. measuring system resources used by a function
    By Aran in forum C Programming
    Replies: 1
    Last Post: 03-13-2006, 05:35 PM
  3. Getting resources from another program.
    By Queatrix in forum C++ Programming
    Replies: 3
    Last Post: 02-11-2006, 09:00 PM
  4. Storing resources into a single file
    By LuckY in forum Game Programming
    Replies: 20
    Last Post: 08-15-2004, 12:28 AM
  5. Adding resources
    By nima_ranjbar in forum Windows Programming
    Replies: 0
    Last Post: 04-15-2002, 12:36 AM

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