I created a basic application with windows api. It just displays a small window. I start with the main function, get an instance, create a window class, etc. Everything works perfectly. However, the problem is that my custom icon will not appear in the upper left corner of the window or on the taskbar, it just shows a small window image by default. However, it appears as an icon for my actual clickable EXE file. I used resedit to create my resources and created all 4 icon sizes so that it has one available size. I got a pen with
HICON hMyIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
Then I used WNDCLASSEX and gave the handle to both hIcon and hIconsm. If there is something that might make it not appear in a corner or taskbar, please help.
#include <Windows.h>
#include <iostream>
#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:
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[])
{
char title[500];
GetConsoleTitleA( title, 500 );
HWND hwndConsole = FindWindowA( NULL, title );
HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtr(hwndConsole, GWLP_HINSTANCE);
hMyIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
if (hMyIcon == NULL)
{
std::cout<< "NULL\n";
}
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);
hwndwnd = CreateWindow("Jacob", "My Window",
WS_OVERLAPPEDWINDOW, 520, 20, 300, 300, NULL, NULL, hInstance, NULL);
ShowWindow( hwndwnd, SW_SHOWNORMAL);
UpdateWindow( hwndwnd );
while(GetMessage( &msg, hwndwnd, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
This is my source code. What I start to wonder if my problem has something to do with my resources. When I used resedit I have an mad icon of any size. Hope this helps, and thanks for your patience.