Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"SHDocVw.WebBrowser" with "wait"
This is a bit difficult to explain as it concerns a large project, so I extracted the important parts to try to explain my question.
I have in a "SHDocVw.WebBrowser" control and a button that does the following:
1. navigate to a folder path
2. focus on an specific folder using a subfunction

Part I: is how the "SHDocVw.WebBrowser" is set up
Part II: The code under the button that FIRST navigates to a "folder" then executes a subfunction
Part III: contents of the subfunction

The actual question regards, Part II.
If I use a "wait 2" (wait 2 seconds) then the dialog first waits 2 seconds then navigates to the "folder" and thus I run into an error
subfunction (described at Part III) get's executed to soon.
However if I use the code specified at Part II with just "wait" only, the code works perfect!.
* QUESTION: Is it allowed to use just "wait" below in Part II or do I need to use "opt waitmsg"?
* QUESTION: If the "wait" below in Part II is not correct then how do I use opt waitmsg?

   EDIT: If found this to be working, dont't know if it is actually correct (maybe 300 is to much but would result in max 3 seconds)?

  rep(300) opt waitmsg 1; 0.01; if(!we1.Busy) break

In the help it states:
Copy      Help
timeS 0 or omutted: Just process messages that possibly are waiting in thread's message queue, regardless of opt waitmsg.
Note: If the thread has windows/dialogs or uses COM events or some Windows API functions that use Windows messages, you should avoid wait commands in it. Or use small time (<0.1). By default, messages are not processed while waiting, and your thread may temporarily hang. To process messages while waiting, use opt waitmsg.

Note: Don't use Windows API wait functions, because then QM cannot properly end the thread on user request. QM then terminates thread, which causes a big memory leak and possibly more bad things. Also, opt waitmsg is not applied.

PART I , very briefly describes how the 'SHDocVw.WebBrowser' is setup
Copy      Help
str dd:
3 ActiveX 0x54030000 0x0 5 36 194 190 "SHDocVw.WebBrowser"

#sub DlgProc:
SHDocVw.WebBrowser- we1
Shell32.ShellFolderView- fv1
Shell32.FolderItem- fi1
we1._getcontrol(id(3 hDlg))
we1._setevents("sub.we1") ;;need DocumentComplete event

PART II (button code)
Copy      Help

PART III contents of the subfunction
"sub.focus_on"  subfunction contains code very similair to (
Copy      Help
int lv=child("" "SysListView32" hDlg)
SetFocus lv
Acc a.Find(lv "LISTITEM" "VM" "" 0x1015)
SendMessage lv LVM_ENSUREVISIBLE a.elem-1 0
Copy      Help
probably is asynchronous even when the URL is a folder. If your code with just 'wait' works, it is the best way. If need to wait longer, either use a timer or opt waitmsg.
or use setwintext instead of Navigate. It waits while busy.

Copy      Help
,case 6
,_s="q:\"; _s.setwintext(id(3 hDlg))
,sub.focus_on hDlg
Thank you!!!

(I wish you and all QM community a successful, happy and healthy new year!)

Forum Jump:

Users browsing this thread: 1 Guest(s)