Guest User

Untitled

a guest
May 25th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. //This example text box class (MyText is an object) as a wrapper for a text box, with getters for the text box's properties
  2. /*General idea is that WM_LBUTTONDOWN is called on left mouse click, and checks whether the click was inside the text box's region.
  3. If it is, the DraggingText bool remembers the text box is being dragged. The WM_MOUSEMOVE case is called when the mouse is moved.
  4. If the box is being dragged, it captures the cursor's position and uses SetWindowPos to update the text box's coordinates to the cursor
  5. position. The coordinates are also updated in the MyText object for future reference. WM_LBUTTONUP is called when the left mouse button
  6. is released, stopping the dragging process*/
  7. //Cases exist in window procedure for the text box's parent window
  8. case WM_LBUTTONDOWN: {
  9. POINT pos;
  10. pos.x = LOWORD(lP);
  11. pos.y = HIWORD(lP);
  12. if (pos.x >= mwns::MyText.GetXPos() && pos.x <= mwns::MyText.GetXPos() + mwns::MyText.GetWidth() &&
  13. pos.y >= mwns::MyText.GetYPos() && pos.y <= mwns::MyText.GetYPos() + mwns::MyText.GetHeight()) {
  14. DraggingText = true;
  15. }
  16. break;
  17. }
  18. case WM_LBUTTONUP:
  19. DraggingText = false;
  20. break;
  21. case WM_MOUSEMOVE: {
  22. POINT pos;
  23. pos.x = LOWORD(lP);
  24. pos.y = HIWORD(lP);
  25. if (DraggingText) {
  26. mwns::MyText.SetXPos(pos.x);
  27. mwns::MyText.SetYPos(pos.y);
  28. SetWindowPos(*mwns::MyText.GetHandle(), NULL, pos.x, pos.y, mwns::MyText.GetWidth(), mwns::MyText.GetHeight(), NULL);
  29. }
  30. break;
  31. }
Add Comment
Please, Sign In to add comment