May 31, 2024, 07:42:20 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Using @IDCHAR and @WPARAM in Embedded Browser Windows

Started by Logman, February 04, 2011, 10:09:05 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Logman

Larry - Sapero: I Need Help

I used the sample browser code that came with IWBasic to test some callback messages.

The question I need help with is why canââ,¬â,,¢t I seem to get @IDCHAR or @IDKEYDOWN to work in the ââ,¬Å"sub handlerââ,¬Â callback subroutine?  

If I click outside the main window and then mouse back over the main window without clicking on it, the @IDCHAR and @IDKEYDOWN selections seem to work. That is until I click back inside the main window.

This tells me there is a problem with which window has focus. Everything else seems to work just fine. How do I capture keystrokes inside my main window when attaching a browser?



' Define variables used in the program
DEF win,cont,urldlg AS WINDOW
DEF caption,newCaption,strKey AS STRING
DEF tbArray[9] AS INT
DEF key AS INT
CONST idBack = 0x100
CONST idForward = 0x101
CONST idStop = 0x102
CONST idRefresh = 0x103
CONST idHome = 0x104
CONST idPrev = 0x105
CONST idNext = 0x106

' Declare any imported procedures
DECLARE IMPORT,GetSysColor(nIndex as INT),UINT

' Open the main window and attach the menu
OPENWINDOW win,0,0,800,600,@NOAUTODRAW|@SIZE|@MINBOX|@MAXBOX,0,"Test HTML File",&handler

' Open the browser containing window
OPENWINDOW cont,0,0,800,580,@NOAUTODRAW|@NOCAPTION,win,"",&browserhandler

' Open the URL entry window used as a toolbar
OPENWINDOW urldlg,50,0,800,35,@NOAUTODRAW|@NOCAPTION|@BORDER,win,"",&urlHandler
CONTROL urldlg,@EDIT,"",54,6,500,22,@CTEDITMULTI|@CTEDITRETURN|@CTEDITAUTOV,2
CONTROL urldlg,@STATIC,"URL",21,8,31,16,0x5000010B,3
SETWINDOWCOLOR urldlg,GetSysColor(15)
SETFONT urldlg,"MS Sans Serif",-13,400,0,2

' Add a status window for messages
CONTROL win,@STATUS,"Status",0,0,0,0,0,2
' Create a toolbar. It will send its messages to the main window
tbArray = idBack,idForward,idStop,idRefresh,idHome,0,idPrev,idNext
IF LOADTOOLBAR(win,"",999,tbArray,8,@TBTOP | @TBLIST)
CONTROLCMD win,999,@TBSETLABELS,"Back |Fwd |Stop |Refresh |Home |Prev |Next ||"
CONTROLCMD win,999,@TBRESIZE
CONTROLCMD win,999,@TBENABLEBUTTON,idBack,FALSE
CONTROLCMD win,999,@TBENABLEBUTTON,idForward,FALSE
ENDIF
' Create and attach the browser to the containing window
' ATTACHBROWSER returns 0 on success
IF ATTACHBROWSER(cont) <> 0
MESSAGEBOX win,"Unable to create embedded browser","error"
CLOSEWINDOW urldlg
CLOSEWINDOW cont
CLOSEWINDOW win
END
ENDIF

' Set the browser, status window and toolbars initial size
ResizeAll()
' Browse to document cover page
BROWSECMD cont,@NAVIGATE,GETSTARTPATH+"index.htm"

WAITUNTIL win=0
END

SUB browserhandler
SELECT @MESSAGE
CASE @IDBEFORENAV
BROWSECMD(cont,@GETNAVURL,caption,255)
SETCAPTION win,caption
SETCONTROLTEXT urldlg,2,caption
CASE @IDNAVCOMPLETE
BROWSECMD(cont,@GETTITLE,caption,255)
newCaption=caption
IF LEN(caption) THEN SETCAPTION win,newCaption
'best place to update toolbar buttons
CONTROLCMD win,999,@TBENABLEBUTTON,idBack,BROWSECMD(cont,@BACKENABLED)
CONTROLCMD win,999,@TBENABLEBUTTON,idForward,BROWSECMD(cont,@FORWARDENABLED)
CASE @IDSTATUSTEXTUPDATE
BROWSECMD(cont,@GETSTATUSTEXT,caption,255)
CONTROLCMD win,2,@SWSETPANETEXT,0,caption
ENDSELECT
RETURN
ENDSUB

