Thread: How to place your ICON on the top window

  1. #1
    Registered User
    Join Date
    Jan 2003

    Question How to place your ICON on the top window

    I'm new to this board, and also to C++. I use DEV-C++ app.

    I'm also a wonderful website designer/hoster....but now find myself wanting to learn how to program my own programs,
    so that i can support myself better (financially).

    Anyway, I need to know how to insert the code for placing a icon on the windows I the upper left hand side, as most other programs do?

    Here, (I assume) is where it's placed: (in the file called:main.cpp)

    /* Use default icon and mouse-pointer */
    hIcon = LoadIcon (NULL, IDI_APPLICATION);
    can someone please help me out? I want to place a ICO file called: kit.ico
    Last edited by myispnet; 01-06-2003 at 07:54 PM.

  2. #2
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    or the code version ...I found people arn't nearly as likly to look @ it if they have to download it heh.

    #include <windows.h>
    /*  Declare Windows procedure  */
    /*  Make the class name into a global variable  */
    char szClassName[ ] = "WindowsApp";
    int WINAPI
    WinMain (HINSTANCE hThisInstance,
             HINSTANCE hPrevInstance,
             LPSTR lpszArgument,
             int nFunsterStil)
        HWND hwnd;               /* This is the handle for our window */
        MSG messages;            /* Here messages to the application are saved */
        WNDCLASSEX wincl;        /* Data structure for the windowclass */
        /* The Window structure */
        wincl.hInstance = hThisInstance;
        wincl.lpszClassName = szClassName;
        wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */ = CS_DBLCLKS;                 /* Catch double-clicks */
        wincl.cbSize = sizeof (WNDCLASSEX);
        /* Use default icon and mouse-pointer */
        wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
        wincl.lpszMenuName = NULL;                 /* No menu */
        wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
        wincl.cbWndExtra = 0;                      /* structure or the window instance */
        /* Use Windows's default color as the background of the window */
        wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
        /* Register the window class, and if it fails quit the program */
        if (!RegisterClassEx (&wincl))
            return 0;
        /* The class is registered, let's create the program*/
        hwnd = CreateWindowEx (
               0,                   /* Extended possibilites for variation */
               szClassName,         /* Classname */
               "KompuKit-beta",       /* Title Text */
               WS_OVERLAPPEDWINDOW, /* default window */
               CW_USEDEFAULT,       /* Windows decides the position */
               CW_USEDEFAULT,       /* where the window ends up on the screen */
               780,                 /* The programs width */
               580,                 /* and height in pixels */
               HWND_DESKTOP,        /* The window is a child-window to desktop */
               NULL,                /* No menu */
               hThisInstance,       /* Program Instance handler */
               NULL                 /* No Window Creation data */
        /* Make the window visible on the screen */
        ShowWindow (hwnd, nFunsterStil);
        /* Run the message loop. It will run until GetMessage() returns 0 */
        while (GetMessage (&messages, NULL, 0, 0))
            /* Translate virtual-key messages into character messages */
            /* Send message to WindowProcedure */
        /* The program return-value is 0 - The value that PostQuitMessage() gave */
        return messages.wParam;
    /*  This function is called by the Windows function DispatchMessage()  */
    WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
        switch (message)                  /* handle the messages */
            case WM_DESTROY:
                PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            default:                      /* for messages that we don't deal with */
                return DefWindowProc (hwnd, message, wParam, lParam);
        return 0;

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  3. #3
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    this has the stench of a windows question to me...

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Depends to some extent on your compiler. Look up the documentation at msdn on LoadImage() and LoadIcon(). Then consult your compilers helpfiles to learn how to use your resource compiler.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :-

  5. #5
    Registered User
    Join Date
    Jan 2003

    Not sure you understand what i need

    You know how, when one of your apps' windows comes up...
    (to do whatever)...well, at the top of the window on the left, next to the programs name (title)...there's a icon usually...
    sometimes it's the authors logo or the programs' logo...

    well, I need to know how to place that on my windows...using the code in main.cpp (I supplied) or step-by-step HOW-to

    I can't seem to find how to do this...I hate the default icon there...yuk.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C or C++
    By AcerN30 in forum Game Programming
    Replies: 41
    Last Post: 05-30-2008, 06:57 PM
  2. Just starting Windows Programming, School me!
    By Shamino in forum Windows Programming
    Replies: 17
    Last Post: 02-22-2008, 08:14 AM
  3. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 02:33 PM
  4. dont want to use all params
    By stallion in forum Windows Programming
    Replies: 2
    Last Post: 02-18-2003, 08:10 AM
  5. Stack functions as arrays instead of node pointers
    By sballew in forum C Programming
    Replies: 8
    Last Post: 12-04-2001, 11:13 AM