Oppure

Loading
28/03/10 20:03
Ocentral
ho trovato{$APPTYPE GUI}
{$MODE DELPHI}
program WinHello;

uses
Strings, Windows;

const
AppName = 'Triplo di un numero';

var
bottone:hwnd;
edit1,edit2:hwnd;

//qui si controllano tutti gli eventi della finestra
function WindowProc(Window: HWnd; AMessage: UINT; WParam : WPARAM;
LParam: LPARAM): LRESULT; stdcall; export;

var
dc : hdc;//e' il device context: nel device context si fanno tutti i nostri disegni
//riguarda la grafica
ps : paintstruct;//e' un record per il disegno
r : rect;

begin
WindowProc := 0;

case AMessage of//amsesage e' un numero che ci da gli eventi che accadono
wm_paint:
begin
dc:=BeginPaint(Window,@ps);
GetClientRect(Window,@r);
DrawText(dc,'Introduci un numero intero',-1,@r,
DT_SINGLELINE );
EndPaint(Window,ps);
Exit;
end;
wm_Destroy:
begin
PostQuitMessage(0);
Exit;
end;
wm_Command : begin
if lParam = Bottone then MessageBeep (mb_OK);
if lparam = edit1 then edit;
end;
end;

WindowProc := DefWindowProc(Window, AMessage, WParam, LParam);
end;

//registrazione delle caratteristiche della finestra
function WinRegister: Boolean;
var
WindowClass: WndClass;
begin
WindowClass.Style := cs_hRedraw or cs_vRedraw;
WindowClass.lpfnWndProc := WndProc(@WindowProc);
WindowClass.cbClsExtra := 0;
WindowClass.cbWndExtra := 0;
WindowClass.hInstance := system.MainInstance;
WindowClass.hIcon := LoadIcon(0, idi_Application);
WindowClass.hCursor := LoadCursor(0, idc_Arrow);
WindowClass.hbrBackground := GetStockObject(GRAY_BRUSH);
WindowClass.lpszMenuName := nil;
WindowClass.lpszClassName := AppName;

Result := RegisterClass(WindowClass) <> 0;
end;

//crea la windows class. questa e' una classe che contiene le caratteristiche della
//nostra finestra
function WinCreate: HWnd;
var
hWindow: HWnd;
begin
hWindow := CreateWindow(AppName, 'Questo programma calcola il triplo di un numero dato',
ws_OverlappedWindow, cw_UseDefault, cw_UseDefault,
cw_UseDefault, cw_UseDefault, 0, 0, system.MainInstance, nil);

if hWindow <> 0 then begin
ShowWindow(hWindow, CmdShow);
ShowWindow(hWindow, SW_SHOW);
UpdateWindow(hWindow);
end;

Result := hWindow;
end;


var
AMessage: Msg;
hWindow: HWnd;

begin
if not WinRegister then begin
MessageBox(0, 'Register failed', nil, mb_Ok);
Exit;
end;
hWindow := WinCreate;
bottone:=CreateWindow ('Button', 'Calcola',
WS_VISIBLE or WS_CHILD or BS_PUSHLIKE ,
10, 80, 50, 30, hWindow, 0, hInstance, nil);
edit1:=CreateWindow ('Edit', '',
WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or ES_NUMBER ,
10, 50, 55, 16, hWindow, 0, hInstance, nil);
edit2:=CreateWindow ('Edit', '',
WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or ES_NUMBER ,
80, 50, 55, 16, hWindow, 0, hInstance, nil);
if longint(hWindow) = 0 then begin
MessageBox(0, 'WinCreate failed', nil, mb_Ok);
Exit;
end;

while GetMessage(@AMessage, 0, 0, 0) do begin
TranslateMessage(AMessage);
DispatchMessage(AMessage);
end;
Halt(AMessage.wParam);
end.


Ma non so come prendere il valore di edit
aaa
31/03/10 10:46
Phi
Questo programma funziona.
Attenzione: l'ho compilato usando Free Pascal e su Turbo Pascal non dovrebbe funzionare.


program triplo;
{$APPTYPE GUI}

uses Windows, graph;

var
bottone:hwnd;
edit1,edit2:hwnd;
scritto : boolean;

var P :pchar;
procedure calcola;
var l:longint;
    s:string;
    v, ris:real;
begin
bar(250,250,410,290);
l := getwindowtextlength(edit1);
if l = 0 then exit;
getmem(P,l);
getwindowtext(edit1,P,l+1);
s := P;
val(s,v,l);
ris := 3*v;
str(v:10:0,s);
outtextxy(250,250,concat('3 x ',s));
str(ris:10:0,s);
outtextxy(290,265,'=');
outtextxy(250,280,s);
l := length(s);
s[0]:=#32;s[l+1]:=#0;
setwindowtext(edit2,@s);
scritto := true;
end;


function command(Window:HWnd; AMessage:UINT; WParam:WPARAM; LParam:LPARAM): LRESULT;stdcall;
begin
if lParam = Bottone then calcola;
command := 0;
end;

procedure inizio;
begin
bottone:=CreateWindow ('Button', 'Calcola',WS_VISIBLE or WS_CHILD or BS_PUSHLIKE,270, 160, 100, 30, Graphwindow, 0, hInstance, nil);
edit1:=CreateWindow ('Edit', '', WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or ES_NUMBER, 80, 80, 140, 20, GraphWindow, 0, hInstance, nil);
edit2:=CreateWindow ('Edit', '',  WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or ES_NUMBER or es_readonly, 420, 80, 140, 20, GraphWindow, 0, hInstance, nil);
end;

const
G1 : smallint = VGA;
G2 : smallint = 1;

begin
windowtitle := 'Triplo';
ongraphwindowcreation := @inizio;
commandmessagehandler := @command;
initgraph(G1,G2,'');
outtextxy(160,5,  'Inserisci il numero da multiplicare per 3');
outtextxy(210,15, 'poi schiacca il tasto "CALCOLA"');
outtextxy(280,85, 'x 3   =');
setfillstyle(0,0);
while iswindow(Graphwindow) do begin
 sleep(100);
 if scritto then begin
  sleep(2000);
  bar(250,250,430,290);
  scritto := false;
 end;
end;
end.


aaa