Stopping A Window Moving

Windows specific forum
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

Stopping A Window Moving

Post 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
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post 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
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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)
BERESHEIT
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

Post 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.
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post 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.
Post Reply