I have created a basic application with with windows api. It just displays a small window. I am starting from main function, getting the instance, created my windows class, etc. Everything works out fine. The problem I have however is that my custom icon will not display in the top left corner of the window or on the task bar, it just shows the default little picture of a window. It does however show up as the icon for my the actual click-able exe file. I used resedit to make my resources, and created all 4 icon sizes so it should have one available of the proper size. I got the handle with
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\n";
}
//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;
}
This is my source code. What im starting to wonder is if my problem has anything to do with my resources. When i used resedit i mad an icon of every possible size. Hope this Helps, and thanks for the patience.