Need help in resource file

This is a discussion on Need help in resource file within the Windows Programming forums, part of the Platform Specific Boards category; im creating a winapi program with a simple menu and i get an error in my resource file when i ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Location
    New York
    Posts
    123

    Need help in resource file

    im creating a winapi program with a simple menu and i get an error in my resource file when i try to compile it. cannot open "ICON" file
    line 18 : IDI_MYICON ICON "menu_one.ico"

    resource file codes:
    Code:
    //This is for simple menu
    #include "resources.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"
    header file code:
    Code:
    //Resource header made by justin :)
    
    //the below code is used with the .rc file
    #define IDR_MYMENU 101
    #define IDI_MYICON "menu_one.ico" 201
    
    #define ID_FILE_EXIT 9001
    #define ID_STUFF_GO 9002
    my main() code...:
    Code:
    #include <windows.h>
    #include "resources.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.hIcon  = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
        wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
        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;
        }
    
        // Step 2: Creating the Window
        hwnd = CreateWindowEx(
            WS_EX_CLIENTEDGE,
            g_szClassName,
            "Justin window of pain",
            WS_OVERLAPPEDWINDOW,
            CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
            NULL, NULL, hInstance, NULL);
    
        if(hwnd == NULL)
        {
            MessageBox(NULL, "DAMN IT ERROR!", "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;
    }
    i added the header file code, and main code to show u wants just going on...

  2. #2
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    The compiler can't find your .ico file. Have you created it?
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  3. #3
    Registered User
    Join Date
    Oct 2006
    Location
    New York
    Posts
    123

    ???

    i got get i did this off of winprog.org, and i did exactly what it said.. >.<

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    As manutd has already pointed out, the resource compiler cannot find 'menu_one.ico'. Either it doesn't exist or it's not in the path the resource compiler knows about. If it does exist then, as a quick test, provide the full path and name for 'menu_one.ico'. If it doesn't exist, you'll have to provide it and put it in the same directory as the resource script (*.rc) and its accompanying header file.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  5. #5
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Since you got it off of winprog, you must do what winprog did. In the project directory, you need to have a .ico file named menu_one.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  6. #6
    Mad OnionKnight's Avatar
    Join Date
    Jan 2005
    Location
    Ume, Sweden
    Posts
    555
    IDI_MYICON ICON "menu_one.ico"
    #define IDI_MYICON "menu_one.ico" 201
    This expands into
    "menu_one.ico" 201 ICON "menu_one.ico"
    The icon filename is not supposed to be there in the define, just the ID-number like with everything else.

  7. #7
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    aka make it:
    Code:
    #define IDI_MYICON 201
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  8. #8
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Quote Originally Posted by OnionKnight
    This expands into

    The icon filename is not supposed to be there in the define, just the ID-number like with everything else.
    Glad to see someone's paying attention - well spotted.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 04:53 AM
  2. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  3. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  4. resource file problem
    By jjj93421 in forum Game Programming
    Replies: 6
    Last Post: 03-30-2004, 10:58 PM
  5. menu resource file
    By satriani in forum Windows Programming
    Replies: 5
    Last Post: 06-08-2002, 11:52 PM

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