Windows下Win32实现对话框子控件刷新通知
typedef struct RectArea {
public:
RectArea(RectArea * pRectArea)
{
this->left = pRectArea->left;
this->top = pRectArea->top;
this->right = pRectArea->right;
this->bottom = pRectArea->bottom;
}
RectArea(const RectArea& rectArea)
{
this->left = rectArea.left;
this->top = rectArea.top;
this->right = rectArea.right;
this->bottom = rectArea.bottom;
}
RectArea(LONG left, LONG top, LONG right, LONG bottom)
{
this->left = left;
this->top = top;
this->right = right;
this->bottom = bottom;
}
RectArea(const RECT & rect)
{
this->left = rect.left;
this->top = rect.top;
this->right = rect.right;
this->bottom = rect.bottom;
}
RectArea(LPRECT lpRect)
{
this->left = lpRect->left;
this->top = lpRect->top;
this->right = lpRect->right;
this->bottom = lpRect->bottom;
}
RectArea(LPPOINT lpPoint, LPSIZE lpSize)
{
this->left = lpPoint->x;
this->top = lpPoint->y;
this->right = lpSize->cx - this->left;
this->bottom = lpSize->cy - this->top;
}
RectArea(const POINT & point, const SIZE & size)
{
this->left = point.x;
this->top = point.y;
this->right = size.cx - this->left;
this->bottom = size.cy - this->top;
}
public:
LONG left;
LONG top;
LONG right;
LONG bottom;
public:
LONG X() {
return left;
}
LONG Y() {
return top;
}
LONG Width() {
return (right - left);
}
LONG Height() {
return (bottom - top);
}
void X(LONG X) {
right = X + Width();
left = X;
}
void Y(LONG Y) {
bottom = Y + Height();
top = Y;
}
void Width(LONG width) {
right = left + width;
}
void Height(LONG height) {
bottom = top + height;
}
};
LPRECT ScreenToDialog(HWND hWnd, LPRECT lpRect, INT nRectNum)
{
for (SIZE_T i = 0; i < nRectNum * sizeof(RECT) / sizeof(POINT); i++)
{
::ScreenToClient(hWnd, &((LPPOINT)lpRect)[i]);
}
return lpRect;
}
LPPOINT ScreenToClient(HWND hWnd, LPPOINT lpPoint, INT nPointNum)
{
for (SIZE_T i = 0; i < nPointNum; i++)
{
::ScreenToClient(hWnd, &((LPPOINT)lpPoint)[i]);
}
return lpPoint;
}
LPRECT GetDlgItemRgect(RECT& rcRect, HWND hWnd, INT nIDWndItem)
{
::GetWindowRect(::GetDlgItem(hWnd, nIDWndItem), &rcRect);
return ScreenToDialog(hWnd, &rcRect, sizeof(rcRect)/sizeof(RECT));
}
void CalculateWindowSize(RECT& rect, INT nSpaceX, INT nSpaceY)
{
rect.right -= nSpaceX;
rect.bottom -= nSpaceY;
}
void CalculateWindowSize(RECT& rect, INT nSpaceL, INT nSpaceT, INT nSpaceR, INT nSpaceB)
{
rect.left += nSpaceL;
rect.top += nSpaceT;
rect.right -= nSpaceR;
rect.bottom -= nSpaceB;
}
void CalculateWindowSize(RECT& rect, const RECT & newRect, INT nSpaceX, INT nSpaceY)
{
rect.right = newRect.right - nSpaceX;
rect.bottom = newRect.bottom - nSpaceY;
}
void CalculateWindowSize(RECT & rect, const RECT& newRect, INT nSpaceL, INT nSpaceT, INT nSpaceR, INT nSpaceB)
{
rect.left = newRect.left + nSpaceL;
rect.top = newRect.top + nSpaceT;
rect.right = newRect.right - nSpaceR;
rect.bottom = newRect.bottom - nSpaceB;
}
void ResizeWindow(HWND hWnd, INT nIDWndItem, LPCRECT lpRect, BOOL bRepaint = TRUE)
{
MoveWindow(GetDlgItem(hWnd, ID_EDIT_TEXT), lpRect->left, lpRect->top, lpRect->right - lpRect->left, lpRect->bottom - lpRect->top, bRepaint);
}
void NotifyUpdateWindowControl(HWND hWnd, INT nIDWndItem, INT nSpaceX, INT nSpaceY)
{
RECT rc = { 0 }; GetDlgItemRgect(rc, hWnd, nIDWndItem);
rc.right += nSpaceX; rc.bottom += nSpaceY; ::InvalidateRect(hWnd, &rc, TRUE);
}
void NotifyUpdateWindowControl(HWND hWnd, INT nIDWndItem, INT nSpaceL, INT nSpaceT, INT nSpaceR, INT nSpaceB)
{
RECT rc = { 0 }; GetDlgItemRgect(rc, hWnd, nIDWndItem);
rc.left -= nSpaceL; rc.top -= nSpaceT; rc.right += nSpaceR; rc.bottom += nSpaceB; ::InvalidateRect(hWnd, &rc, TRUE);
}