Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Movewindow offscreen

Status
Not open for further replies.

zachman123

Programmer
Feb 16, 2004
2
US
This is a compilation of my posts on Neowin, but they couldn't help (at least so far)
I'm using C#. I'm creating a program similar to the OSX expose feature. Using the user32 MoveWindow, I can do this to move every window to the left edge of the screen,
Code:
foreach (EnumWindowsItem item in eW.Items)
  {
   if (item.Visible)
   {
    if (item.Maximised)
    {
    item.UnMax();
    }
    while(item.Location.X > 0){
    item.Moveit(); /*Moves window one to the left, using this code
UnManagedMethods.MoveWindow(this.hWnd,this.Location.X-1,this.Location.Y,this.Size.Width,this.Size.Height,false);
this.location.X refers to the window, as item is the current window
*/
    }
   }
  }
But if I try to make the while loop lower than 0 (negitive), the program freezes. Anyone have any ideas?

It works if I put -10 right into it like this...

UnManagedMethods.MoveWindow(this.hWnd,-10,this.Location.Y,this.Size.Width,this.Size.Height,false);

so it is possible, I think it might have to so with the loop, but I'm not sure

Also, while(item.Location.X >= 0) doesn't work, but while(item.Location.X >= 1) does, so it appears the problem is when the window edge hits 0

Just tried it with SetWindowPos and it didn't work either (worked with 0 though). If anyone has any idea, please tell me. If I'm not giving enough source code, just ask here/PM me and I'll give it to you.

Same thing also happens if I just use true in the while loop (that's obvious that the infinate loop will freeze it), but I've been trying to figure out what's making this loop infinite (Or if it just freezes)

Anyways, I'm so confused

Thanks for any help

edit: Also, if I switch it around to move to the right, and switch the operator to <, it only works with a negitive in the while loop.

Please Help

From
 
Have you specifically tested calling
Code:
UnManagedMethods.MoveWindow(this.hWnd,-1,this.Location.Y,this.Size.Width,this.Size.Height,false);

This is the call that would happen at the point where [tt]item.Location.X == 0[/tt]
 
Yes that works, the odd thing is that using any negative number that way works (such as -1)... Therefore I think the problem is in the loop.


thanks for any ideas (and if you want to see more of the source just ask
 
Add in the loop :
this.Location.X = this.Location.X- 1;
and call GetLastError() after MoveWindow() call;
-obislavu-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top