CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2009
    Posts
    1,355

    [RESOLVED] win32 - WNDCLASSEX: how we change the window icon?

    for we create a window, we must, first, create a register a class:
    Code:
    string strWindowClassName = "WindowClassname";		WNDCLASSEX wndClassName;
    		ZeroMemory(&wndClassName, sizeof(WNDCLASSEX));
    		wndClassName.cbSize = sizeof(WNDCLASSEX);
    		wndClassName.cbClsExtra = 0;
    		wndClassName.cbWndExtra = 0;
    		wndClassName.hbrBackground = (HBRUSH)(COLOR_WINDOW);
    		wndClassName.hCursor = LoadCursor(NULL, IDC_ARROW);
    		wndClassName.hIcon = LoadIcon(NULL, IDI_WINLOGO);
    		wndClassName.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
    		wndClassName.hInstance = GetModuleHandle(NULL);
    		wndClassName.lpfnWndProc = (WNDPROC)WndProc;
    		wndClassName.lpszClassName = strWindowClassName.c_str();
    		wndClassName.lpszMenuName = 0;
    		wndClassName.style = CS_HREDRAW | CS_VREDRAW;
    		if (!RegisterClassEx(&wndClassName))
    			MessageBox(NULL, "Not Registed", "error", MB_OK);
    until here, it's normal...
    now i need to show you just WNDCLASSEX 2 members:
    Code:
    wndClassName.hIcon = LoadIcon(NULL, IDI_WINLOGO);
    		wndClassName.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
    these 2 members are for change the window icon(hIconSm) and on windows toolbar icon(hIcon). these 2 members must be the same(tested).
    i have 1 question about IDI consts. i can use IDI_QUESTION, but not the IDI_WINLOGO... why? it's because of the icon resolution?

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: win32 - WNDCLASSEX: how we change the window icon?

    Not sure I'm understanding the question. LoadIcon() can only load an icon whose size conforms to the SM_CXICON and SM_CYICON system metric values.

    See remarks section in https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: win32 - WNDCLASSEX: how we change the window icon?

    Quote Originally Posted by Cambalinho View Post
    ... i can use IDI_QUESTION, but not the IDI_WINLOGO... why? it's because of the icon resolution?
    What exactly is your problem by using IDI_WINLOGO icon?
    Victor Nijegorodov

  4. #4
    Join Date
    Apr 2009
    Posts
    1,355

    Re: win32 - WNDCLASSEX: how we change the window icon?

    "What exactly is your problem by using IDI_WINLOGO icon?"
    now i get it the
    IDI_WINLOGO and IDI_APPLICATION are the same icon:
    Value Meaning
    IDI_APPLICATIONMAKEINTRESOURCE(32512) Default application icon.
    IDI_ASTERISKMAKEINTRESOURCE(32516) Asterisk icon. Same as IDI_INFORMATION.
    IDI_ERRORMAKEINTRESOURCE(32513) Hand-shaped icon.
    IDI_EXCLAMATIONMAKEINTRESOURCE(32515) Exclamation point icon. Same as IDI_WARNING.
    IDI_HANDMAKEINTRESOURCE(32513) Hand-shaped icon. Same as IDI_ERROR.
    IDI_INFORMATIONMAKEINTRESOURCE(32516) Asterisk icon.
    IDI_QUESTIONMAKEINTRESOURCE(32514) Question mark icon.
    IDI_SHIELDMAKEINTRESOURCE(32518) Security Shield icon.
    IDI_WARNINGMAKEINTRESOURCE(32515) Exclamation point icon.
    IDI_WINLOGOMAKEINTRESOURCE(32517) Default application icon.
    Windows 2000: Windows logo icon.
    i know that i can choose the icon by resource or file. i don't know all macros icons. but the result it's the same.
    see these image:
    Name:  Sem TÃ*tulo.png
Views: 1096
Size:  6.5 KB
    that icon, on image, is the default icon?
    on MSDN i can't see the icons

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: win32 - WNDCLASSEX: how we change the window icon?

    Quote Originally Posted by Cambalinho View Post
    ... that icon, on image, is the default icon?
    on MSDN i can't see the icons
    Yes, it is a default one.
    All these standard icons are stored in the User32.dll
    Victor Nijegorodov

  6. #6
    Join Date
    Apr 2009
    Posts
    1,355

    Re: win32 - WNDCLASSEX: how we change the window icon?

    thanks for correct me

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured