drag/move a line

How can I drag/move a line?

I have created the line but I don’t know how to select and move this by mouse!

Thank so much for help to me,

---------------------------------

case WM_PAINT:

{

PAINTSTRUCT ps;

HDC hdc = BeginPaint(hWnd, &ps);

MoveToEx (hdc, x, y, NULL);

LineTo (hdc, x, 0);

EndPaint(hWnd, &ps);

}
Dear Meyson,

You need to update your implementation so that your application react to mouse move event.
You might also want to define global variable "x" and "y" so that the values of "x" and "y" changes according to mouse move event. The following is the reference on how to process a mouse move event.
https://docs.microsoft.com/en-us/windows/desktop/inputdev/wm-mousemove

The following is example to enable the movement of the line according to x position of the mouse:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/// Define global variable to store the changes of mouse position
/// It is recommended to add a prefix "g_" for global variable.
int g_x = 0;
int g_y = 100;
...
...
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
...
...
case WM_MOUSEMOVE:
{
        /// Retrieve X Position from lower bytes of lParam
        g_x = lParam & 0x0FFFF;
        /// Request windows to update the rendering
        InvalidateRect(hWnd, NULL, TRUE); 
        break;
}
case WM_PAINT:
{
        PAINTSTRUCT ps;
        HDC hdc = BeginPaint(hWnd, &ps);
        MoveToEx (hdc, g_x, g_y, NULL);
        LineTo (hdc, g_x, 0);
	EndPaint(hWnd, &ps);
        /// Do not forget the break so that the case after WM_PAINT will not be executed
	break;
}
Last edited on
Topic archived. No new replies allowed.