做了個小程式測驗一下兩個功能,出了點兒問題,如圖

上面是WM_MOVING輸出,下面一行是M_MOVE,正常來講兩行輸出的坐標值不應該相同嗎?
另外還有,我原本以為WM_MOVING是在移動程序中坐標數值會發生變換,M_MOVE是在移動后坐標值變換,但是我測驗之后正好反過來,在移動視窗的程序中M_MOVE的坐標一直在改變,而WM_MOVING的坐標是視窗靜止下來后才發生變化的。
我是初學者,自學到這里有點兒糊涂了,請大神們賜教
附上代碼
case WM_MOVING:{
//system("Cls");
int xpos = LOWORD(lparam);
int ypos = HIWORD(lparam);
hdc = GetDC(hwnd);
SetTextColor(hdc, RGB(255, 0, 0));
SetBkColor(hdc, RGB(0, 255, 0));
SetBkMode(hdc, TRANSPARENT);
SetBkMode(hdc, OPAQUE);
sprintf(buffer, "現在的坐標是(%d,%d)", xpos, ypos);
TextOut(hdc, 0,0, buffer, strlen(buffer));
ReleaseDC(hwnd, hdc);
}break;
case WM_MOVE: {
//system("Cls");
int xpos = LOWORD(lparam);
int ypos = HIWORD(lparam);
hdc = GetDC(hwnd);
SetTextColor(hdc, RGB(255, 0, 0));
SetBkColor(hdc, RGB(0, 255, 0));
SetBkMode(hdc, TRANSPARENT);
SetBkMode(hdc, OPAQUE);
sprintf(buffer, "現在的坐標是(%d,%d)", xpos, ypos);
TextOut(hdc, 0, 20, buffer, strlen(buffer));
ReleaseDC(hwnd, hdc);
}break;
uj5u.com熱心網友回復:
WM_MOVINGThe WM_MOVING message is sent to a window that the user is moving. By processing this message, an application can monitor the size and position of the drag rectangle and, if needed, change its size or position.
fwSide = wParam; // edge of window to be moved
lprc = (LPRECT) lParam; // screen coordinates of drag rectangle
uj5u.com熱心網友回復:
void CListCtrl3Dlg::OnMoving(UINT fwSide, LPRECT pRect)
{
CDialog::OnMoving(fwSide, pRect);
// TODO: Add your message handler code here
#if 1
#define MOSTLEFT 100
#define MOSTTOP 80
#define MOSTRIGHT 1050
#define MOSTBOTTOM 750
CRect rect;
GetWindowRect(&rect);
afxDump << *pRect << "\n";
if(pRect->left <=MOSTLEFT)
{
pRect->left=MOSTLEFT;
pRect->right=MOSTLEFT+rect.Width();
}
if(pRect->right >=MOSTRIGHT)
{
pRect->right=MOSTRIGHT;
pRect->left=MOSTRIGHT-rect.Width();
}
if(pRect->top <=MOSTTOP)
{
pRect->top=MOSTTOP;
pRect->bottom=MOSTTOP+rect.Height();
}
if(pRect->bottom >=MOSTBOTTOM)
{
pRect->bottom=MOSTBOTTOM;
pRect->top=MOSTBOTTOM-rect.Height();
}
// pRect->top = rect.top;
// pRect->left = rect.left;
// pRect->right = rect.right;
// pRect->bottom = rect.bottom;
#endif
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/88156.html
標籤:界面
