English 中文(简体)
1. 未在左上角或任务栏上展示的习俗icon
原标题:Custom icon not displayed in upper left corner or on task bar

我用窗户 a子建立了基本应用程序。 这只是一个小窗口。 我从主要职能开始,接手,创造我的窗口等。 一切都做的是罚款。 然而,我面临的问题是,我的习俗icon将不会在窗口顶端或任务栏上展示,它只是显示一个窗口的缺省情景。 然而,这确实表明我的实际可点击的外壳是一角。 我利用善待提供资源,并创造所有4个系数,以便它能够拥有适当的规模。 接手

HICON hMyIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));

I then used WNDCLASSEX and gave the handle to both hIcon and hIconsm. If there is anything that could cause it to not show up in the corner or task bar, please help.

#include <Windows.h>
#include <iostream>
#include "resource.h"
//globals
    MSG msg;
    HWND hwndwnd;
    HICON hMyIcon;
//Windows Procedure
LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam )
{
    switch ( message )
    {
    case WM_CLOSE:    
        exit( 0 );
        break;    
    case WM_CREATE:
        SendMessage(hwndwnd,WM_SETICON,ICON_SMALL,(LPARAM)hMyIcon);
        break;
    }
    return DefWindowProc( hwnd, message, wparam, lparam );
}

int main(int ArgumentNum, char *arg[])
{
    //get instance
    char title[500];
    GetConsoleTitleA( title, 500 );
    HWND hwndConsole = FindWindowA( NULL, title );
    HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtr(hwndConsole, GWLP_HINSTANCE);
    //get icon handle
    hMyIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
    if (hMyIcon == NULL)
    {
         std::cout<< "NULL
";
    }
    //create & register class
    WNDCLASSEX wc;
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_DROPSHADOW;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = hMyIcon;
    wc.hCursor = LoadCursor(hInstance, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH );
    wc.lpszMenuName = 0;
    wc.lpszClassName = "Jacob";
    wc.hIconSm = hMyIcon;
    RegisterClassEx(&wc);
    //create window
    hwndwnd = CreateWindow("Jacob", "My Window", 
    WS_OVERLAPPEDWINDOW, 520, 20, 300, 300, NULL, NULL, hInstance, NULL);
    //Tried sendmessage here as well
    //SendMessage(hwndwnd,WM_SETICON,ICON_SMALL,(LPARAM)hMyIcon);
    ShowWindow( hwndwnd, SW_SHOWNORMAL);
    UpdateWindow( hwndwnd );
    //hide console, not using to see if icon is null
    //ShowWindow( hwndConsole, 0 );
    //message loop
    while(GetMessage( &msg, hwndwnd, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return 0;
}

这是我的源代码。 问题是否与我的资源有任何关系,这是我开始想到的。 当使用转基因器时,它就投放了一切可能的大小。 希望这一帮助,并感谢耐心。

最佳回答

我的第一个建议是尝试装上标准icon,而不是你自己的一意:

hMyIcon = LoadIcon(NULL, MAKEINTRESOURCE(IDI_ERROR));

这或许会奏效,而且你应当看到红色错误的信息。

下一步工作是设法以不同方式处理案件。 黄色窗口是一种奇怪的育种,与温32原体的其余部分相比,并不多。 Try:

hInstance = GetModuleHandle(NULL);
问题回答
  • Are you sure your LoadIcon calls return != NULL?
  • LoadIcon always loads a 32x32 icon, MSDN says if hIconSm is NULL, it checks the icon resource for a icon with the correct size so maybe you should try to set hIconSm=NULL;
  • You could use WM_SETICON

Edit:

//(Having your code from the start would have made things easier)
#include <Windows.h>
#include "resource.h"
MSG msg;
HWND hwndwnd;
HICON hMyIcon;

LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam )
{
    switch ( message )
    {
    case WM_CLOSE:    
        DestroyWindow(hwnd);//exit( 0 );
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    case WM_CREATE:
//        SendMessage(hwndwnd,WM_SETICON,ICON_SMALL,(LPARAM)hMyIcon);
        break;
    }
    return DefWindowProc( hwnd, message, wparam, lparam );
}


int main(int ArgumentNum, char *arg[]) 
{
/*
    You don t own/control the console window, don t use it s HWND if you don t have to.
    ...And there is even a function to get the HWND if you need it, no need for FindWindow

    char title[500];
    GetConsoleTitleA( title, 500 );
    HWND hwndConsole = FindWindowA( NULL, title );
    HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtr(hwndConsole, GWLP_HINSTANCE);
    */
    HINSTANCE hInstance=GetModuleHandle(NULL);
    hMyIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
    WNDCLASSEX wc;
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_DROPSHADOW;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = hMyIcon;
    wc.hCursor = LoadCursor(/*hInstance*/NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH );
    wc.lpszMenuName = 0;
    wc.lpszClassName = "Jacob";
#if 1 //The easy way
    wc.hIconSm = NULL;//hMyIcon; LoadIcon only loads 32x32 icons, you would get the wrong icon
#else //The hard way
    wc.hIconSm = (HICON)LoadImage(hInstance,MAKEINTRESOURCE(IDI_ICON1),IMAGE_ICON,GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON),0);
#endif
    RegisterClassEx(&wc);
    //create window
    hwndwnd = CreateWindow("Jacob", "My Window", 
    WS_OVERLAPPEDWINDOW, 520 , 20, 300, 300, NULL, NULL, hInstance, NULL);
    ShowWindow(hwndwnd,SW_SHOW);
    while(GetMessage( &msg, /*hwndwnd*/NULL, 0, 0) >0 ) //normally not a good idea to specify a hwnd
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return msg.wParam;
}




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签