making a window move itself

Started by
2 comments, last by graeme 22 years, 2 months ago
Ok, as a first project in C++ i am trying to make a desktop toy so far i have a window with no borders bliting an image from the desktop into itself. i want to be able to let the window find out where it is on the screen in order to move itself. so far i''ve been making it hop about here and there with this code: /*SetWindowPos (hwnd, 0, rand()%(GetSystemMetrics(SM_CXSCREEN)-60), rand()%(GetSystemMetrics(SM_CYSCREEN)-60), 0,0, SWP_NOSIZE | SWP_NOZORDER);*/ instead of those random positions how could i replace them with a ''my windows x pos +1 and my window y pos +1 sort of thing, obviously i wouldn''t introduce the increment within the actual moving of the window, i''d be setting a variable earlier. i think, in essence my question is ''how do interogate an hwnd in terms of x and y coords on the screen''? with MSDN i have got as far as the operation GetWindowRect, is the one to use? and how do i interrogate the structure that it returns (is it a structure?) ? do i use bracket access? like to get the x coord i''d say theThingThatWasTheResultOfGetWindowRect [1] for the x coord and [3] for the x width? or am i completely wrong??
Advertisement
Why interrogate the window if you have its previous position already (you set it, didn''t you)?

[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!
Am I missing something, or couldn''t you just keep track of the window''s location in a couple of variables?

------------------------------
bah
------------------------------
of course you are quite right of course. i should learn not to post (or program) after pub. i vow not to in the future.
But for the sake of argument, how do you access the properties of a window? hwnd._X or something?

This topic is closed to new replies.

Advertisement