Fenster verschwindet plötzlich nach definition einer ID
-
Müßte aber eigentlich so funktionieren. Poste mal den ganzen Code.
-
Code:
#include <windows.h> #define IDB 4711 /* Declare Windows procedure */ LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); HWND hWnd; HWND hAboutDialog; /* Make the class name into a global variable */ 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; /* Catch double-clicks */ wincl.cbSize = sizeof (WNDCLASSEX); /* Use default icon and mouse-pointer */ wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); 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 Windows's default color as the background of the window */ wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND; /* 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 */ "test", /* Title Text */ WS_OVERLAPPED , /* default window */ GetSystemMetrics(SM_CXSCREEN)/4, //X-Position GetSystemMetrics(SM_CXSCREEN)/4, //Y-Position 600, /* The programs width */ 200, /* 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) { static HWND hButtonAbout; static HWND hButtonExit; static HWND hButtonGenerate; static HWND hStatic1; switch (message) { case WM_CREATE: { // Creates the Exit-Button hButtonExit = CreateWindow( "button", "&Exit", WS_CHILD | WS_VISIBLE | BS_VCENTER | BS_FLAT , 492, 153, 100, 20, hwnd, NULL, ((LPCREATESTRUCT) lParam) -> hInstance, NULL); // Set the font to windows standart font for Exit-Button SendMessage(hButtonExit, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), MAKELONG(TRUE, 0)); // Creates the Exit-Button hButtonAbout = CreateWindow( "button", "&About", WS_CHILD | WS_VISIBLE | BS_VCENTER | BS_FLAT , 0, 153, 100, 20, hwnd, NULL, ((LPCREATESTRUCT) lParam) -> hInstance, NULL); // Set the font to windows standart font for About-Button SendMessage(hButtonAbout, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), MAKELONG(TRUE, 0)); // Creates the Generate-Button hButtonGenerate = CreateWindow( "button", "&Generate", WS_CHILD | WS_VISIBLE | BS_VCENTER |BS_FLAT , 246, 153, 100, 20, hwnd, (HMENU) IDB, ((LPCREATESTRUCT) lParam) -> hInstance, NULL); // Set the font to windows standart font for Generte-Button SendMessage(hButtonGenerate, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), MAKELONG(TRUE, 0)); // Creates the Static1-Control hStatic1 = CreateWindow( "static", "Serial invalid, shmocks !", WS_CHILD | WS_VISIBLE | BS_CENTER , 20, 20, 170, 20, hwnd, NULL, ((LPCREATESTRUCT) lParam) -> hInstance, NULL); // Set the font to windows standart font for Static1-Button SendMessage(hStatic1, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), MAKELONG(TRUE, 0)); return 0; } case WM_COMMAND: { if (lParam == (LPARAM)hButtonExit) { if (HIWORD(wParam) == BN_CLICKED) SendMessage(hwnd, WM_CLOSE, 0, 0); } if (lParam == (LPARAM)hButtonAbout) { if (HIWORD(wParam) == BN_CLICKED) { MessageBoxA(hWnd,"test","toll",TRUE); } } break; } SendMessage(hButtonGenerate, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), MAKELONG(TRUE, 0)); case WM_CLOSE: { PostQuitMessage(0); return 0; } case WM_DESTROY: PostQuitMessage (0); break; default: return DefWindowProc (hwnd, message, wParam, lParam); } }
Momentan bin ich noch nicht weiter wie hier. Ich habs wieder gelöscht, da es nicht klappte. Kannst du mir sagen wie ich mit dem About Button ein neuen Dialog öffne, bzw ihn erstmal erstelle ?
Wär nett,
OH
-
Momentan bin ich noch nicht weiter wie hier. Ich habs wieder gelöscht, da es nicht klappte. Kannst du mir sagen wie ich mit dem About Button ein neuen Dialog öffne, bzw ihn erstmal erstelle ?
Wie immer. Neue Fensterklasse registrieren (oder alte benutzen) und einfach per CreateWindow ein neues Fenster davon erstellen.
-
Na ja, aber da dein About-Dialog nur ne MessageBox ist, geht das natürlich nicht. Wann soll denn das neue Fenster geöffnet werden? Oder soll das neue Fenster der About-Dialog sein?
-
Ich hab jetzt einfach mal was kopiert, stimmt so bestimmt nicht. Nur vom Prinzip her, würde das gehen, das ich so einen neuen Dialog erstelle ?
#include <windows.h> #define IDB 4711 /* Declare Windows procedure */ LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); HWND hWnd; HWND hAboutDialog; /* Make the class name into a global variable */ 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; /* Catch double-clicks */ wincl.cbSize = sizeof (WNDCLASSEX); /* Use default icon and mouse-pointer */ wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); 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 Windows's default color as the background of the window */ wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND; /* 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 */ "test", /* Title Text */ WS_OVERLAPPED , /* default window */ GetSystemMetrics(SM_CXSCREEN)/4, //X-Position GetSystemMetrics(SM_CXSCREEN)/4, //Y-Position 600, /* The programs width */ 200, /* 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; } int WINAPI WinAbout (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; /* Catch double-clicks */ wincl.cbSize = sizeof (WNDCLASSEX); /* Use default icon and mouse-pointer */ wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); 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 Windows's default color as the background of the window */ wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND; /* 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 */ "test2", /* Title Text */ WS_OVERLAPPED , /* default window */ GetSystemMetrics(SM_CXSCREEN)/4, //X-Position GetSystemMetrics(SM_CXSCREEN)/4, //Y-Position 600, /* The programs width */ 200, /* 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) { static HWND hButtonAbout; static HWND hButtonExit; static HWND hButtonGenerate; static HWND hStatic1; switch (message) { case WM_CREATE: { // Creates the Exit-Button hButtonExit = CreateWindow( "button", "&Exit", WS_CHILD | WS_VISIBLE | BS_VCENTER | BS_FLAT , 492, 153, 100, 20, hwnd, NULL, ((LPCREATESTRUCT) lParam) -> hInstance, NULL); // Set the font to windows standart font for Exit-Button SendMessage(hButtonExit, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), MAKELONG(TRUE, 0)); // Creates the Exit-Button hButtonAbout = CreateWindow( "button", "&About", WS_CHILD | WS_VISIBLE | BS_VCENTER | BS_FLAT , 0, 153, 100, 20, hwnd, NULL, ((LPCREATESTRUCT) lParam) -> hInstance, NULL); // Set the font to windows standart font for About-Button SendMessage(hButtonAbout, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), MAKELONG(TRUE, 0)); // Creates the Generate-Button hButtonGenerate = CreateWindow( "button", "&Generate", WS_CHILD | WS_VISIBLE | BS_VCENTER |BS_FLAT , 246, 153, 100, 20, hwnd, (HMENU) IDB, ((LPCREATESTRUCT) lParam) -> hInstance, NULL); // Set the font to windows standart font for Generte-Button SendMessage(hButtonGenerate, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), MAKELONG(TRUE, 0)); // Creates the Static1-Control hStatic1 = CreateWindow( "static", "Serial invalid, shmocks !", WS_CHILD | WS_VISIBLE | BS_CENTER , 20, 20, 170, 20, hwnd, NULL, ((LPCREATESTRUCT) lParam) -> hInstance, NULL); // Set the font to windows standart font for Static1-Button SendMessage(hStatic1, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), MAKELONG(TRUE, 0)); return 0; } case WM_COMMAND: { if (lParam == (LPARAM)hButtonExit) { if (HIWORD(wParam) == BN_CLICKED) SendMessage(hwnd, WM_CLOSE, 0, 0); } if (lParam == (LPARAM)hButtonAbout) { if (HIWORD(wParam) == BN_CLICKED) { MessageBoxA(hWnd,"test","toll",TRUE); } } break; } SendMessage(hButtonGenerate, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), MAKELONG(TRUE, 0)); case WM_CLOSE: { PostQuitMessage(0); return 0; } case WM_DESTROY: PostQuitMessage (0); break; default: return DefWindowProc (hwnd, message, wParam, lParam); } }
-
Ja ich will ein About Fenster erstellen, soll aber keine MessageBox sein sondern ein Fenster in dem ich noch was reinpacken kann...
-
Einfach anstatt der MessageBox das Fenster deiner Wahl zu erstellen. So z.B., da wird jetzt das Hauptfenster nochmal erstellt, beim Klick auf den About-Button.
#include <windows.h> #define IDB 4711 /* Declare Windows procedure */ LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); HWND hWnd; HWND hAboutDialog; /* Make the class name into a global variable */ 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; /* Catch double-clicks */ wincl.cbSize = sizeof (WNDCLASSEX); /* Use default icon and mouse-pointer */ wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); 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 Windows's default color as the background of the window */ wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND; /* 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 */ "test", /* Title Text */ WS_OVERLAPPED , /* default window */ GetSystemMetrics(SM_CXSCREEN)/4, //X-Position GetSystemMetrics(SM_CXSCREEN)/4, //Y-Position 600, /* The programs width */ 200, /* 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) { static HWND hButtonAbout; static HWND hButtonExit; static HWND hButtonGenerate; static HWND hStatic1; switch (message) { case WM_CREATE: { // Creates the Exit-Button hButtonExit = CreateWindow( "button", "&Exit", WS_CHILD | WS_VISIBLE | BS_VCENTER | BS_FLAT , 492, 153, 100, 20, hwnd, NULL, ((LPCREATESTRUCT) lParam) -> hInstance, NULL); // Set the font to windows standart font for Exit-Button SendMessage(hButtonExit, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), MAKELONG(TRUE, 0)); // Creates the Exit-Button hButtonAbout = CreateWindow( "button", "&About", WS_CHILD | WS_VISIBLE | BS_VCENTER | BS_FLAT , 0, 153, 100, 20, hwnd, NULL, ((LPCREATESTRUCT) lParam) -> hInstance, NULL); // Set the font to windows standart font for About-Button SendMessage(hButtonAbout, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), MAKELONG(TRUE, 0)); // Creates the Generate-Button hButtonGenerate = CreateWindow( "button", "&Generate", WS_CHILD | WS_VISIBLE | BS_VCENTER |BS_FLAT , 246, 153, 100, 20, hwnd, (HMENU) IDB, ((LPCREATESTRUCT) lParam) -> hInstance, NULL); // Set the font to windows standart font for Generte-Button SendMessage(hButtonGenerate, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), MAKELONG(TRUE, 0)); // Creates the Static1-Control hStatic1 = CreateWindow( "static", "Serial invalid, shmocks !", WS_CHILD | WS_VISIBLE | BS_CENTER , 20, 20, 170, 20, hwnd, NULL, ((LPCREATESTRUCT) lParam) -> hInstance, NULL); // Set the font to windows standart font for Static1-Button SendMessage(hStatic1, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), MAKELONG(TRUE, 0)); return 0; } case WM_COMMAND: { if (lParam == (LPARAM)hButtonExit) { if (HIWORD(wParam) == BN_CLICKED) SendMessage(hwnd, WM_CLOSE, 0, 0); } if (lParam == (LPARAM)hButtonAbout) { if (HIWORD(wParam) == BN_CLICKED) { CreateWindowEx ( 0, /* Extended possibilites for variation */ szClassName, /* Classname */ "test", /* Title Text */ WS_OVERLAPPEDWINDOW | WS_VISIBLE , /* default window */ 20, //X-Position 20, //Y-Position 100, /* The programs width */ 100, /* and height in pixels */ hWnd, /* The window is a child-window to desktop */ NULL, /* No menu */ GetModuleHandle(NULL), /* Program Instance handler */ NULL /* No Window Creation data */ ); } } break; } SendMessage(hButtonGenerate, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), MAKELONG(TRUE, 0)); case WM_CLOSE: { PostQuitMessage(0); return 0; } case WM_DESTROY: PostQuitMessage (0); break; default: return DefWindowProc (hwnd, message, wParam, lParam); } }
-
Jo super das klappt schon, obwohl ich dachte das ich das schonmal probiert hätte, hmm
Und wie mach ich nun ein komplett neues Fenster auf ?
-
Machst dir einfach eine neue Fensterklasse fertig mit neue WndProc. Also WNDCLASSEX Struktur ausfüllen, Registrieren (RegisterClassEX) und dann kannst du auch schon ein neues Fenster davon erstellen.
-
Na wenn's weiter nichts ist !
Ich glaub ich muss mir das nochmal genauer anschauen, irgendwie steig ich noch nicht ganz durch.
Trotzdem danke,
OHPen
-
Hol dir mal das Buch hier!
http://www.amazon.de/exec/obidos/ASIN/3860634879/qid=1042414564/sr=2-1/ref=sr_aps_prod_1_1/302-5666634-0055254
-
Kannst du mir sonst noch Bücher empfehlen ?
Das hab ich morgen aber in englishGruss
-
Ne, das reicht an Büchern für den Anfang.
Das hab ich morgen aber in english
Ebookzzzzzzzz?
-
Naja, was soll man machen
Die Zeiten sind hart !Bis denne
-
Ja, ist nur scheiße das man am Bildschirm schlecht lange Texte lesen kann. Also ich könnte so nicht lernen. Aber wenn du damit klarkommst. *g*
-
Ich drück mir das fein aus Doppelseitig und dann hab ich auch mein Buch
LOL
-
LOL, wenn das billiger kommt.
Lädst du das als chm Hilfedatei? Wenn ja, wie kann man da alles aufeinmal ausdrucken?
-
Hope es is PDF, aber ich weiß es nicht *.RAR
Muss mich wohl überraschen lassen. Hoffentlich kein HTML, grrr.
-
Meines Wissens treibt sich das nur als CHM Datei im Netz rum. Also für das Programm "HTML Help". Aber hab es ausprobiert - ist ganz easy auszudrucken. Aber viele Seiten.
-
Tausend gehn schon
Oder ich machs einfach in der FH.