![]() |
CreateWindowEx, Parent + Child erzeugen
Hi,
ich habe da so meine Probleme mit CreateWindowEx. Ich kann ein Fenster erzeugen, aber ich kann kein Child dazu machen!? Variante 1:
Delphi-Quellcode:
Hier wird das Parent erzeugt, aber das Handle meines Childs bleibt 0!
Procedure CreateWindows;
var wa, wb, wc, wd: TWndClass; hWindowParent, hWindowChild : Thandle; hMyChild : THandle; begin if FindWindow('MyParent','') = 0 then begin with wa do begin lpszClassName := 'MyParent'; lpfnWndProc := @MainWndProc; Style := CS_VREDRAW or CS_HREDRAW; hInstance := hInstance; hIcon := LoadIcon(0, IDI_APPLICATION); hCursor := LoadCursor(0, IDC_ARROW); hbrBackground := (COLOR_WINDOW + 1); lpszMenuName := nil; cbClsExtra := 0; cbWndExtra := 0; end; with wb do begin lpszClassName := 'MyChild'; lpfnWndProc := @ChildWndProc; Style := CS_VREDRAW or CS_HREDRAW; hInstance := hMyChild; hIcon := LoadIcon(0, IDI_APPLICATION); hCursor := LoadCursor(0, IDC_ARROW); hbrBackground := (COLOR_WINDOW + 1); lpszMenuName := nil; cbClsExtra := 0; cbWndExtra := 0; end; Windows.RegisterClass(wa); //create main hwnd: hWindowParent := CreateWindowEx(WS_EX_TOPMOST Or WS_EX_TOOLWINDOW, 'MyParent', nil, WS_POPUP, CW_USEDEFAULT, 0, 0, 0, 0, 0, hInstance, nil); Windows.RegisterClass(wb); hWindowChild := CreateWindowEx(WS_EX_TOPMOST Or WS_EX_TOOLWINDOW, 'MyChild', nil, WS_CHILD, CW_USEDEFAULT, 0, 0, 0, hWindowParent, 0, hMyChild, nil); end; end; Komisch ist auch, wenn ich aus der Prozedure ein Function mache dann gibt mir der Parent auch immer 0!? :wiejetzt: |
Re: CreateWindowEx, Parent + Child erzeugen
Es gibt diese tolle Funktion GetLastError, mit deren Hilfe man Forenmitglieder mit einer sinnvollen Fehlermeldung beglücken kann. Mir fällt an deinem Code auf, dass du eine WndClass, aber CreateWindowEx verwendest - möglicherweise klappt es mit WndClassEx.
|
Re: CreateWindowEx, Parent + Child erzeugen
Nach erzeugen des Parents gibt es keine Fehlermeldung!
Error nach dem Versuch das Child zu erzeugen: Zitat:
|
Re: CreateWindowEx, Parent + Child erzeugen
Füge mal folgendes hinzu:
Delphi-Quellcode:
//...
zeromemory(@wa, sizeof(wa)); // <--<< with wa do begin lpszClassName := 'MyParent'; lpfnWndProc := @MainWndProc; Style := CS_VREDRAW or CS_HREDRAW; hInstance := hInstance; hIcon := LoadIcon(0, IDI_APPLICATION); hCursor := LoadCursor(0, IDC_ARROW); hbrBackground := (COLOR_WINDOW + 1); lpszMenuName := nil; cbClsExtra := 0; cbWndExtra := 0; end; zeromemory(@wb, sizeof(wb)); // <--<< with wb do begin lpszClassName := 'MyChild'; // ... |
Re: CreateWindowEx, Parent + Child erzeugen
Leider immer noch der gleiche Fehler 1407!
|
Re: CreateWindowEx, Parent + Child erzeugen
Was gibt denn RegisterClass zurück?
|
Re: CreateWindowEx, Parent + Child erzeugen
Mach es so:
Delphi-Quellcode:
das funkltioniert mit sicherheit.
Procedure CreateWindows;
var wa, wb, wc, wd: TWndClass; hWindowParent, hWindowChild : Thandle; hMyChild : THandle; begin if FindWindow('MyParent','') = 0 then begin zeromemory(@wa, sizeof(wa)); // <--<< with wa do begin lpszClassName := 'MyParent'; lpfnWndProc := @MainWndProc; Style := CS_VREDRAW or CS_HREDRAW; hInstance := hInstance; hIcon := LoadIcon(0, IDI_APPLICATION); hCursor := LoadCursor(0, IDC_ARROW); hbrBackground := (COLOR_WINDOW + 1); lpszMenuName := nil; cbClsExtra := 0; cbWndExtra := 0; end; zeromemory(@wb, sizeof(wb)); // <--<< with wb do begin lpszClassName := 'MyChild'; lpfnWndProc := @ChildWndProc; Style := CS_VREDRAW or CS_HREDRAW; hInstance := hMyChild; hIcon := LoadIcon(0, IDI_APPLICATION); hCursor := LoadCursor(0, IDC_ARROW); hbrBackground := (COLOR_BTNFACE + 1); // <--<< lpszMenuName := nil; cbClsExtra := 0; cbWndExtra := 0; end; if Windows.RegisterClass(wa) = 0 then // <--<< MessageBox(0, 'Kann Fensterklasse nicht registrieren.', 'MyParent', MB_OK); if Windows.RegisterClass(wb) = 0 then // <--<< MessageBox(0, 'Kann Fensterklasse nicht registrieren.', 'MyChild', MB_OK); //create main hwnd: hWindowParent := CreateWindowEx(WS_EX_TOPMOST Or WS_EX_TOOLWINDOW, 'MyParent', '', WS_POPUP or windows.ws_visible, // <--<< CW_USEDEFAULT, 0, 100, 100, // <--<< 0, 0, hInstance, nil); if hWindowParent <> 0 then // <--<< hWindowChild := CreateWindowEx(0, // <--<< 'MyChild', nil, WS_CHILD or ws_visible, // <--<< CW_USEDEFAULT, 0, 40, 40, // <--<< hWindowParent, 0, hMyChild, nil); end; end; |
Re: CreateWindowEx, Parent + Child erzeugen
Also RegisterClass gibt mir ein Word <> 0 zurück was ja bedeutet das es funktioniert hat, oder?
Jedoch bekomme ich mit GetLastError: Zitat:
Delphi-Quellcode:
mache bekomme ich beim ersten Error 2, beim zweiten Error 0 obwohl hWindowChild 0 ist!?
Windows.RegisterClass(wb);
Showmessage(IntToStr(GetLastError)); hWindowChild := CreateWindowEx(WS_EX_TOPMOST Or WS_EX_TOOLWINDOW, 'MyChild', nil, WS_CHILD, CW_USEDEFAULT, 0, 0, 0, hWindowParent, 0, hMyChild, nil); Showmessage(IntToStr(GetLastError)); |
Re: CreateWindowEx, Parent + Child erzeugen
GetLastError sagt nichts aus, wenn der Rückgabewert der Funktion Erfolg anzeigt.
|
Re: CreateWindowEx, Parent + Child erzeugen
@turboPASCAL:
Zitat:
CreateWindowEx Child bleibt bei 1407. Jetzt habe ich es nocheinmal in einem neuen Projekt versucht. Beim ersten mal wurde ein Parent erzeugt. Will ich es nun nocheinmal starten bleibt das Parent auf 0! Last Error auch 0. Wenn ich mein Programm beende muss ich wa oder sonst etwas anderes deregistrieren. Oder wird das Automatisch beim beenden meiner App gemacht? |
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:43 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz