craig_capel
asked on
Why does this code not work...
program smallexe;
uses
Windows,
Messages;
Var
WindowHandle: HWND;
BH,EH: Integer;
const
MULTIEDIT1 = 1;
EditBox2 = 2;
Button = 3;
function WinProc(hWnd,uMsg,wPar,lPa r:Integer) :Integer; stdcall;
begin
//Writeln(Umsg,' ',wpar,' ',lpar);
case uMsg of
EditBox2:
Begin
If Wpar=Ord('X') Then
PostQuitMessage(0);
End;
Button:
Begin
Writeln(Umsg,' ',wpar,' ',lpar);
End;
WM_CLOSE:
begin
PostQuitMessage(0);
Result:=0;
End;
else Result:=DefWindowProc(hWnd ,uMsg,wPar ,lPar);
end;
end;
var
hWin: Integer;
Msg: TMsg;
wClass: TWndClass;
Active: Boolean=True;
begin
with wClass do
begin
style:=0;
lpfnWndProc:=@WinProc;
cbClsExtra:=0;
cbWndExtra:=0;
hInstance:=hInstance;
hIcon:=LoadIcon(hInstance, 'MAINICON' );
hCursor:=LoadCursor(0,IDC_ ARROW);
hbrBackground:=COLOR_BTNFA CE+1;
lpszMenuName:=nil;
lpszClassName:='someclass' ;
end;
RegisterClass(wClass);
hWin:=CreateWindow('somecl ass','form 1',
WS_VISIBLE or WS_THICKFRAME or WS_OVERLAPPED or WS_SYSMENU,
0,0,380,340,0,0,hInstance, nil);
EH:=CreateWindow('EDIT','E xample', ES_AUTOHSCROLL or WS_Border or WS_Child or WS_Visible,50,50,200,20,Hw in,EditBox 2,Hinstanc e,Nil);
//Create Window, EditBox2 is what to look for...
BH:=CreateWindow('BUTTON', 'OK',BS_PU SHBUTTON Or WS_VISIBLE OR WS_CHILD, 100,100,50,50, Hwin, Button, 0,Nil);
while Active do
begin
if PeekMessage(Msg,hWin,0,0,P M_NOREMOVE ) then
begin
Active:=Longint(GetMessage (Msg,hWin, 0,0))<>0;
TranslateMessage(Msg);
DispatchMessage(Msg);
end else WaitMessage;
end;
end.
When you press shift X it should close down the application but it does not, it should :P
Thanks in Advance...
uses
Windows,
Messages;
Var
WindowHandle: HWND;
BH,EH: Integer;
const
MULTIEDIT1 = 1;
EditBox2 = 2;
Button = 3;
function WinProc(hWnd,uMsg,wPar,lPa
begin
//Writeln(Umsg,' ',wpar,' ',lpar);
case uMsg of
EditBox2:
Begin
If Wpar=Ord('X') Then
PostQuitMessage(0);
End;
Button:
Begin
Writeln(Umsg,' ',wpar,' ',lpar);
End;
WM_CLOSE:
begin
PostQuitMessage(0);
Result:=0;
End;
else Result:=DefWindowProc(hWnd
end;
end;
var
hWin: Integer;
Msg: TMsg;
wClass: TWndClass;
Active: Boolean=True;
begin
with wClass do
begin
style:=0;
lpfnWndProc:=@WinProc;
cbClsExtra:=0;
cbWndExtra:=0;
hInstance:=hInstance;
hIcon:=LoadIcon(hInstance,
hCursor:=LoadCursor(0,IDC_
hbrBackground:=COLOR_BTNFA
lpszMenuName:=nil;
lpszClassName:='someclass'
end;
RegisterClass(wClass);
hWin:=CreateWindow('somecl
WS_VISIBLE or WS_THICKFRAME or WS_OVERLAPPED or WS_SYSMENU,
0,0,380,340,0,0,hInstance,
EH:=CreateWindow('EDIT','E
//Create Window, EditBox2 is what to look for...
BH:=CreateWindow('BUTTON',
while Active do
begin
if PeekMessage(Msg,hWin,0,0,P
begin
Active:=Longint(GetMessage
TranslateMessage(Msg);
DispatchMessage(Msg);
end else WaitMessage;
end;
end.
When you press shift X it should close down the application but it does not, it should :P
Thanks in Advance...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
function WinProc(hWnd,uMsg,wPar,lPa r:Integer) :Integer; stdcall;
var text_array: array[0..256] of char;
begin
case uMsg of
WM_COMMAND: if ((EN_UPDATE = (wPar shr 16)) and (lPar = EH)) then begin
SendMessage(EH, WM_GETTEXT, 256, integer(@text_array[0]));
If Pos('X', text_array) <> 0 Then PostQuitMessage(0);
end;
....
var text_array: array[0..256] of char;
begin
case uMsg of
WM_COMMAND: if ((EN_UPDATE = (wPar shr 16)) and (lPar = EH)) then begin
SendMessage(EH, WM_GETTEXT, 256, integer(@text_array[0]));
If Pos('X', text_array) <> 0 Then PostQuitMessage(0);
end;
....
Hi,
Did you have a look at previous posts?
I posted a complete program using Raw Apis that works nicely.
Have a look in my reply history to find it.
Cheers,
Andrew
Did you have a look at previous posts?
I posted a complete program using Raw Apis that works nicely.
Have a look in my reply history to find it.
Cheers,
Andrew
ASKER