AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi CreateWindowEx, Parent + Child erzeugen
Thema durchsuchen
Ansicht
Themen-Optionen

CreateWindowEx, Parent + Child erzeugen

Ein Thema von schwa226 · begonnen am 12. Jul 2009 · letzter Beitrag vom 4. Jan 2010
Antwort Antwort
Seite 1 von 2  1 2      
schwa226

Registriert seit: 4. Apr 2008
400 Beiträge
 
#1

CreateWindowEx, Parent + Child erzeugen

  Alt 12. Jul 2009, 10:29
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:
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;
Hier wird das Parent erzeugt, aber das Handle meines Childs bleibt 0!

Komisch ist auch, wenn ich aus der Prozedure ein Function mache dann gibt mir der Parent auch immer 0!?
  Mit Zitat antworten Zitat
Apollonius

Registriert seit: 16. Apr 2007
2.325 Beiträge
 
Turbo Delphi für Win32
 
#2

Re: CreateWindowEx, Parent + Child erzeugen

  Alt 12. Jul 2009, 10:35
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.
Wer erweist der Welt einen Dienst und findet ein gutes Synonym für "Pointer"?
"An interface pointer is a pointer to a pointer. This pointer points to an array of pointers, each of which points to an interface function."
  Mit Zitat antworten Zitat
schwa226

Registriert seit: 4. Apr 2008
400 Beiträge
 
#3

Re: CreateWindowEx, Parent + Child erzeugen

  Alt 12. Jul 2009, 10:41
Nach erzeugen des Parents gibt es keine Fehlermeldung!

Error nach dem Versuch das Child zu erzeugen:
Zitat:
ERROR_CANNOT_FIND_WND_CLASS
1407 (0x57F)
  Mit Zitat antworten Zitat
Benutzerbild von turboPASCAL
turboPASCAL

Registriert seit: 8. Mai 2005
Ort: Sondershausen
4.274 Beiträge
 
Delphi 6 Personal
 
#4

Re: CreateWindowEx, Parent + Child erzeugen

  Alt 12. Jul 2009, 10:45
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';
        // ...
Matti
Meine Software-Projekte - Homepage - Grüße vom Rüsselmops -Mops Mopser
  Mit Zitat antworten Zitat
schwa226

Registriert seit: 4. Apr 2008
400 Beiträge
 
#5

Re: CreateWindowEx, Parent + Child erzeugen

  Alt 12. Jul 2009, 10:49
Leider immer noch der gleiche Fehler 1407!
  Mit Zitat antworten Zitat
Apollonius

Registriert seit: 16. Apr 2007
2.325 Beiträge
 
Turbo Delphi für Win32
 
#6

Re: CreateWindowEx, Parent + Child erzeugen

  Alt 12. Jul 2009, 10:54
Was gibt denn RegisterClass zurück?
Wer erweist der Welt einen Dienst und findet ein gutes Synonym für "Pointer"?
"An interface pointer is a pointer to a pointer. This pointer points to an array of pointers, each of which points to an interface function."
  Mit Zitat antworten Zitat
Benutzerbild von turboPASCAL
turboPASCAL

Registriert seit: 8. Mai 2005
Ort: Sondershausen
4.274 Beiträge
 
Delphi 6 Personal
 
#7

Re: CreateWindowEx, Parent + Child erzeugen

  Alt 12. Jul 2009, 11:04
Mach es so:
Delphi-Quellcode:
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;
das funkltioniert mit sicherheit.
Matti
Meine Software-Projekte - Homepage - Grüße vom Rüsselmops -Mops Mopser
  Mit Zitat antworten Zitat
schwa226

Registriert seit: 4. Apr 2008
400 Beiträge
 
#8

Re: CreateWindowEx, Parent + Child erzeugen

  Alt 12. Jul 2009, 11:06
Also RegisterClass gibt mir ein Word <> 0 zurück was ja bedeutet das es funktioniert hat, oder?

Jedoch bekomme ich mit GetLastError:
Zitat:
ERROR_FILE_NOT_FOUND
2 (0x2)
Wenn ich
Delphi-Quellcode:
  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));
mache bekomme ich beim ersten Error 2, beim zweiten Error 0 obwohl hWindowChild 0 ist!?
  Mit Zitat antworten Zitat
Apollonius

Registriert seit: 16. Apr 2007
2.325 Beiträge
 
Turbo Delphi für Win32
 
#9

Re: CreateWindowEx, Parent + Child erzeugen

  Alt 12. Jul 2009, 11:09
GetLastError sagt nichts aus, wenn der Rückgabewert der Funktion Erfolg anzeigt.
Wer erweist der Welt einen Dienst und findet ein gutes Synonym für "Pointer"?
"An interface pointer is a pointer to a pointer. This pointer points to an array of pointers, each of which points to an interface function."
  Mit Zitat antworten Zitat
schwa226

Registriert seit: 4. Apr 2008
400 Beiträge
 
#10

Re: CreateWindowEx, Parent + Child erzeugen

  Alt 12. Jul 2009, 11:13
@turboPASCAL:

Zitat:
ERROR_CALL_NOT_IMPLEMENTED
120 (0x78)
Das bekomme ich nach dem CreateWindowEx Parent.
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?
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 2  1 2      


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:19 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz