Can someone tell me how to exit from a window by pressing ESC.
I tried to use:
IF @CODE=0x1B
'Esc key pressed
run=0
ENDIF
The problem is that it is an internet browser window (wb) which runs inside
the opening window (w1). My browser code may be found here:
http://www.ionicwind.com/forums/index.php/topic,3158.0.html (http://www.ionicwind.com/forums/index.php/topic,3158.0.html)
I tried various schemes but it never worked.
I used the above code in an IBasic Calendar program and it worked like a charm.
Calender IBasic code:
'Don's Monthly Calendar Public Domain program
'You may change name and make yourself the author.
setid "WS_VISIBLE",&H10000000
setid "WS_CHILD",&H40000000
setid "WS_BORDER",8388608
declare "user32",CreateWindowExA(ex:int,class:string,name:string,style:int,x:int,y:int,x1:int,y1:int,parent:window,id:int,hinstance:int,ed:int),int
declare "user32",SendMessageA(wnd:int,message:int,wparam:int,st:SYSTIME),int
declare "user32",DestroyWindow(hWnd:int)
declare "user32",GetSysColor(what:int),int
declare "comctl32", InitCommonControlsEx(p:pointer)
'UDT for system time.
type SYSTIME
def wYear:word
def wMonth:word
def wDayOfWeek:word
def wDay:word
def wHour:word
def wMinute:word
def wSecond:word
def wMilliseconds:word
endtype
type initcommctl
def dwSize:uint
def dwICC:uint
endtype
def temp:int
def st:SYSTIME
def win:window
def run,mcal,n:int
def nowTime:string
def icex:initcommctl
icex.dwICC = 0x00000100
icex.dwSize = len(icex)
InitCommonControlsEx(icex)
clear InitCommonControlsEx
run = 1
window win,0,0,239,240,@CAPTION|@SYSMENU|@SIZE,0," Don's Calendar",mainwindow
centerwindow win
'setwindowcolor win,GetSysColor(15)
setwindowcolor win,GetSysColor(26)
'Create MonthCal Control with ID=5
mcal=CreateWindowExA(0x200,"SysMonthCal32","",&H10000000 | &H40000000 | 8388608 ,5,5,220,170,win,2024+5,0,0)
GOSUB checkDate
waituntil run=0
DestroyWindow(mcal)
closewindow win
end
sub mainwindow
select @class
IF @CODE=0x1B
'Esc key pressed
run=0
ENDIF
case @IDCLOSEWINDOW
run = 0
CASE @IDCONTROL
IF @CONTROLID = 3 THEN run = 0
IF @CONTROLID = 5 THEN GOSUB checkDate
endselect
return
sub checkDate
temp=SendMessageA(mcal,4097,0,st)
nowTime=str$(st.wMonth) + "/"+ str$(st.wDay)+ "/" + str$(st.wYear)
'move win, 45, 180
move win, 55, 180
print win, "Date: " + nowTime + " "
return
Regards, Don Smith
Screen Shot of IBasic Calendar program:
(http://www.smithselfgen.com/QuickBasic/DonsCalendar.Jpg)
Give this a try:
select @class
case @IDCLOSEWINDOW
run = 0
CASE @IDCONTROL
IF @CONTROLID = 3 THEN run = 0
IF @CONTROLID = 5 THEN GOSUB checkDate
CASE @IDKEYDOWN
SELECT @WPARAM
'ESC key handling
CASE 0x1B
run = 0
endselect
endselect
Bill
You are looking at the wrong program. The Calender code is working as it is and pressing ESC exits the program. The program which I wish to exit by pressing ESC is the browser program, CBB.EXE
It is found here:
http://www.ionicwind.com/forums/index.php/topic,3158.0.html (http://www.ionicwind.com/forums/index.php/topic,3158.0.html)
Regards, Don Smith
Hi Don....
Try this :
select @class
CASE @IDKEYDOWN
IF @CODE=0x1B
'Esc key pressed
run=0
ENDIF
The ultimate solution, working even if the browser is focused:
'======================[Main Window]=============================
OpenWindow w1,x,y,w,h,@size|@minbox|@maxbox,0,"CB Browser",&main
$include "windows.inc"
int g_hook = _SetWindowsHookEx(WH_KEYBOARD, &kbHookProc, 0, _GetCurrentThreadId())
sub kbHookProc(int code, int key, int repeat),int
if (key = 0x1B) then run = 0
return _CallNextHookEx(g_hook, code, key, repeat)
endsub
And the cleanupWAITUNTIL run = 0
Closewindow wb
Closewindow w1
_UnhookWindowsHookEx(g_hook)
End
Sapero, your code worked like a charm! Thank you so much.
I have changed the code of the EBA section of the browser program to reflect the changes
with the new code
http://www.ionicwind.com/forums/index.php/topic,3158.0.html (http://www.ionicwind.com/forums/index.php/topic,3158.0.html)
Regards, Don Smith