Click to See Complete Forum and Search --> : Getting an object offset from the main window -


.pcbrainbuster
November 11th, 2007, 04:58 PM
Sup guys,

I've got a static window with a bitmap in it. The question is how do I get it's offset from the parent window?

Thanks.

Marc G
November 12th, 2007, 09:11 AM
GetWindowRect (http://msdn2.microsoft.com/en-us/library/ms633519.aspx) to get the coordinates relative to upper-left corner of screen. Then use ScreenToClient (http://msdn2.microsoft.com/en-us/library/ms533179.aspx) to convert from screen coordinates to client coordinates.

.pcbrainbuster
November 12th, 2007, 11:58 AM
I'm still having problems and just for a note; ScreenToClient is only for a POINT structure.

Could you(or anyone else) please give me a code example which has a static control with a bitmap that can be dragged all over the screen if the user first left clicks obviously...

Thanks.

MrViggy
November 12th, 2007, 01:26 PM
I'm still having problems and just for a note; ScreenToClient is only for a POINT structure..
Right, and a rectangle contains two points.

Viggy

.pcbrainbuster
November 12th, 2007, 02:08 PM
Please explain :(

MrViggy
November 12th, 2007, 03:40 PM
A rectangle is just two points, right?
RECT windowRect;

::GetWindowRect(hWnd, &windowRect);
POINT tmpPt;
tmpPt.x = windowRect.left;
tmpPt.y = windowRect.bottom;
::ScreenToClient(hWnd, &tmpPt);
...
Viggy

.pcbrainbuster
November 12th, 2007, 05:08 PM
Oh that's what you meant :p Well I tried and miserably failed! The reason I'm using SetCursorPos is to test weather or not the positioning is correct, and it doesn't... -


GetWindowRect(DragB, &DragR); // DragB is the handle

DragP.x = DragR.left; // DragP is the boxe's points and DragR the rect
DragP.y = DragR.top; //...

ScreenToClient(hWnd, &DragP); // conversion takes place

SetCursorPos(DragP.x, DragP.y); // no dice :(


Its a little off the small box. What I mean is that I'm working on a replacement for paint and am trying to get some ideas from it and the reason I need the positioning to work correctly is so that the user can drag the drawing area as much as he/she wishes to use(if you go in paint you can drag the gray boxes to increase the 'draw zone').

Thanks.

.pcbrainbuster
November 12th, 2007, 05:25 PM
Hmm, doesn't a control send a message when the mouse is over it?!? If so what message?

Thanks.

.pcbrainbuster
November 12th, 2007, 06:15 PM
Why doesn't this work?!? -


StartingCursorPos.x > DragR.left - 1 && StartingCursorPos.x < DragR.left + 5 && StartingCursorPos.y > DragR.top - 1 && StartingCursorPos.y < DragR.top + 5


I used it in a if statement to check weather or not the mouse is pressed down on the static control but apperently it doesn't work! :(

Why?

Thanks.

Marc G
November 13th, 2007, 08:26 AM
Hmm, doesn't a control send a message when the mouse is over it?!? If so what message?

Thanks.
WM_MOUSEMOVE but if this is a static control you might need to add the SS_NOTIFY style to your static control.

.pcbrainbuster
November 13th, 2007, 11:24 AM
I already had, but found out that SS_NOTIFY is to receive click and double click messaged and not mouse move ones :( Isn't the code posted in the last post correct?

MrViggy
November 13th, 2007, 03:32 PM
Don't know. There isn't enough code there. Syntactically, it looks correct. Why not step though the code with your debugger, and see if the values are what you expect? Or, just dump them to some file.

Viggy

.pcbrainbuster
November 13th, 2007, 03:49 PM
Well I finally got it working! But it only works when I click on the border of the static control! I think it only works like that because a static control can't receive input/output.

What should I do? How did Microsoft manage it?

Thanks.

Marc G
November 14th, 2007, 09:39 AM
Yes, you are right, SS_NOTIFY is for clicks and double clicks.
For processing mouse moves, try to subclass the CStatic and implement your own WM_MOUSEMOVE handler.

.pcbrainbuster
November 14th, 2007, 12:04 PM
What does that mean :confused:

Marc G
November 15th, 2007, 10:06 AM
Search the articles on www.codeguru.com for examples on how to subclass CStatic controls.

.pcbrainbuster
November 15th, 2007, 05:20 PM
What I meant by that was, isn't CStatic MFC related?

Marc G
November 17th, 2007, 04:38 AM
Yes exactly, sorry my mistake.
Can you post your project so we can take a look at your current implementation?

.pcbrainbuster
November 17th, 2007, 09:42 AM
Well the project can't really be shared sadly enough because its destined to be commercial :)

Though I prepared another code which has pretty much the same problem -

Thanks.

Marc G
November 19th, 2007, 05:49 AM
I checked your project but please explain again in clear details what exactly you want to accomplish. Do you really need this static control? Are you just trying to draw a bitmap on the window which the user can move?

.pcbrainbuster
November 19th, 2007, 11:40 AM
What this static control is supposed to do in my project is allow you draw the region in which you may draw(like paint, have a look at the screen shot). But I all I want you to do is edit my code so that it allows you to simply move the static control around.

Thanks.

.pcbrainbuster
November 19th, 2007, 12:11 PM
Woops, here you go -

Marc G
November 20th, 2007, 05:34 AM
Ah, but in that case you don't really need any static control at all.
Create a variable to hold your "drawing rectangle". In WM_PAINT use that to know where to draw. WM_PAINT should also draw the little rectangles that you can use for dragging. In your WM_MOUSEMOVE handler check whether the mouse is over one of these little rectangles and if it is, update the variable and redraw. That's it. No need for any static control for this.

Marc G
November 20th, 2007, 06:18 AM
Ok, I made a small sample.
See attachment. It shows the following things:
Double buffering for flicker free drawing
Allow user to change size of the white drawing area
Change mouse cursor when hovering over the resizing rectangle
Limit the minimum size of the dialog

.pcbrainbuster
November 20th, 2007, 01:48 PM
Thanks for your post!

I tried to do the double buffering and failed same for limiting my window :( But why can't I find out if the cursor is over the static control?

Thanks.

LoKi_79
November 20th, 2007, 05:06 PM
But why can't I find out if the cursor is over the static control?
did you give it the SS_NOTIFY style?

http://msdn2.microsoft.com/en-us/library/bb760767.aspx

"Although static controls are child windows, they cannot be selected. Therefore, they cannot receive the keyboard focus and cannot have a keyboard interface. A static control that has the SS_NOTIFY style receives mouse input, notifying the parent window when the user clicks or double clicks the control."

.pcbrainbuster
November 20th, 2007, 05:53 PM
I did but you don't get a mouse down report which is what I need :(

Any ideas?

Thanks.

Marc G
November 21st, 2007, 04:28 AM
What is wrong with my example. It is working properly. You don't need any statics for your purpose. Please post your project or at least your windowproc.

.pcbrainbuster
November 21st, 2007, 09:05 AM
The reason I'm using statics is because everything becomes more easier and I think it may be resolved for now.

Thanks.

Marc G
November 21st, 2007, 12:43 PM
Well, I have to disagree with your idea about statics. In my opinion having 1 window, and processing WM_MOUSEMOVE, WM_LBUTTONDOWN/UP gives you all the power to create everything even a PhotoShop killer ;)

.pcbrainbuster
November 21st, 2007, 01:21 PM
Hmm, I see, YOU'RE A FANATIC AREN'T YOU! Just joking :p Well I haven't decided what I'm going to do yet because I have an issue that has more priority(see Shifting a DC).

Thanks.

Marc G
November 22nd, 2007, 04:51 AM
I'm just trying to help ;) ...