📄 ccsplitter.c
字号:
if (pt.x < sp->xlower)
pt.x = sp->xlower;
if (pt.y < sp->ylower)
pt.y = sp->ylower;
if (pt.x > rc.right - sp->xupper)
pt.x = rc.right - sp->xupper;
if (pt.y > rc.bottom - sp->yupper)
pt.y = rc.bottom - sp->yupper;
hdc = GetDCEx (hSplitter, NULL, DCX_PARENTCLIP);
hbr = SelectObject (hdc, hbrDotty);
if (sp->ydrag >= 0) {
PatBlt (hdc, 0, SPTOP (sp->ydrag, sp->ywidth), rc.right, sp->ywidth, PATINVERT);
sp->ydrag = pt.y;
}
if (sp->xdrag >= 0) {
PatBlt (hdc, SPLEFT (sp->xdrag, sp->xwidth), 0, sp->xwidth, rc.bottom, PATINVERT);
sp->xdrag = pt.x;
PatBlt (hdc, SPLEFT (sp->xdrag, sp->xwidth), 0, sp->xwidth, rc.bottom, PATINVERT);
}
if (sp->ydrag >= 0) {
PatBlt (hdc, 0, SPTOP (sp->ydrag, sp->ywidth), rc.right, sp->ywidth, PATINVERT);
}
SelectObject (hdc, hbr);
ReleaseDC (hSplitter, hdc);
}
return TRUE;
case WM_SETCURSOR:
dw = GetMessagePos ();
pt.x = GET_X_LPARAM (dw);
pt.y = GET_Y_LPARAM (dw);
ScreenToClient (hSplitter, &pt);
if (CURSORPOS_OK (pt.x, sp->xpos, sp->xwidth)) {
if (CURSORPOS_OK (pt.y, sp->ypos, sp->ywidth))
SetCursor (hcurBoth);
else
SetCursor (hcurHorz);
return TRUE;
}
else
if (CURSORPOS_OK (pt.y, sp->ypos, sp->ywidth)) {
SetCursor (hcurVert);
return TRUE;
}
break;
case WM_SIZE:
SpPositionViewWindows (hSplitter);
break;
case CCSPM_GETHANDLE:
switch (wParam) {
case CCSPV_TOPLEFT:
case CCSPV_TOPRIGHT:
case CCSPV_BOTTOMLEFT:
case CCSPV_BOTTOMRIGHT:
return (LRESULT)sp->hView[wParam];
}
return (LRESULT)NULL;
case CCSPM_GETRECT:
return SpGetRect (hSplitter, wParam, (RECT *)lParam);
case CCSPM_GETSPLIT:
if ((spx = (CCSPLIT *)wParam) != NULL)
if (spx->cbSize != sizeof (*spx))
return FALSE;
if ((spy = (CCSPLIT *)lParam) != NULL)
if (spy->cbSize != sizeof (*spy))
return FALSE;
if (spx) {
spx->flags = CCSP_POS|CCSP_LOWER|CCSP_UPPER|CCSP_WIDTH;
spx->pos = sp->xpos;
spx->lower = sp->xlower;
spx->upper = sp->xupper;
spx->width = sp->xwidth;
}
if (spy) {
spy->flags = CCSP_POS|CCSP_LOWER|CCSP_UPPER|CCSP_WIDTH;
spy->pos = sp->ypos;
spy->lower = sp->ylower;
spy->upper = sp->yupper;
spy->width = sp->ywidth;
}
return TRUE;
case CCSPM_SETHANDLE:
switch (wParam) {
case CCSPV_TOPLEFT:
case CCSPV_TOPRIGHT:
case CCSPV_BOTTOMLEFT:
case CCSPV_BOTTOMRIGHT:
if ((HWND)lParam == NULL || IsWindow ((HWND)lParam))
{
if (sp->hView[wParam] != NULL && sp->hView[wParam] != (HWND)lParam)
ShowWindow (sp->hView[wParam], SW_HIDE);
sp->hView[wParam] = (HWND)lParam;
SetWindowPos (hSplitter, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOSIZE);
SpPositionViewWindows (hSplitter);
return TRUE;
}
break;
}
return FALSE;
case CCSPM_SETSPLIT:
GetClientRect (hSplitter, &rc);
if ((spx = (CCSPLIT *)wParam) != NULL)
if (spx->cbSize != sizeof (*spx))
return FALSE;
if ((spy = (CCSPLIT *)lParam) != NULL)
if (spy->cbSize != sizeof (*spy))
return FALSE;
if (spx) {
if (spx->flags & CCSP_FPOS) sp->xpos = spx->pos * rc.right / 100;
if (spx->flags & CCSP_POS) sp->xpos = spx->pos;
if (sp->xpos <= 0) sp->xpos = -1;
if (spx->flags & CCSP_FLOWER) sp->xlower = spx->lower * rc.right / 100;
if (spx->flags & CCSP_LOWER) sp->xlower = spx->lower;
if (sp->xlower <= 0) sp->xlower = 0;
if (spx->flags & CCSP_FUPPER) sp->xupper = spx->upper * rc.right / 100;
if (spx->flags & CCSP_UPPER) sp->xupper = spx->upper;
if (sp->xupper <= 0) sp->xupper = 0;
if (spx->flags & CCSP_WIDTH) sp->xwidth = spx->width;
if (sp->xwidth < CCSP_DEFWIDTH) sp->xwidth = CCSP_DEFWIDTH;
}
if (spy) {
if (spy->flags & CCSP_FPOS) sp->ypos = spy->pos * rc.bottom / 100;
if (spy->flags & CCSP_POS) sp->ypos = spy->pos;
if (sp->ypos <= 0) sp->ypos = -1;
if (spy->flags & CCSP_FLOWER) sp->ylower = spy->lower * rc.bottom / 100;
if (spy->flags & CCSP_LOWER) sp->ylower = spy->lower;
if (sp->ylower <= 0) sp->ylower = 0;
if (spy->flags & CCSP_FUPPER) sp->yupper = spy->upper * rc.bottom / 100;
if (spy->flags & CCSP_UPPER) sp->yupper = spy->upper;
if (sp->yupper <= 0) sp->yupper = 0;
if (spy->flags & CCSP_WIDTH) sp->ywidth = spy->width;
if (sp->ywidth < CCSP_DEFWIDTH) sp->ywidth = CCSP_DEFWIDTH;
}
SpPositionViewWindows (hSplitter);
SpNotifyParent (hSplitter, CCSPN_SPLITCHANGED, sp->xpos>=0, sp->ypos>=0);
return TRUE;
}
return DefWindowProc (hSplitter, uMsg, wParam, lParam);
}
/********************************************************************************/
/* Private procedure definitions - utility functions */
/********************************************************************************/
static int SpGetRect (
HWND hSplitter, // Splitter window handle
int id, // Rectangle ID
RECT *prc) // Rectangle data ptr
{
RECT rc; // Window rectangle
SPINFO *sp; // Splitter info ptr
if (prc == NULL)
return FALSE;
SetRect (prc, 0, 0, 0, 0);
GetClientRect (hSplitter, &rc);
sp = (SPINFO *)GetWindowLong (hSplitter, GWL_SPINFO);
switch (id) {
case CCSPV_TOPLEFT:
prc->left = 0;
prc->top = 0;
prc->right = sp->xpos>=0 ? SPLEFT (sp->xpos, sp->xwidth) : rc.right;
prc->bottom = sp->ypos>=0 ? SPTOP (sp->ypos, sp->ywidth) : rc.bottom;
return TRUE;
case CCSPV_TOPRIGHT:
if (sp->xpos < 0)
break;
prc->left = SPRIGHT (sp->xpos, sp->xwidth);
prc->top = 0;
prc->right = rc.right;
prc->bottom = sp->ypos>=0 ? SPTOP (sp->ypos, sp->ywidth) : rc.bottom;
return TRUE;
case CCSPV_BOTTOMLEFT:
if (sp->ypos < 0)
break;
prc->left = 0;
prc->top = SPBOTTOM (sp->ypos, sp->ywidth);
prc->right = sp->xpos>=0 ? SPLEFT (sp->xpos, sp->xwidth) : rc.right;
prc->bottom = rc.bottom;
return TRUE;
case CCSPV_BOTTOMRIGHT:
if (sp->ypos < 0 || sp->xpos < 0)
break;
prc->left = SPRIGHT (sp->xpos, sp->xwidth);
prc->top = SPBOTTOM (sp->ypos, sp->ywidth);
prc->right = rc.right;
prc->bottom = rc.bottom;
return TRUE;
}
// Rectangle does not exist...
return FALSE;
}
static void SpNotifyParent (
HWND hSplitter, // Splitter window handle
int code, // Notification code
int xParam, // X-parameter to notification
int yParam) // Y-parameter to notification
{
NMCCSPLIT notify; // Notification data
notify.hdr.hwndFrom = hSplitter;
notify.hdr.idFrom = GetWindowLong (hSplitter, GWL_ID);
notify.hdr.code = code;
notify.x = xParam;
notify.y = yParam;
SendMessage (GetParent (hSplitter), WM_NOTIFY, notify.hdr.idFrom, (LPARAM)¬ify);
}
static void SpPositionViewWindows (
HWND hSplitter) // Splitter window handle
{
SPINFO *sp; // Splitter info ptr
HDWP hDefer; // DeferWindowPos handle
RECT rc; // View window rectangle
int i; // Loop counter
sp = (SPINFO *)GetWindowLong (hSplitter, GWL_SPINFO);
hDefer = BeginDeferWindowPos (NVIEWS);
for (i=0; i<NVIEWS; i++) {
if (sp->hView[i] == NULL)
continue;
if (SpGetRect (hSplitter, i, &rc)) {
MapWindowPoints (hSplitter, GetParent (sp->hView[i]), (POINT *)&rc, 2);
hDefer = DeferWindowPos (hDefer, sp->hView[i], NULL, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, SWP_NOZORDER|SWP_NOACTIVATE|SWP_SHOWWINDOW);
} else {
ShowWindow (sp->hView[i], SW_HIDE);
}
}
EndDeferWindowPos (hDefer);
SpNotifyParent (hSplitter, CCSPN_POSCHANGED, sp->xpos, sp->ypos);
}
/********************************************************************************/
/* End of file */
/********************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -