Page 1 of 1
Stopping A Window Moving
Posted: Tue Sep 26, 2006 10:01 am
by RichardL
I have written an application to program some hardware via the serial port (using MVCOM) and it works well and is crash free in the hands of inexpert users, except... on some machines... programming fails and has to be re-started...
When the window is moved it hogs sufficient resources to introduce some timing errors. Is there a neat way to force the window to the front, keep it there and prevent it being dragged while the time critical functions are being carried out, then return to normal operation after programming is finished?
RichardL
Posted: Tue Sep 26, 2006 11:04 am
by gnozal
To lock a window
Easy way :
Code: Select all
PureRESIZE_SetWindowMonitoring(WindowNumber.l, Flag.l) ; Monitor a window [forbids moving or resizing]
Or :
Check #WM_WINDOWPOSCHANGING message in callback
Code: Select all
Procedure myWindowCallback(hwnd, msg, wParam, lParam)
result = #PB_ProcessPureBasicEvents
Select msg
Case #WM_WINDOWPOSCHANGING
If hwnd = WindowID(0)
*WinPos.WINDOWPOS = lParam
*WinPos\flags = #SWP_NOMOVE | #SWP_NOSIZE ; delete this line and it will move ...
result = #False
EndIf
EndSelect
ProcedureReturn result
EndProcedure
If OpenWindow(0, 100, 200, 200, 200, "Locked Window", #PB_Window_SystemMenu) And CreateGadgetList(WindowID(0))
SetWindowCallback(@myWindowCallback())
Repeat
event = WaitWindowEvent()
Until event = #PB_Event_CloseWindow
EndIf
Posted: Tue Sep 26, 2006 9:55 pm
by netmaestro
Something else you might consider is putting the programming function in a thread and giving it "Time Critical" priority, which will cause the OS to give all the resources to it while it runs. If moving a window can make it crash it's an option I'd be looking at quite seriously. (assuming the programming is accomplished in a reasonably short time)
Posted: Wed Sep 27, 2006 7:35 am
by RichardL
The timing problem that started this thread was very specific to the hardware that was being programmed via the RS232 port.
Genearally the serial comms are very reliable and have sufficient buffering to cater for most things. For example, on a USB interface I wrote, which used RS232 comms to tell remote hardware which packets to send via USB, I could scrub a half screen window around as much as I liked, the transfer just slowed down.
However, in the current case there are some absolute timings that the peripheral imposes and these were causing the problem. I'm going to try Gnozal's library as a solution... the next cut of the software is due next month and I will see if that fixes the problem.
Thanks guys.
Posted: Wed Sep 27, 2006 7:46 am
by Rescator
In your main/gui loop, make sure to put something like Delay(20) after any window resizing or move code. Resizing a window (esp. on WindowsXP if the "show window contents while moving" is very cpu intensive.