Einzelnen Beitrag anzeigen

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