SUB handler
SELECT @MESSAGE
CASE @IDKEYDOWN
key=@wparam
strKey=str$(key)
MESSAGEBOX(win,"Key Pressed!","Key: "+strKey,@MB_OK)
' CASE @IDCHAR
' key=@wparam
' strKey=str$(key)
' MESSAGEBOX(win,"Key Pressed!","Key: "+strKey,@MB_OK)
CASE @IDCLOSEWINDOW
CLOSEWINDOW urldlg
CLOSEWINDOW cont
CLOSEWINDOW win
CASE @IDSIZE
ResizeAll()
CASE @IDCONTROL
IF @NOTIFYCODE = 0 /* ignore any tooltip messages */
SELECT @CONTROLID
CASE idBack
BROWSECMD cont,@GOBACK
CASE idForward
BROWSECMD cont,@GOFORWARD
CASE idStop
BROWSECMD cont,@BROWSESTOP
CASE idRefresh
BROWSECMD cont,@REFRESH
CASE idHome
BROWSECMD cont,@GOHOME
CASE idPrev
BROWSECMD cont,@NAVIGATE,GETSTARTPATH + "index.htm"
CASE idNext
BROWSECMD cont,@NAVIGATE,GETSTARTPATH + "noscroll.htm"
ENDSELECT
ENDIF
ENDSELECT
RETURN
ENDSUB

SUB urlHandler
DEF temp as STRING
DEF rcEdit,rcClient as WINRECT
SELECT @MESSAGE
CASE @IDCONTROL
SELECT @CONTROLID
CASE 1
BROWSECMD cont,@NAVIGATE,GETCONTROLTEXT(urldlg,2)
CASE 2
SELECT @NOTIFYCODE
CASE @ENCHANGE
temp = GETCONTROLTEXT(urldlg,2)
IF INSTR(temp,"\n")
BROWSECMD cont,@NAVIGATE,temp
ENDIF
ENDSELECT
ENDSELECT
CASE @IDSIZE
'dynamically adjust the size of the edit control.
GETCLIENTSIZE urldlg,rcClient.left,rcClient.top,rcClient.right,rcClient.bottom
SETSIZE urldlg,54,6,rcClient.right - 58,22, 2
ENDSELECT
RETURN
ENDSUB

SUB ResizeAll
'use rects for convenience.
'the Get*Size functions return width and height instead of right and bottom
WINRECT rcClient,rcStatus,rcUrl
'tell the status bar to resize itself
CONTROLCMD win,2,@SWRESIZE
CONTROLCMD win,999,@TBRESIZE
GetClientSize win,rcClient.left,rcClient.top,rcClient.right,rcClient.bottom
'get the size of the statusbar
GetSize win,rcStatus.left,rcStatus.top,rcStatus.right,rcStatus.bottom,2
'subtract the 'height' of the status bar control
rcClient.bottom -= rcStatus.bottom
'get the size of the toolbar
GetSize win,rcStatus.left,rcStatus.top,rcStatus.right,rcStatus.bottom,999
'subtract the 'height' of the toolbar. Do this by increasing the top of the rectangle by
'the height of the toolbar and also reducing the height of the rectangle accordingly
rcClient.top += rcStatus.bottom
rcClient.bottom -= rcStatus.bottom
'make room for our URL entry window
GetSize urldlg,rcUrl.left,rcUrl.top,rcUrl.right,rcUrl.bottom
rcClient.top += rcUrl.bottom
rcClient.bottom -= rcUrl.bottom
'set the size of the browsers containing window
SetSize cont,rcClient.left,rcClient.top,rcClient.right,rcClient.bottom
'finally set the size of the url window
SetSize urldlg,rcClient.left,rcClient.top-rcUrl.bottom,rcClient.right,rcUrl.bottom
RETURN
ENDSUB



Thank you ahead of time.

I attached a copy of the .eba file and a copy of both .html files used with the program. However, I had to change the name of the two .htm files to .txt to get them to upload as you can't upload .html files. Need to rename the extensions to .htm.

Logman
Education is what you get when you read the fine print.<br />Experience is what you get when you don't!

aurelCB

Maby something like this ,but dont show hex values then normal decimal numbers..
IF @message= @IDKEYDOWN
IF @wparam
key=@wparam
FOR key= 0x08 TO 0x5A
MESSAGEBOX(0,"Key Pressed!","Key: "+str$(@wparam),@MB_OK)
BREAKFOR
Next key
endif
ENDIF

sapero

Logman, the client area of ââ,¬Å"sub handlerââ,¬Â must be focused to receive key stokes. The user is even not able to click on it, because other windows are covering it.
Only the focused or active window receives user input.

Logman

Thanks guys, I know I need to somehow get focus in the sub handler, just not sure how to force this using IWBasic commands while perusing browser pages. I tried putting the @IDKEYDOWN/@IDCHAR routines in the browserhandler, but that doesn't work either.

AurelCB-nice code. The @IDKEYDOWN code I showed was just for examining what was going on. My final code will just look for the F1 and ESC keys and then either quit the program (ESC) or bring up a help file (F1) for the program. I have to figure out how to get focus in the right location so that my sub handler will capture user keystrokes.

Logman
Education is what you get when you read the fine print.<br />Experience is what you get when you don't!

aurelCB

Logman do you try Accelerator...
QuoteADDACCELERATOR

ADDACCELERATOR(win as WINDOW,fVirt as CHAR,key as WORD,cmd as WORD)


Logman

AurelCB,

I thought about it, but haven't tried it. Now that you mention it, I might give it a try today.

Thanks, Logman
Education is what you get when you read the fine print.<br />Experience is what you get when you don't!