Delphi - menor programa possivel usando 1 form 9k em Delphi 7 |
Top Previous Next |
|
program MenorProjeto;
uses Windows, Messages {, MMSystem};
const AppName: pChar = 'HelloWin';
function WindowProc(Window:HWnd; AMessage, WParam,LParam:LongInt): LongInt; StdCall; Export; var h : hdc; ps : tPaintStruct; r : tRect; begin Result := 0; case AMessage of WM_Create: begin // PlaySound('C:\WINDOWS\MEDIA\Musica Windows Start.wav', 0, Snd_FileName or Snd_Async); Exit; end; WM_Paint : begin h := BeginPaint(Window, Ps); GetClientRect(Window, r); DrawText(h, 'Hello Windows 95!', -1, r, DT_SingleLine or DT_Center or DT_VCenter); EndPaint(Window, ps); Exit; end; WM_Destroy:begin PostQuitMessage(0); Exit; end; end; Result := DefWindowProc(Window, AMessage, WParam, LParam); end;
function WinRegister: Boolean; var WindowClass: TWndClass; begin {WindowClass.cbSize := sizeof(WindowClass);} WindowClass.Style := cs_HRedraw or cs_VRedraw; WindowClass.lpfnWndProc := @WindowProc; WindowClass.cbClsExtra := 0; WindowClass.cbWndExtra := 0; WindowClass.hInstance := HInstance; WindowClass.hIcon := LoadIcon(0, idi_Application); WindowClass.hCursor := LoadCursor(0, idc_Arrow); WindowClass.hbrBackground := HBrush(GetStockObject(White_Brush)); WindowClass.lpszMenuName := NIL; WindowClass.lpszClassName := AppName; Result := RegisterClass(WindowClass)<>0; end;
function WinCreate: HWnd; var HWindow:HWnd; begin hWindow := CreateWindow(AppName, 'The Hello Program', WS_OverlappedWindow, CW_UseDefault, CW_UseDefault, CW_UseDefault, CW_UseDefault, 0, 0, HInstance, nil); If hWindow<>0 then begin ShowWindow(hWindow, CmdShow); UpdateWindow(hWindow); end; Result := hWindow; end;
var AMessage: TMsg; hWindow: HWnd; begin If not WinRegister then begin MessageBox(0, 'Register Failed', NIL, mb_Ok); Exit; end; hWindow := WinCreate; If hWindow = 0 then begin MessageBox(0, 'Register Failed', NIL, mb_Ok); Exit; end; while GetMessage(AMessage, 0, 0, 0) do begin TranslateMessage(AMessage); DispatchMessage(AMessage); end; Halt(AMessage.WParam); End. |