Win32 API Icon Loading Error (VS2010)

This is a discussion on Win32 API Icon Loading Error (VS2010) within the C++ Programming forums, part of the General Programming Boards category; I am trying to load an icon I created for my program. Relevant code is below: Code: //resource.h #define IDR_MYMENU ...

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    32

    Question Win32 API Icon Loading Error (VS2010)

    I am trying to load an icon I created for my program. Relevant code is below:

    Code:
    //resource.h
    #define IDR_MYMENU                      103
    #define IDR_MYICON                        201
    #define ID_HELP_NOTICE         40001
    #define ID_HELP_ERROR                40002
    #define ID_FILE_EXIT                    40003
    
    //the .rc file
    IDR_MYMENU MENU
    BEGIN
        POPUP "&File"
        BEGIN
            MENUITEM "&Exit", ID_FILE_EXIT
        END
    
        POPUP "&Help"
        BEGIN
            MENUITEM "&Developer Notice", ID_HELP_NOTICE
            MENUITEM "&Error Codes", ID_HELP_ERROR
        END
    END
    
    IDI_MYICON ICON "myIcon.ico"
    
    //the section of code in the WINAPI function where I'm defining my window (WNDCLASSEX wc;)
        wc.cbSize        = sizeof(WNDCLASSEX);
        wc.style         = 0;
        wc.lpfnWndProc   = WndProc;
        wc.cbClsExtra    = 0;
        wc.cbWndExtra    = 0;
        wc.hInstance     = hInstance;
        wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
        wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
        wc.lpszClassName = g_szClassName;
        wc.lpszMenuName  = MAKEINTRESOURCE(IDR_MYMENU);
        //wc.hIcon  = LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_MYICON));
        wc.hIconSm  = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_MYICON), IMAGE_ICON, 16, 16, 0);
    
         if(!wc.hIconSm)
            MessageBox(NULL, L"Icon Registration Failed!", L"Error!",
                MB_ICONEXCLAMATION | MB_OK);
    
    //creating the actual window
    hwnd = CreateWindowEx(
            WS_EX_CLIENTEDGE,
            g_szClassName,
            L"Pandect - In Development",
            WS_OVERLAPPEDWINDOW | SB_LINEUP | SB_LINEDOWN | ES_MULTILINE |
            WS_HSCROLL | WS_VSCROLL,
            CW_USEDEFAULT, CW_USEDEFAULT, 1024, 768,
            NULL, NULL, hInstance, NULL);
    For some reason, the icon fails to load. I ran a breakpoint at the line for the hIconSm and got this error for the variable:

    Code:
    CXX0030: Error: expression cannot be evaluated
    The icon image is in the source folder and was compiled via ImageMagick. Google is not giving me any info regarding the error and the icon combined. Is there even a solution to this?

  2. #2
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    You call your icon IDI_MYICON
    but try to reference it in the hIconSm line as IDR_MYICON

  3. #3
    Registered User
    Join Date
    Sep 2012
    Posts
    32
    thank you for pointing that out. i didn't notice i defined it as an IDR everywhere but in the .rc file. it works now. thank you!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Loading Icon ?!?!?!?
    By C+noob in forum Windows Programming
    Replies: 7
    Last Post: 07-14-2005, 07:58 PM
  2. Loading image from a file (program icon)
    By GaPe in forum Windows Programming
    Replies: 4
    Last Post: 07-13-2004, 01:03 AM
  3. icon in win32 console application
    By osal in forum Windows Programming
    Replies: 3
    Last Post: 06-30-2004, 03:13 PM
  4. System Icon Loading & Other stuff
    By *ClownPimp* in forum Windows Programming
    Replies: 0
    Last Post: 01-11-2003, 10:17 PM

Tags for this Thread


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