Icon nicht neben Fenstertitel trotz resource!!!
-
Hallo zusammen,
habe kuerzlich gesehen das hier nach dem Icon in der linken oberen Ecke
eines Fensters gefragt wurde. Leider sind die Treads nicht weiter behandelt worden.
Habe mich daran gemacht bei meinem Programm auch mal ein Icon anzeigen zu lassen,
und nicht immer dieses weisse Viereck.Nun ist der Code zwar aus einem Tuturial uebernommen in dem auch mit Dev-C++ gearbeitet
wurde, nur leider funzt es nicht so wie es soll.
Hier mal ein wenig Code
//main.c #include <windows.h> #include <stdio.h> #include <time.h> #include <stdbool.h> #include "resource.h" /* Declare Windows procedure */ LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); 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 */ wincl.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW; /* Catch double-clicks */ wincl.cbSize = sizeof (WNDCLASSEX); wincl.hIcon = LoadIcon (GetModuleHandle(NULL), MAKEINTRESOURCE(ID_ICON)); 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 actual Windows's color as the background of the window */ wincl.hbrBackground = (HBRUSH) GetSysColorBrush(COLOR_WINDOW); //rueckgabewert von GetSysColorBrush wird gecastet /* 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 */ "Nicos Alter 5", /* Title Text */ WS_BORDER | WS_SYSMENU, /* thin border, size can't be change with close button */ CW_USEDEFAULT, /* Windows decides the position */ CW_USEDEFAULT, /* where the window ends up on the screen */ 200, /* The programs width */ 120, /* 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 */ TranslateMessage(&messages); /* Send message to WindowProcedure */ DispatchMessage(&messages); } /* The program return-value is 0 - The value that PostQuitMessage() gave */ return messages.wParam; } /* This function is called by the Windows function DispatchMessage() */ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; /* A device context used for drawing */ PAINTSTRUCT ps; /* Also used during window drawing */ RECT rc; /* A rectangle used during drawing */ const UINT TimerID = 1; const int iDelay = 1000; // = Zeit einstellen switch (message) /* handle the messages */ { case WM_CREATE: { SetTimer(hwnd, TimerID, iDelay, NULL); //Timer setzen return 0; } case WM_TIMER: { berechne_alter(); InvalidateRect(hwnd, NULL, TRUE); return 0; break; } case WM_DESTROY: { KillTimer(hwnd, TimerID); //nicht vergessen den Timer zu loeschen!!! PostQuitMessage (0); /* send a WM_QUIT to the message queue */ break; } case WM_PAINT: { /* The window needs to be painted (redrawn). */ hdc = BeginPaint (hwnd, &ps); GetClientRect (hwnd, &rc); //Hintergrund der Schriftart transparent machen SetBkMode(hdc,TRANSPARENT); //den Text ausgeben DrawText (hdc, (LPCTSTR)&cText, -1, &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER ); EndPaint (hwnd, &ps); return 0; break; } default: /* for messages that we don't deal with */ return DefWindowProc (hwnd, message, wParam, lParam); } return 0; }die resource.h
#define ID_ICON 111und zu guter letzt noch resource.rc
ID_ICON ICON "NicosAlter.ico"Die Icondatei liegt im selben Verzeichniss wie alle anderen Dateien.
(*.c; *.h; *.rc usw.)Hat jemand eine Idee warum das Icon nur in der Taskleiste angezeigt wird?

-
Hier liegt der Fehler:
wincl.hIcon = LoadIcon (GetModuleHandle(NULL), MAKEINTRESOURCE(ID_ICON)); wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);Mache es so:
wincl.hIcon = LoadIcon (hThisInstance, MAKEINTRESOURCE(ID_ICON)); wincl.hIconSm = LoadIcon (hThisInstance, MAKEINTRESOURCE(ID_ICON));
-
Danke fuer den Tip!
Leider aber immer noch so. Das Icon wird nur in der Taskleiste angezeigt.
Im Fenster bleibt es bei dem weissen Viereck (Standardsymbol?).Eventuell ein Problem mit der IDE (Dev-C++)

-
Eventuell ein Problem mit der IDE (Dev-C++)
Nein!
So wie ich es Vorgab funktioniert es.
a. #include "resource.h" muß in der resource.rc und in der main.cpp stehen
b. projektOptionen->Dateien auf "recourcen.rc" klicken und hacken rein bei "In kompilation einbeziehen"
c. das so machen wie ich es vorgab.wenn es jetzt immer noch nicht geht liegt der Fehler wo anders
nur wo?
-
Super das wars! Danke!

Hatte die "resource.h" in der "resource.rc" nicht includiert!
Das Haeckchen, zum einkompilieren der resource.rc war bereits gesetzt.