Thread: Icon Trouble

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    545

    Icon Trouble

    I am following the Forger's tutorial and have a problem with adding my icon, the error is only in two lines and i think i know where it is i just don't know how to get rid.

    Code:
    hIcon = LoadImage(NULL, "menu_one.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE);
    
    hIconSm = LoadImage(NULL, "menu_one.ico", IMAGE_ICON, 16, 16, LR_LOADFROMFILE);
    The error is the same in both lines and it says:
    29 untitled18.cpp
    ANSI C++ forbids implicit conversion from `void *' in assignment

    I am using Dev C++

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    In C++, you will have to use a cast. This is because LoadImage can return objects of several types (HICON, HBITMAP) so returns a void*. In C++ (but not C), a cast is required to go from a void* to another type. The Forger tutorials are written for C so there will be a few minor changes needed to compile with C++.
    Code:
    hIcon = (HICON) LoadImage(NULL, "menu_one.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE);
    
    hIconSm = (HICON) LoadImage(NULL, "menu_one.ico", IMAGE_ICON, 16, 16, LR_LOADFROMFILE);

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    Thanks

  4. #4
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    When you are writing for Windows after you have the code for creating the window, is everything else done in the WinProc area? (obviously apart from changing things like window size)

  5. #5
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273
    Generally speaking, yes. Unless you're doing something funky with multiple threads, then nearly all of the code you're gonna write for a GUI program will occur in or branch from a window procedure.

  6. #6
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    I now have a problem creating a dialogue the error is in:
    Code:
     GROUPBOX        "About this program...",IDC_STATIC,7,7,225,52

  7. #7
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    oh it is a parse error

  8. #8
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    You need to define IDC_STATIC after your includes (in the .rc file):
    Code:
    #include <windows.h>
    #define IDC_STATIC -1

  9. #9
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    MAKEINTRESOURCE(IDD_ABOUT), hwnd, AboutDlgProc);

    I nwo have a problewm with that line: parse error before ), it doesnt work in C or C++

  10. #10
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    That means that you don't have IDD_ABOUT defined. You should have a "resource.h" file with the ID defines in it. This file is included in both the rc file and the .c or .cpp file.

  11. #11
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    Ok i thought I had tried define IDD_ABOUT

  12. #12
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    #include <windows.h>
    #define IDC_STATIC -1
    #define IDD_ABOUT

    that is my dialog header file and that is included in the main file

  13. #13
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    Any help?

  14. #14
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You're not supposed to bump threads.

    You should have a "resource.h" file with the ID defines in it. This file is included in both the rc file and the .c or .cpp file.
    Do you?

    Code:
    MAKEINTRESOURCE(IDD_ABOUT), hwnd, AboutDlgProc);
    I nwo have a problewm with that line: parse error before ), it doesnt work in C or C++
    Of course not. You need this:
    Code:
    MAKEINTRESOURCE(IDD_ABOUT /* nothing here */, hwnd, AboutDlgProc);
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  15. #15
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    Bump Threads?

    And what do i do about my problem because I don't know what that is that you just showed me

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Icon Help
    By The Brain in forum Windows Programming
    Replies: 11
    Last Post: 04-05-2009, 04:06 PM
  2. Custom Icon for DLL
    By Delf in forum Windows Programming
    Replies: 5
    Last Post: 06-10-2005, 08:36 AM
  3. Icon problem
    By mkyong in forum Windows Programming
    Replies: 0
    Last Post: 02-17-2003, 05:39 PM
  4. Icon? help!
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-16-2001, 06:21 PM
  5. icon in title bar?
    By Unregistered in forum Windows Programming
    Replies: 3
    Last Post: 12-12-2001, 06:43 PM