| CODE |
#include <windows.h> #include "resource.h" #include <iostream> using namespace std; LRESULT CALLBACK MainDlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam); bool moving = false; int oy = 0; int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) { DialogBox(hThisInstance, MAKEINTRESOURCE(IDD_DLGMAIN), NULL, reinterpret_cast<DLGPROC>(MainDlgProc)); return 0; } LRESULT CALLBACK MainDlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam) { if (Msg == WM_INITDIALOG) { HFONT hFont = CreateFont(24, 20, 0, 0, FW_THIN, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, "Georgia"); SendDlgItemMessage(hWndDlg, IDE_NUMBER, WM_SETFONT, (WPARAM)hFont, (LPARAM)MAKELPARAM(true, 0)); return true; } if (Msg == WM_LBUTTONDOWN) { WINDOWPLACEMENT winplace, scrplace; winplace.length = sizeof(winplace); GetWindowPlacement(GetDlgItem(hWndDlg, IDE_NUMBER), &winplace); RECT wplace = winplace.rcNormalPosition; int x = LOWORD(lParam); int y = HIWORD(lParam); if (x >= wplace.left && y >= wplace.top && x <= wplace.right && y <= wplace.bottom) { oy = y - wplace.top; moving = true; } } if (Msg == WM_LBUTTONUP) { moving = false; } if (Msg == WM_MOUSEMOVE) { if (moving) { if (wParam == MK_LBUTTON) { WINDOWPLACEMENT winplace, scrplace; winplace.length = sizeof(winplace); GetWindowPlacement(GetDlgItem(hWndDlg, IDE_NUMBER), &winplace); RECT wplace = winplace.rcNormalPosition; int x = LOWORD(lParam); int y = HIWORD(lParam); if (x >= wplace.left && y >= wplace.top && x <= wplace.right && y <= wplace.bottom) { cout << "top: " << wplace.top << endl << "y: " << y << endl << "oy: " << oy << endl; MoveWindow(GetDlgItem(hWndDlg, IDE_NUMBER), wplace.left, (wplace.top - (oy - (y - wplace.top))), wplace.right - wplace.left, wplace.bottom - wplace.top, true); oy = y - wplace.top; } } } return true; } return false; } |
| CODE |
(wplace.top - (oy - (y - wplace.top))), |
| CODE |
(wplace.top + (oy - (y - wplace.top))), |
| CODE |
#include <windows.h> #include "resource.h" #include <iostream> using namespace std; LRESULT CALLBACK MainDlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam); bool moving = false; int oy = 0; int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) { DialogBox(hThisInstance, MAKEINTRESOURCE(IDD_DLGMAIN), NULL, reinterpret_cast<DLGPROC>(MainDlgProc)); return 0; } LRESULT CALLBACK MainDlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam) { if (Msg == WM_INITDIALOG) { HFONT hFont = CreateFont(24, 20, 0, 0, FW_THIN, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, "Georgia"); SendDlgItemMessage(hWndDlg, IDE_NUMBER, WM_SETFONT, (WPARAM)hFont, (LPARAM)MAKELPARAM(true, 0)); return true; } if (Msg == WM_LBUTTONDOWN) { WINDOWPLACEMENT winplace, scrplace; winplace.length = sizeof(winplace); GetWindowPlacement(GetDlgItem(hWndDlg, IDE_NUMBER), &winplace); RECT wplace = winplace.rcNormalPosition; int x = LOWORD(lParam); int y = HIWORD(lParam); if (x >= wplace.left && y >= wplace.top && x <= wplace.right && y <= wplace.bottom) { oy = y; moving = true; } } if (Msg == WM_LBUTTONUP) { moving = false; } if (Msg == WM_MOUSEMOVE) { if (moving) { if (wParam == MK_LBUTTON) { WINDOWPLACEMENT winplace, scrplace; winplace.length = sizeof(winplace); GetWindowPlacement(GetDlgItem(hWndDlg, IDE_NUMBER), &winplace); RECT wplace = winplace.rcNormalPosition; int x = LOWORD(lParam); int y = HIWORD(lParam); if (x >= wplace.left && y >= wplace.top && x <= wplace.right && y <= wplace.bottom) { if (oy != (y - wplace.top)) { MoveWindow(GetDlgItem(hWndDlg, IDE_NUMBER), wplace.left, (wplace.top - ((oy - wplace.top) - (y - wplace.top))), wplace.right - wplace.left, wplace.bottom - wplace.top, true); oy = y; } } } } return true; } return false; } |