Solved

Why does this code not work...

Posted on 2003-11-21
8
398 Views
Last Modified: 2010-04-05
program smallexe;

uses
  Windows,
  Messages;

Var
  WindowHandle: HWND;
  BH,EH: Integer;

const
  MULTIEDIT1 = 1;
  EditBox2 = 2;
  Button = 3;

function WinProc(hWnd,uMsg,wPar,lPar: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_BTNFACE+1;
     lpszMenuName:=nil;
     lpszClassName:='someclass';
end;

  RegisterClass(wClass);
  hWin:=CreateWindow('someclass','form1',
  WS_VISIBLE or WS_THICKFRAME or WS_OVERLAPPED or WS_SYSMENU,
  0,0,380,340,0,0,hInstance,nil);

 EH:=CreateWindow('EDIT','Example', ES_AUTOHSCROLL or WS_Border or WS_Child or WS_Visible,50,50,200,20,Hwin,EditBox2,Hinstance,Nil);

//Create Window, EditBox2 is what to look for...


 BH:=CreateWindow('BUTTON','OK',BS_PUSHBUTTON Or WS_VISIBLE OR WS_CHILD, 100,100,50,50, Hwin, Button, 0,Nil);



 while Active do
  begin
  if PeekMessage(Msg,hWin,0,0,PM_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...
0
Comment
Question by:craig_capel
8 Comments
 
LVL 6

Accepted Solution

by:
GloomyFriar earned 50 total points
ID: 9802397
function WinProc(hWnd,uMsg,wPar,lPar:Integer):Integer; stdcall;
begin
case uMsg of
WM_CHAR: begin
  If Wpar=Ord('X') Then PostQuitMessage(0);
end;

EditBox2:
 Begin
  If Wpar=Ord('X') Then PostQuitMessage(0)
  else Result:=DefWindowProc(hWnd,uMsg,wPar,lPar);
 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;
0
 
LVL 2

Author Comment

by:craig_capel
ID: 9802587
Nope still did not help, closing down the form when it recvs a char is not what it's intended to do, when you press X in the edit box that displays, then it's supposed to close down...

0
 
LVL 2

Expert Comment

by:TheLeader
ID: 9802973
try to look at this link
it may help
http://www.delphi-resource.com/articles/raw_api.shtml
0
 
LVL 6

Expert Comment

by:GloomyFriar
ID: 9805588
function WinProc(hWnd,uMsg,wPar,lPar: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;

....
0
 
LVL 5

Expert Comment

by:DeerBear
ID: 9810117
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
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
delphi exception 7 64
Help on project with Soap 10 53
Downloading email attachments 2 72
Drag & Drop... Data from one grid to another 2 9
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question