![]() |
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? |
Re: CreateWindowEx, Parent + Child erzeugen
Wie und wo rufst du das auf ?
Ist oder wird das eine nonVCL oder eine VCL Application ? oder hänge das Projekt mal als zip an. |
Re: CreateWindowEx, Parent + Child erzeugen
Es ist eine VCL Anwendung!
Habe es jetzt aber geschafft! Habe nochmal deinen Code komplett kopiert und neu eingefügt. Auch waren meine Funktionen wie MainWndProc nicht Global erreichbar. Ich bekomme zwar immer noch den Error 120 nach dem erzeugen des Parents, aber es werden Parent und Child erzeugt! Auch kann ich nun eine Funktion statt der Prozedur verwenden! Danke! :lol: Anscheinend hat es auch etwas mit dem zu tun:
Delphi-Quellcode:
Wenn ich Result := 0 zurück gebe werden Childs nicht erzeugt!
function ChildWndProc(hWindow: HWND; Msg: UINT;
wParam: wParam; lParam: lParam): HRESULT; stdcall; begin Result := 1; end; |
Re: CreateWindowEx, Parent + Child erzeugen
Sehe gerade noch einen Fehler:
Delphi-Quellcode:
// ...
with wb do begin lpszClassName := 'MyChild'; lpfnWndProc := @ChildWndProc; Style := CS_VREDRAW or CS_HREDRAW; //hInstance := hMyChild; // <--<< das wird nix hInstance := hInstance; |
Re: CreateWindowEx, Parent + Child erzeugen
Hi,
also das mit Zitat:
Bei RegisterClass habe ich auch hMyChild. Habe jetzt bei 4 Windows 4 verschiedene hInstance und es geht. Jedoch habe ich noch eine kleine Frage: Wie schließe ich das Fenster wieder, dass mit CreateWindowEx eruegt wurde? Habe es versucht mit FindWindow das Handle zu bekommen und mit: Zitat:
Es wird auch geschlossen, aber leider auch meine Anwendung!? |
Re: CreateWindowEx, Parent + Child erzeugen
Hallo,
ich habe zu RegisterClass und Unregister nochmal eine Frage: Ich erzeuge so mein Fenster:
Delphi-Quellcode:
Das Fenster wird erzeugt und ich bekomme Aufrufe in der angegebenen Funktion: MainWndProc.
zeromemory(@wa, sizeof(wa)); // <--<<
with wa do begin lpszClassName := 'Mein_Fenster'; lpfnWndProc := @MainWndProc; Style := CS_VREDRAW or CS_HREDRAW; hInstance := hInstance;//hMain; hIcon := 0;//LoadIcon(0, IDI_APPLICATION); hCursor := 0;//LoadCursor(0, IDC_ARROW); hbrBackground := (COLOR_WINDOW + 1); lpszMenuName := nil; cbClsExtra := 0; cbWndExtra := 0; end; Windows.RegisterClass(wa); hMainFenster := CreateWindowEx(WS_EX_TOPMOST Or WS_EX_TOOLWINDOW, wa.lpszClassName, '', WS_POPUP or windows.ws_visible, // <--<< 0, 0, 0, 0, // <--<< 0, 0, hInstance, nil); Wie beende ich das nun wieder. Ich habe es so versucht:
Delphi-Quellcode:
Jedoch scheint es so das immer noch Aufrufe in meine MainWndProc Funktion rein kommen.
if hMainFenster <> 0 then
DestroyWindow(hMainFenster); if GetClassInfo(HInstance, wa.lpszClassName, TempClass) then Windows.UnregisterClass(wa.lpszClassName,hInstance); zeromemory(@wa, sizeof(wa)); Wie kann ich das verhindern, oder ist wenn ich das Fenster schließe auch sichergestellt das die Funktion MainWndProc nicht mehr verfügbar ist? |
Re: CreateWindowEx, Parent + Child erzeugen
Zitat:
|
Re: CreateWindowEx, Parent + Child erzeugen
Weil das erzeugte "unsichtbare" Fenster für einen Shell-Ersatz dient.
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 22:01 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