Einzelnen Beitrag anzeigen

Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.691 Beiträge
 
Delphi 11 Alexandria
 
#17

AW: Win32 non-Vcl ein zweites Window Modal und Umlaute Frage

  Alt 26. Mai 2018, 01:25
So hab ich es jetzt momentan, es macht genau das was ich wollte.
Vielen Dank nochmal!!

Ist DestroyWindow() das richtige Mittel um das Fenster zu schließen oder sollte da ein anderer Befehl hin?

Delphi-Quellcode:
{******************************************************************************}
{                                                                              }
{                                TwoWindows                                    }
{                                                                              }
{                    Copyright (c) 2001 Michael Puff                           }
{                            www.luckie-online.de                              }
{                           mpuff@luckie-online.de                             }
{                                                                              }
{******************************************************************************}
program TwoWindows;

{$R resource.res}

uses
  Windows,
  Messages;

const
  ClassName1 = 'Wnd1Class';
  ClassName2 = 'Wnd2Class';
  Window1Name = 'Window 1';
  Window2Name = 'Window 2';
  WindowWidth1 = 500;
  WindowHeight1 = 400;
  WindowWidth2 = 300;
  WindowHeight2 = 200;

  IDC_BUTTON1 = 1;

var
  hWnd1: DWORD;
  hWnd2: DWORD;

  hwndButton1: DWORD;

{Fensterfunktion für Fenster 1}
function Wnd1Proc(_hWnd1: HWND; uMsg: UINT; wParam: wParam; lParam: LParam):
  lresult; stdcall;
var
  x, y : integer;
begin
  Result := 0;
  case uMsg of
    WM_CREATE:
      begin
        {Fenster zentrieren}
        x := GetSystemMetrics(SM_CXSCREEN);
        y := GetSystemMetrics(SM_CYSCREEN);
        MoveWindow(_hWnd1, (x div 2) - (WindowWidth1 div 2),
          (y div 2) - (WindowHeight1 div 2),
          WindowWidth1, WindowHeight1, true);

        hwndButton1 := CreateWindowEx(0, 'BUTTON', 'Klick mich',
          WS_CHILD or WS_VISIBLE, 200, 160,
          100, 25, _hWnd1, IDC_BUTTON1, hInstance, nil);
      end;
    WM_COMMAND:
      begin
        if hiword(wParam) = BN_CLICKED then
          case loword(wParam) of
            IDC_BUTTON1:
              {Fenster 2 erzeugen und anzeigen}
              begin
                EnableWindow(_hWnd1, false);
                hwnd2 := CreateWindowEx(0, ClassName2, Window2Name,
                  WS_OVERLAPPEDWINDOW or WS_VISIBLE, 40, 10,
                  300, 200, _hWnd1, 0, hInstance, nil);
              end;
          end;
      end;
    WM_DESTROY:
      begin
        PostQuitMessage(0);
      end;
  else
    Result := DefWindowProc(_hWnd1, uMsg, wParam, lParam);
  end;
end;

{Fensterfunktion für Fenster 2}
function Wnd2Proc(_hWnd2: HWND; iMsg: UINT; wParam: wParam; lParam: LParam):
  lresult; stdcall;
var
  x, y : integer;
begin
  Result := 0;
  case iMsg of
    WM_CREATE:
      begin
        {Fenster zentrieren}
        x := GetSystemMetrics(SM_CXSCREEN);
        y := GetSystemMetrics(SM_CYSCREEN);
        MoveWindow(_hWnd2, (x div 2) - (WindowWidth2 div 2),
          (y div 2) - (WindowHeight2 div 2),
          WindowWidth2, WindowHeight2, true);
      end;
    WM_CLOSE:
      begin
        EnableWindow(hWnd1, True);
        DestroyWindow( _hWnd2 );
      end;
    else
      Result := DefWindowProc(_hWnd2, iMsg, wParam, lParam);
  end;
end;

{WindowStruktur für beide Fenster}
var
  wc: TWndClassEx = (
    cbSize : SizeOf(TWndClassEx);
    Style : CS_HREDRAW or CS_VREDRAW;
    lpfnWndProc : @Wnd1Proc; //Fensterfunktion für Fenster 1
    cbClsExtra : 0;
    cbWndExtra : 0;
    hbrBackground : COLOR_APPWORKSPACE;
    lpszMenuName : nil;
    lpszClassName : ClassName1; //Klassenname für Fenster 1
    hIconSm : 0;
  );
  msg: TMsg;

begin
  {Struktur mit Infos für Fenster 1 füllen}
  wc.hInstance := hInstance;
  wc.hIcon := LoadIcon(hInstance,MAKEINTRESOURCE(100));
  wc.hCursor := LoadCursor(0, IDC_ARROW);

  {Fenster 1 registrieren}
  RegisterClassEx(wc);

  {Fenste 1 erzeugen und hWnd1 zuweisen}
  hWnd1 := CreateWindowEx(0, ClassName1, Window1Name, WS_VISIBLE or
    WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT, CW_USEDEFAULT, WindowWidth1, WindowHeight1, 0, 0, hInstance,
    nil);

  {Struktur mit Infos für Fenster 2 füllen}
  wc.hInstance := hInstance;
  wc.lpfnWndProc := @Wnd2Proc; //Fensterfunktion für Fenster 2
  wc.hIcon := LoadIcon(0, IDI_INFORMATION);
  wc.hCursor := LoadCursor(0, IDC_ARROW);
  wc.lpszClassName := ClassName2; //Klassenname für Fenster 2

  {Fenster 2 registrieren}
  RegisterClassEx(wc);

  while GetMessage(msg,0,0,0) do
  begin
    TranslateMessage(msg);
    DispatchMessage(msg);
  end;
  ExitCode := msg.wParam;
end.
Gruß vom KodeZwerg
  Mit Zitat antworten Zitat