Du bist nicht angemeldet.

Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!

Werbeanzeige

1

23.01.2007, 14:57

API: Icon willl nicht!

Hallo.
Ich habe eine Fensterklasse geschrieben.
Doch wenn ich ein icon einfügen will funktioniert das nicht!

Hier erstmal die dateitypen:

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
typedef struct tVertex2D  // Wieder ein neuer Dateityp! Hier kann man einen Vektor angeben!

{
       tVertex2D() {}
       tVertex2D (int new_x, int new_y, int new_b, int new_h)
       {
        x = new_x;
        y = new_y;
        b = new_b;
        h = new_h;
       }
       
       int x; //x Position

       int y; //y Position

       int b; //breite

       int h; //hoehe

       
       };
       
typedef struct tColor  //Hier können Farben definiert werden!!

{
       tColor() {}
       tColor(int new_r, int new_g, int new_b)
       {
                  
       R = new_r;
       G = new_g;
       B = new_b;
       
       }
       
       int R;
       int G;
       int B;
       
       };

typedef struct tInfo   //Neuer Dateityp wird eingefügt! Hier werden alle daten vom Fenster gespeichert!

{
       HWND hwnd;
       LPARAM lParam;
       WPARAM wParam;
              
       int Menuid;
       int Icoid;
       
       tVertex2D Position;
       
       tColor Color;
       
       HINSTANCE hThisInstance;
       HINSTANCE hPrevInstance;
       LPSTR lpszArgument;
       int nFunsterStil;
       
       };


So. Jetzt mal die Klasse:

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//::::::::::::::::::::::::::::

//:::::::::Window.h:::::::::::

//::::::::::::::::::::::::::::

//::::Copyright by Florian::::

//::::::::::::::::::::::::::::



//-------------------------------Die Fenster funktion---------------------------


LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);

//----------------------------------Klasse--------------------------------------


class tWindow
{
      private:     HWND hwnd;                                                   //Window handle (Grundfenster)

                   WNDCLASSEX wincl;                                            //Windows-klasse: Styles

                   MSG messages;                                                //Window-Message

      
      public: tWindow();
              bool creat(char *ClassName, char *titel, tInfo Window);           //Erstellt das Fenster!

              void run();                                                       //Hier ist die Nachrichtenschleife

              MSG message();                                                   //gibt die aktuelle Message wieder

              
              
              
      
      };
      
//------------------------------------------------------------------------------    

  
tWindow::tWindow(){
                   
reset_Logbuch();

}

//------------------------------------------------------------------------------


bool tWindow::creat(char *ClassName, char *titel, tInfo Window) //erstellt >ein< Fenster!

{
     
    //Windows-klasse

    wincl.hInstance = Window.hThisInstance;
    wincl.lpszClassName = ClassName;
    wincl.lpfnWndProc = WindowProcedure;     
    wincl.style = CS_DBLCLKS;       
    wincl.cbSize = sizeof (WNDCLASSEX);    
    wincl.hIcon  = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(Window.Icoid));
    wincl.hIconSm  = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(Window.Icoid), IMAGE_ICON, 16, 16, 0);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName  = MAKEINTRESOURCE(Window.Menuid);
    wincl.cbClsExtra = 0;                   
    wincl.cbWndExtra = 0;                    
    wincl.hbrBackground = (HBRUSH) CreateSolidBrush(RGB(Window.Color.R, Window.Color.G, Window.Color.B)); 
    //Windows-klasse

    
    
    if (!RegisterClassEx (&wincl)){  //Klasse wird regestriert!

        into_Logbuch("Fensterklasse konnte nicht regestiert werden!", false);
        return 0;
        }else{
        into_Logbuch("Fenster wurde regestriert!", true);
        }
    
    hwnd = CreateWindowEx (                                                     //Erstellen des Fensters        

           0,                
           ClassName,      
           titel, 
           WS_OVERLAPPED | WS_BORDER | WS_SYSMENU, 
           Window.Position.x,       
           Window.Position.y,     
           Window.Position.b,                
           Window.Position.h,                
           HWND_DESKTOP,        
           NULL,                
           Window.hThisInstance,     
           NULL                 
           );

    if (hwnd==NULL){
    into_Logbuch("Fenster konnte nicht erstellt werden!", false);
    }else{
    into_Logbuch("Fenster wurde erstellt!", true);      
    }
   
    ShowWindow (hwnd, Window.nFunsterStil);                                            //Fenster wird sichtbar gemacht

    UpdateWindow(hwnd);                                                         //Fenster wird geupdatet

               
}

//------------------------------------------------------------------------------


void tWindow::run(){ //Hier befindet sich die Nachrichtenschleife!


while (GetMessage (&messages, NULL, 0, 0))
{       
        TranslateMessage(&messages);                                            //Message Übersetzen

        DispatchMessage(&messages);                                             //Message setzen

}
     
}

//------------------------------------------------------------------------------


MSG tWindow::message(){                                                      //Gibt die Message aus

return messages;    
}

//------------------------------------------------------------------------------


Jetzt die main.cpp:

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "API.h"
#include "resource.h"

tWindow Fenster;

tInfo WindowInfo;

int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nFunsterStil)
{ 
    
    
    WindowInfo.hThisInstance=hThisInstance;
    WindowInfo.hPrevInstance=hPrevInstance;
    WindowInfo.lpszArgument=lpszArgument;
    WindowInfo.nFunsterStil=nFunsterStil;
    WindowInfo.Color=tColor(200,200,0);
    WindowInfo.Position=tVertex2D(400,300,600,480);
    
    WindowInfo.Icoid=IDI_MYICON;
    WindowInfo.Menuid=0;
    
    Fenster.creat("Test", "Willkommen", WindowInfo);    
    Fenster.run();
    
    return Fenster.message().wParam;
}





LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
        
    switch (message)                 
    {
                           
           case WM_DESTROY:
            PostQuitMessage (0);      
            break;
        default:                     
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}


Jetzt noch die resource dateien:

resource.h

C-/C++-Quelltext

1
#define IDI_MYICON 100


resource.rc

C-/C++-Quelltext

1
2
3
#include "resource.h"

IDI_MYICON ICON "Verwalter.ico"


in API.h werden alle wichtigen sachen includet!
Was ist falsch?
Warum wird das einfach ignoriert?

Gruß Flo

ChrisJ

Alter Hase

Beiträge: 487

Wohnort: Schweich

Beruf: Schüler

  • Private Nachricht senden

2

23.01.2007, 16:04

schau dir mal den befehl makeintresource() an

3

23.01.2007, 18:25

Hallo.
Jetzt klappt wieder alles!
Gruß Flo

Firefly

Alter Hase

Beiträge: 484

Wohnort: Irgendwoundnirgendwo

  • Private Nachricht senden

4

24.01.2007, 14:15

create() ? komische schreibweise... :roll:

Werbeanzeige