invoking events of a control under another control
-
hi, need your help to solve this issue.. i have a custom pictureedit control in which i have many custom properties and events. i need to place an image OVER this in another ordinary picture edit and should be able to work on the events in the picture edit in the lower layer. i'll make it clearer... in my custom pictureedit i have added a feature to measure the distance between 2 points. now what i need to do is place another image over the main image and while comparing these images should be able to take the measurements from the lower image... hope you guys understood my issue clearly... tons of thanks in advance for any help
-
hi, need your help to solve this issue.. i have a custom pictureedit control in which i have many custom properties and events. i need to place an image OVER this in another ordinary picture edit and should be able to work on the events in the picture edit in the lower layer. i'll make it clearer... in my custom pictureedit i have added a feature to measure the distance between 2 points. now what i need to do is place another image over the main image and while comparing these images should be able to take the measurements from the lower image... hope you guys understood my issue clearly... tons of thanks in advance for any help
I'm not sure I understood correctly. You have 2 controls, one on top of the other, the covered one is a custom control (you wrote it?) and you want mouse events, I suppose, to pass through to the covered control? If it's your custom control (you have its code) then you can add methods you can call from the top control mouse event handlers then you make those metods call OnMouse.. methods, raise the events or do what you want to do directly in them. If you don't have the code, I think you can send the appropriate message(s) to the covered control using SendMessage[^].
Eslam Afifi
-
I'm not sure I understood correctly. You have 2 controls, one on top of the other, the covered one is a custom control (you wrote it?) and you want mouse events, I suppose, to pass through to the covered control? If it's your custom control (you have its code) then you can add methods you can call from the top control mouse event handlers then you make those metods call OnMouse.. methods, raise the events or do what you want to do directly in them. If you don't have the code, I think you can send the appropriate message(s) to the covered control using SendMessage[^].
Eslam Afifi
Thanks eslam... i tried using the sendmessage function.. but till now i've not been able to implement it successfully.. so can you help me in this... actually i make the measurement by dragging through the custom pictureedit(i dont have the source code) which is below the covering control i tried sending the WM_MOUSEMOVE alone & WM_LBUTTONDOWN & MOUSEMOVE together but nothing much happened...
[DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);\[DllImport("user32.dll", CharSet = CharSet.Auto)\] private static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam); private const int WM\_MOUSEMOVE = 0x200; private const int WM\_LBUTTONDOWN = 0x201; private void button2\_Click(object sender, EventArgs e) { SendMessage(axe.Handle, WM\_LBUTTONDOWN, IntPtr.Zero, IntPtr.Zero); SendMessage(axe.Handle, WM\_MOUSEMOVE, IntPtr.Zero, IntPtr.Zero);
}
once again thanks for showing the light.. hope you woulld be able to lead me further thanks
-
hi, need your help to solve this issue.. i have a custom pictureedit control in which i have many custom properties and events. i need to place an image OVER this in another ordinary picture edit and should be able to work on the events in the picture edit in the lower layer. i'll make it clearer... in my custom pictureedit i have added a feature to measure the distance between 2 points. now what i need to do is place another image over the main image and while comparing these images should be able to take the measurements from the lower image... hope you guys understood my issue clearly... tons of thanks in advance for any help
Perhaps you could explain again in an other way. It is not clear if you are using 2 controls (one top of other) or are you using 2 images?
http://vivekragunathan.spaces.live.com
Programming is an art. Code is a poem
-
Perhaps you could explain again in an other way. It is not clear if you are using 2 controls (one top of other) or are you using 2 images?
http://vivekragunathan.spaces.live.com
Programming is an art. Code is a poem
thanks for the reply.. i'll put the problem in another way i have 2 controls 1. a customized pictureedit 2. a custom picturebox which is transparent in the customized pictureedit i can measure the distance between 2 points by dragging the mouse from one point to another. in my form i place the second control exactly over the first one i load an image in the first control(in which i can take the measurements) that is underneath then i load different images in the upper transparent picturebox so that i can see both the images overlapping each other.. so far it works fine... now comes the tricky stuff i should be able to drag through the upper transparent control and take the difference in measurements between the 2 images. i can't keep the measurable pictureedit on the top as per the requirements. so what i need to do is drag on the upper transparent picturebox but get measurements as if i dragged on the lower pictureedit. i hope i have made it clearer this time once again thanks for the help
-
hi, need your help to solve this issue.. i have a custom pictureedit control in which i have many custom properties and events. i need to place an image OVER this in another ordinary picture edit and should be able to work on the events in the picture edit in the lower layer. i'll make it clearer... in my custom pictureedit i have added a feature to measure the distance between 2 points. now what i need to do is place another image over the main image and while comparing these images should be able to take the measurements from the lower image... hope you guys understood my issue clearly... tons of thanks in advance for any help
thanks for the reply.. i'll put the problem in another way i have 2 controls 1. a customized pictureedit 2. a custom picturebox which is transparent in the customized pictureedit i can measure the distance between 2 points by dragging the mouse from one point to another. in my form i place the second control exactly over the first one i load an image in the first control(in which i can take the measurements) that is underneath then i load different images in the upper transparent picturebox so that i can see both the images overlapping each other.. so far it works fine... now comes the tricky stuff i should be able to drag through the upper transparent control and take the difference in measurements between the 2 images. i can't keep the measurable pictureedit on the top as per the requirements. so what i need to do is drag on the upper transparent picturebox but get measurements as if i dragged on the lower pictureedit. i hope i have made it clearer this time once again thanks for the help
-
Thanks eslam... i tried using the sendmessage function.. but till now i've not been able to implement it successfully.. so can you help me in this... actually i make the measurement by dragging through the custom pictureedit(i dont have the source code) which is below the covering control i tried sending the WM_MOUSEMOVE alone & WM_LBUTTONDOWN & MOUSEMOVE together but nothing much happened...
[DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);\[DllImport("user32.dll", CharSet = CharSet.Auto)\] private static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam); private const int WM\_MOUSEMOVE = 0x200; private const int WM\_LBUTTONDOWN = 0x201; private void button2\_Click(object sender, EventArgs e) { SendMessage(axe.Handle, WM\_LBUTTONDOWN, IntPtr.Zero, IntPtr.Zero); SendMessage(axe.Handle, WM\_MOUSEMOVE, IntPtr.Zero, IntPtr.Zero);
}
once again thanks for showing the light.. hope you woulld be able to lead me further thanks
What you need is to send a mouse button down message when the mouse is down, mouse move when the mouse is moving and mouse up when the mouse is up. You can experiment to be sure of the message sequence when dragging happens by creating a dummy custom control (or form) with some code similar to the following and figure out the proper message sequence that is generated when you do dragging with it.
protected override void WndProc(ref Message m)
{
Debug.WriteLine(m.ToString()); // writes to the output window of visual studio when debugging a debugging build
base.WndProc(ref m);
}Use this list[^] to facilate analyzing the messages. Then you can send the appropriate message(s) in the proper event. By the way, don't send messages with lParam and wParam as IntPtr.Zero since they are supposed to hold modifier keys and mouse coordinates, which you need to make the covered control calculate the distance, otherzise it would calculate zero or some other wrong value since you're notifying it that is the mouse is currently at position (0, 0). See the msdn documentation of WM_LBUTTONDown... to know what to pass to lParam and wParam.
Eslam Afifi
-
What you need is to send a mouse button down message when the mouse is down, mouse move when the mouse is moving and mouse up when the mouse is up. You can experiment to be sure of the message sequence when dragging happens by creating a dummy custom control (or form) with some code similar to the following and figure out the proper message sequence that is generated when you do dragging with it.
protected override void WndProc(ref Message m)
{
Debug.WriteLine(m.ToString()); // writes to the output window of visual studio when debugging a debugging build
base.WndProc(ref m);
}Use this list[^] to facilate analyzing the messages. Then you can send the appropriate message(s) in the proper event. By the way, don't send messages with lParam and wParam as IntPtr.Zero since they are supposed to hold modifier keys and mouse coordinates, which you need to make the covered control calculate the distance, otherzise it would calculate zero or some other wrong value since you're notifying it that is the mouse is currently at position (0, 0). See the msdn documentation of WM_LBUTTONDown... to know what to pass to lParam and wParam.
Eslam Afifi
once again thanks eslam. i'm still fighting with this. pls see the log that i got ... msg=0x201 (WM_LBUTTONDOWN) hwnd=0xb046e wparam=0x0 lparam=0x4b0266 result=0x0 msg=0x7 (WM_SETFOCUS) hwnd=0xb046e wparam=0xd04a4 lparam=0x0 result=0x0 msg=0x8 (WM_KILLFOCUS) hwnd=0xb046e wparam=0x7a045c lparam=0x0 result=0x0 msg=0x111 (WM_COMMAND) hwnd=0xb046e wparam=0x100045c lparam=0x7a045c result=0x0 msg=0xc206 hwnd=0xb046e wparam=0x0 lparam=0x0 result=0x0 msg=0x200 (WM_MOUSEMOVE) hwnd=0xb046e wparam=0x1 lparam=0xffffffffff5d0230 result=0x0 msg=0x2a1 (WM_MOUSEHOVER) hwnd=0xb046e wparam=0x1 lparam=0xffffffffff5d0230 result=0x0 msg=0x202 (WM_LBUTTONUP) hwnd=0xb046e wparam=0x0 lparam=0xffffffffff5d0230 result=0x0 msg=0x215 (WM_CAPTURECHANGED) hwnd=0xb046e wparam=0x0 lparam=0x0 result=0x0 msg=0x2a3 (WM_MOUSELEAVE) hwnd=0xb046e wparam=0x0 lparam=0x0 result=0x0 msg=0x111 (WM_COMMAND) hwnd=0xb046e wparam=0x200045c lparam=0x7a045c result=0x0 but nothing special happened... no event in the message receiving control was fired.. am I missing anything ? pls help me on this thanks
-
once again thanks eslam. i'm still fighting with this. pls see the log that i got ... msg=0x201 (WM_LBUTTONDOWN) hwnd=0xb046e wparam=0x0 lparam=0x4b0266 result=0x0 msg=0x7 (WM_SETFOCUS) hwnd=0xb046e wparam=0xd04a4 lparam=0x0 result=0x0 msg=0x8 (WM_KILLFOCUS) hwnd=0xb046e wparam=0x7a045c lparam=0x0 result=0x0 msg=0x111 (WM_COMMAND) hwnd=0xb046e wparam=0x100045c lparam=0x7a045c result=0x0 msg=0xc206 hwnd=0xb046e wparam=0x0 lparam=0x0 result=0x0 msg=0x200 (WM_MOUSEMOVE) hwnd=0xb046e wparam=0x1 lparam=0xffffffffff5d0230 result=0x0 msg=0x2a1 (WM_MOUSEHOVER) hwnd=0xb046e wparam=0x1 lparam=0xffffffffff5d0230 result=0x0 msg=0x202 (WM_LBUTTONUP) hwnd=0xb046e wparam=0x0 lparam=0xffffffffff5d0230 result=0x0 msg=0x215 (WM_CAPTURECHANGED) hwnd=0xb046e wparam=0x0 lparam=0x0 result=0x0 msg=0x2a3 (WM_MOUSELEAVE) hwnd=0xb046e wparam=0x0 lparam=0x0 result=0x0 msg=0x111 (WM_COMMAND) hwnd=0xb046e wparam=0x200045c lparam=0x7a045c result=0x0 but nothing special happened... no event in the message receiving control was fired.. am I missing anything ? pls help me on this thanks
jamesjk wrote:
but nothing special happened... no event in the message receiving control was fired.. am I missing anything ?
The code was not to fire the events. It was to help you find the right message sequence and the lParam and wParam values to pass (read msdn documentation of those messages to find out the correct values to pass). You send the messages using SendMessage. So I guess the sequence would be sending, WM_LBUTTONDOWN in mousedown event WM_MOUSEMOVE in mousemove WM_MOUSEHOVER in mousehover (just in case the covered control uses it for something, i don't know. the same applies to WM_MOUSELEAVE) WM_LBUTTONUP in mouseup I don't know anything about WM_COMMAND nor 0xc206 (I couldn't find anything about it, maybe it's an undocumented message, i don't know). I think you shouldn't use WM_SETFOCUS and WM_KILLFOCUS. WM_CAPTURECHANGED, i don't know, maybe you should send it right after WM_MOUSEUP in mouseup event. P.S. I've never tried to simulate something like dragging before but I did try sending simple messages before. I don't know much so you should experiment more. And study sequences generated from cases like mousedown, move, leave the control, re-enter the control, move, mouse up... (cases like that) to ensure you get the desired result in both normal cases and extreme cases. And you're welcome.
Eslam Afifi