Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This example text box class (MyText is an object) as a wrapper for a text box, with getters for the text box's properties
- /*General idea is that WM_LBUTTONDOWN is called on left mouse click, and checks whether the click was inside the text box's region.
- If it is, the DraggingText bool remembers the text box is being dragged. The WM_MOUSEMOVE case is called when the mouse is moved.
- 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
- position. The coordinates are also updated in the MyText object for future reference. WM_LBUTTONUP is called when the left mouse button
- is released, stopping the dragging process*/
- //Cases exist in window procedure for the text box's parent window
- case WM_LBUTTONDOWN: {
- POINT pos;
- pos.x = LOWORD(lP);
- pos.y = HIWORD(lP);
- if (pos.x >= mwns::MyText.GetXPos() && pos.x <= mwns::MyText.GetXPos() + mwns::MyText.GetWidth() &&
- pos.y >= mwns::MyText.GetYPos() && pos.y <= mwns::MyText.GetYPos() + mwns::MyText.GetHeight()) {
- DraggingText = true;
- }
- break;
- }
- case WM_LBUTTONUP:
- DraggingText = false;
- break;
- case WM_MOUSEMOVE: {
- POINT pos;
- pos.x = LOWORD(lP);
- pos.y = HIWORD(lP);
- if (DraggingText) {
- mwns::MyText.SetXPos(pos.x);
- mwns::MyText.SetYPos(pos.y);
- SetWindowPos(*mwns::MyText.GetHandle(), NULL, pos.x, pos.y, mwns::MyText.GetWidth(), mwns::MyText.GetHeight(), NULL);
- }
- break;
- }
Add Comment
Please, Sign In to add comment