this slowpoke moves

Post Quit Message Form Template

{******************************************************************************}
{                                                                              }
{ - erzeugen eines Fensterns ohne Resourcen-Datei                              }
{ - zentrieren des Fensters auf dem Desktop                                    }
{ - Zuweisen eines Icons aus einer Resourcen-Datei                             }
{ - Nachrichtenverarbeitung                                                    }
{ - WM_DESTROY, PostQuitMessage(), WM_QUIT                                     }
{ - WM_LBUTTONDOWN                                                             }
{ - wvsprintf(), lstrcat(), TextOut                                            }
{                                                                              }
{******************************************************************************}
program TAB_ALT_Fix;

uses
  Windows,
  Messages;

const
  ClassName = 'WndClass';
  AppName = 'TAB/ALT-Fix (Demo)';
  WindowWidth = 500;
  WindowHeight = 350;

  IDC_CLOSE = 1;

var
  hwndMain: DWORD;
  hClose: DWORD;

function WndProc(hWnd: 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(hWnd, (x div 2) - (WindowWidth div 2),
          (y div 2) - (WindowHeight div 2),
          WindowWidth, WindowHeight, true);

        { Controls erstellen }
        hClose := CreateWindowEx(WS_EX_CLIENTEDGE, 'BUTTON', '&Schließen',
          WS_VISIBLE or WS_CHILD or WS_TABSTOP,
          WindowWidth-115, WindowHeight-60, 100, 25,
          hWnd, IDC_CLOSE, hInstance, nil);

        CreateWindowEx(WS_EX_CLIENTEDGE, 'BUTTON', 'Button 1',
          WS_VISIBLE or WS_CHILD or WS_TABSTOP, 10, 10, 100, 25,
          hWnd, 0, hInstance, nil);
        CreateWindowEx(WS_EX_CLIENTEDGE, 'BUTTON', 'Button 2',
          WS_VISIBLE or WS_CHILD or WS_TABSTOP, 10, 45, 100, 25,
          hWnd, 0, hInstance, nil);
        CreateWindowEx(WS_EX_CLIENTEDGE, 'BUTTON', 'Button 3',
          WS_VISIBLE or WS_CHILD or WS_TABSTOP, 10, 75, 100, 25,
          hWnd, 0, hInstance, nil);

        SetFocus(hClose);
      end;
    WM_DESTROY:
      PostQuitMessage(0);
    WM_COMMAND:
      if hiword(wParam) = BN_CLICKED then
        case loword(wParam) of
          IDC_CLOSE:
            SendMessage(hwnd, WM_DESTROY, 0, 0);
        end;
    WM_SIZE:
      MoveWindow(hClose, LoWord(lParam)-115, HiWord(lParam)-40, 100, 25, true)
    else
      Result := DefWindowProc(hWnd, uMsg, wParam, lParam);
  end;
end;

var
  wc: TWndClassEx = (
    cbSize          : SizeOf(TWndClassEx);
    Style           : CS_HREDRAW or CS_VREDRAW;
    lpfnWndProc     : @WndProc;
    cbClsExtra      : 0;
    cbWndExtra      : 0;
    hbrBackground   : COLOR_APPWORKSPACE;
    lpszMenuName    : nil;
    lpszClassName   : ClassName;
    hIconSm         : 0;
  );
  msg: TMsg;
begin
  {Klasse registrieren}
  wc.hInstance  := hInstance;
  wc.hIcon      := LoadIcon(hInstance, MAKEINTRESOURCE(100));
  wc.hCursor    := LoadCursor(0, IDC_ARROW);
  RegisterClassEx(wc);

  {Fenster erzeugen}
  hwndMain := CreateWindowEx(0, ClassName, AppName, WS_CAPTION or WS_VISIBLE or WS_SYSMENU,
    integer(CW_USEDEFAULT),integer(CW_USEDEFAULT),WindowWidth,
    WindowHeight, 0, 0, hInstance, nil);

  while GetMessage(msg,0,0,0) do
    begin
      if not(IsDialogMessage(hWndMain,msg)) then
        begin
          TranslateMessage(msg);
          DispatchMessage(msg);
        end;
    end;

  ExitCode := msg.wParam;
end.

Keine Kommentare:

Kommentar veröffentlichen

Beliebte Posts

Translate