Childwindow wird nicht erzeugt
-
Ich möchte einfach nur ein ChildWindow erzeugen. Aaber, nichtmal die WM_CREATE-Nachricht wird abgearbeitet. ergo wür ich mal sagen, dass das Fenster garnicht erstellt wird, aber warum??
#include <windows.h> #include "winprocedures.h" char MainClassName[ ] = "WorldGenerator"; /* Declare Windows procedure */ /* Make the class name into a global variable */ 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 Main Window structure */ wincl.hInstance = hThisInstance; wincl.lpszClassName = MainClassName; wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */ wincl.style = CS_DBLCLKS; /* Catch double-clicks */ wincl.cbSize = sizeof (WNDCLASSEX); 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 */ wincl.hbrBackground = (HBRUSH) (COLOR_WINDOW); /* 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 */ MainClassName, /* Classname */ "World Generator v1.0", /* Title Text */ WS_OVERLAPPEDWINDOW|WS_HSCROLL|WS_VSCROLL, /* default window */ CW_USEDEFAULT, /* Windows decides the position */ CW_USEDEFAULT, /* where the window ends up on the screen */ CW_USEDEFAULT, /* The programs width */ CW_USEDEFAULT, /* 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; }
so, nun erstelle ich in der WindowProcedure ein Childwindow - oder scheinar eher nicht
#include "winprocedures.h" #include "Button/c_mybutton.h" /* This function is called by the Windows function DispatchMessage() */ HWND ToolDialog; char ToolClassName[ ] = "ToolWindow"; LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { WNDCLASSEX wincl; switch (message) /* handle the messages */ { case WM_CREATE: /* Register the child window */ wincl.hInstance = hThisInstance; wincl.lpszClassName = ToolClassName; wincl.lpfnWndProc = ToolProc; /* This function is called by windows */ wincl.cbSize = sizeof (WNDCLASSEX); 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 */ wincl.hbrBackground = (HBRUSH) (COLOR_WINDOW); /* Register the window class, and if it fails quit the program */ if (!RegisterClassEx (&wincl)) return 0; ToolDialog = CreateWindowEx ( 0, /* Extended possibilites for variation */ ToolClassName, /* Classname */ "Toolbox", /* Title Text */ WS_CHILDWINDOW|WS_VISIBLE, /* default window */ CW_USEDEFAULT, /* Windows decides the position */ CW_USEDEFAULT, /* where the window ends up on the screen */ 50, /* The programs width */ 100, /* and height in pixels */ hwnd, /* The window is a child-window to Main Window */ NULL, /* No menu */ hThisInstance, /* Program Instance handler */ NULL /* No Window Creation data */ ); break; case WM_DESTROY: DestroyWindow(ToolDialog); PostQuitMessage (0); /* send a WM_QUIT to the message queue */ break; default: /* for messages that we don't deal with */ return DefWindowProc (hwnd, message, wParam, lParam); } return 0; } LRESULT CALLBACK ToolProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static C_MyButton *Wasser, *Ebene, *Berg; switch (message) /* handle the messages */ { case WM_CREATE: break; case WM_DESTROY: break; default: /* for messages that we don't deal with */ return FALSE; } return TRUE; }
der Vollständigkeit halber auch noch die passende Headerdatei dazu:
#ifndef WINPROCEDURES_H #define WINPROCEDURES_H #include <windows.h> LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK ToolProc (HWND, UINT, WPARAM, LPARAM); #endif
C_MyButton.h ist eine selbstgeschriebene Klasse für Buttons, hat aber noch keine Bedeutung..
Nun aber die Frage: Wo ist mein Fehler (bitte nur auf das Prog bezogen)
cYa && thx
DjR
-
Ich kann mir nicht vorstellen, dass "hThisInstance" einen gültigen Wert hat.
Denk mal nach..
-
ups. die zeile gehört da auch nicht rein.
habe den Code aus einem anderen Post (in einer anderen Sparte) zusammengestellt und nach dem Gedächtnis zusammengeschaufelt und umgestellt, da ich hier auf Arbeit nicht an meinen Rechner zuhause komme..cYa
DjR
-
Die Lösung is eigentlich ganz einfach
ersetz mal return true; in deine toolbarproc gegen
return DefWindowProc (hwnd, message, wParam, lParam);mfg
-
auch das funzt net
-
Was machst du denn da für ein scheiss Code?
default: /* for messages that we don't deal with */ return DefWindowProc(...); } return 0; }
Kannst du nicht dein Code vernünftig kürzen für deine Posts? Warum stehen da ein leeres WM_CREATE und WM_DESTROY drin?
-
1. Ich bin ja nicht so umständlich und schreib mir die Windowdeklarationen immer selber. Ich benutze Templates und ändere das, was ich brauch!
2. Wenn Du mitliest, dann weißt du, dass ich diesen Post aus einem anderen zurechtgeschneidert habe, bei dem es aber um etwas anderes ging. Ein paar Dinge hab ich geändert, einiges aber vergessen. Entschuldige bitte, dass ich neben dem boarden auch noch ARBEITE!
kann ich auch.
-
1. Das hier ändern!
LRESULT CALLBACK ToolProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_CREATE: break; case WM_DESTROY: break; default: // hier nicht!!! FALSE zurückgeben; return DefWindowProc (hwnd, message, wParam, lParam); } return TRUE; }
2. Am Anfang die WNDCLASSEX Struktur nullen, oder alle Elemente daraus füllen.
3. Grau auf grau fällt nicht besonders auf, also spendier deinem Child ne Border oder sowas.
(Am besten machst du danach noch ein Posting im Programmierfehler-Thread im Rund um... *g*)
-
umpf!
klar, jetzt weiß ich erst, was gemeint war:D
Sorry Snaky,etc., hab heute echt nicht meinen besten Tag..
Naja, ist wohl eher nicht mein Monat..
Wie auch immer, jetzt tuter's .
-
jo np ohh ich seh grad mein fehler
aber haben ja schon andere bemerkt
aber warum gleich diese bösen smileys???? mein gott es gibt nunma tage wo man aufn schlauch steht...........
Kein mensch is perfekt ich hab diesen fehler selber oft genug gemacht aber solche smileys sind nu eht unpassend und dann noch nicht ma einen namen angeben ......
naja bin ja selber nichma registriert
mfg