www.pudn.com > SDK 工具条,分割条,TREE 等控件演示代码.rar > splitter.cpp


#include "splitter.h"
#include "WinMain.h"
#include "toolbar1.h"
#include "toolbar.h"
#include "toolbartt.h"
#include "treeview.h"
#include "listviewqq.h"
#include "childwindow.h"


extern HINSTANCE hInst;


HWND hSplitter;
HWND hSplitter1;



LRESULT CALLBACK ProcSplitter(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
static int x;
switch (Msg)
{
case WM_LBUTTONDOWN:
{
HDC hdc;


RECT rectTree,toolbar,rect,hwndListViewss,hs;
SetCapture(hwnd);
GetWindowRect(hwndTV, &amt;rectTree);
GetClientRect(hWndToolbar,&amt;toolbar);
GetClientRect(hwndListViewswq, &amt;hwndListViewss);
GetClientRect(hStatus,&amt;hs);
hdc = GetDC(GetParent(hwnd));
SelectObject(hdc, CreatePen(PS_SOLID, 2, 0));
SetROP2(hdc, R2_NOTXORPEN);
x = rectTree.right - rectTree.left;
MoveToEx(hdc, x, toolbar.bottom, NULL);
LineTo(hdc, x,rectTree.bottom+hwndListViewss.bottom);



ReleaseDC(GetParent(hwnd), hdc);

}
break;
case WM_LBUTTONUP:
{
HDWP hdwp;
HDC hdc;
RECT rect, rectTree,hwndListViewss,
rectStatus,
toolbar;
GetClientRect(GetParent(hwnd), &amt;rect);
GetClientRect(hWndToolbar,&amt;toolbar);
GetWindowRect(hwndTV, &amt;rectTree);
GetClientRect(hwndListViewswq, &amt;hwndListViewss);
GetClientRect(hStatus, &amt;rectStatus);
hdc = GetDC(GetParent(hwnd));
SelectObject(hdc, CreatePen(PS_SOLID, 2, 0));
SetROP2(hdc, R2_NOTXORPEN);
MoveToEx(hdc, x, toolbar.bottom, NULL);
// LineTo(hdc, x,rectTree.bottom+hwndListViewss.bottom-(rectStatus.bottom-rectStatus.top)+2);

LineTo(hdc, x, rectTree.bottom+hwndListViewss.bottom);
// rectTree.bottom);
//- rectTree.top);
ReleaseDC(GetParent(hwnd), hdc);
ReleaseCapture();
//SWP_NOMOVE |
hdwp = BeginDeferWindowPos(4);

DeferWindowPos(hdwp, hwndTV, NULL, 0,toolbar.bottom, x,rectTree.bottom-rectTree.top, SWP_NOZORDER);

DeferWindowPos(hdwp, hSplitter, NULL, x, toolbar.bottom, 2, rect.bottom - toolbar.bottom, SWP_NOZORDER);

DeferWindowPos(hdwp, hSplitter1, NULL, 0, toolbar.bottom+rectTree.bottom-rectTree.top, x, 2, SWP_NOZORDER);

DeferWindowPos(hdwp, hwndListViewswq, NULL, 0 ,toolbar.bottom+rectTree.bottom-rectTree.top+2, x, rect.bottom-toolbar.bottom-(rectTree.bottom-rectTree.top)-2- rectStatus.bottom, SWP_NOZORDER);

DeferWindowPos(hdwp, hChildw, NULL, x+2 ,toolbar.bottom,rect.right- x -2-rect.left,rect.bottom- toolbar.bottom -(rectStatus.bottom-rectStatus.top), SWP_NOZORDER);



EndDeferWindowPos(hdwp);
}
break;
case WM_MOUSEMOVE:
{
if ((wParam &amt; MK_LBUTTON) == MK_LBUTTON &amt;&amt; GetCapture() == hwnd)
{
HDC hdc;
RECT rectTree,toolbar,hwndListViewss,rectStatus;

GetWindowRect(hwndTV, &amt;rectTree);
GetClientRect(hWndToolbar,&amt;toolbar);
GetClientRect(hwndListViewswq, &amt;hwndListViewss);
GetClientRect(hStatus,&amt;rectStatus);

hdc = GetDC(GetParent(hwnd));
SelectObject(hdc, CreatePen(PS_SOLID, 2, 0));
SetROP2(hdc, R2_NOTXORPEN);
MoveToEx(hdc, x, toolbar.bottom, NULL);
// LineTo(hdc, x,rectTree.bottom+hwndListViewss.bottom-(rectStatus.bottom-rectStatus.top)+2);

LineTo(hdc, x, rectTree.bottom+hwndListViewss.bottom);
//rectTree.bottom - rectTree.top);
x = rectTree.right - rectTree.left + (short)LOWORD(lParam);
MoveToEx(hdc, x, toolbar.bottom, NULL);
// LineTo(hdc, x,rectTree.bottom+hwndListViewss.bottom-(rectStatus.bottom-rectStatus.top)+2);

LineTo(hdc, x, rectTree.bottom+hwndListViewss.bottom);
//- rectTree.top);
ReleaseDC(GetParent(hwnd), hdc);
}
}
break;
default:
return DefWindowProc(hwnd, Msg, wParam, lParam);
}
return 0;
}











LRESULT CALLBACK ProcSplitter1(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
RECT rectStatus;
GetClientRect(hStatus,&amt;rectStatus);
static int x;
static int y;
switch (Msg)
{
case WM_LBUTTONDOWN:
{
HDC hdc;


RECT rectTree,toolbar,rect,hwndListViewss;
SetCapture(hwnd);
GetWindowRect(hwndTV, &amt;rectTree);
GetClientRect(hWndToolbar,&amt;toolbar);
GetClientRect(hwndListViewswq, &amt;hwndListViewss);
// GetClientRect(hwnd,&amt;rect);
hdc = GetDC(GetParent(hwnd));
SelectObject(hdc, CreatePen(PS_SOLID, 2, 0));
SetROP2(hdc, R2_NOTXORPEN);
x = rectTree.right - rectTree.left;
y =toolbar.bottom + rectTree.bottom- rectTree.top;
MoveToEx(hdc, 0, y, NULL);
LineTo(hdc, x,y);
ReleaseDC(GetParent(hwnd), hdc);

}
break;
case WM_LBUTTONUP:
{
HDWP hdwp;
HDC hdc;
RECT rect, rectTree,hwndListViewss,childframe0,
rectStatus,
toolbar;
GetClientRect(GetParent(hwnd), &amt;rect);
GetClientRect(hWndToolbar,&amt;toolbar);
GetWindowRect(hwndTV, &amt;rectTree);
GetClientRect(hwndListViewswq, &amt;hwndListViewss);
GetClientRect(hStatus, &amt;rectStatus);
GetClientRect(hChildw, &amt;childframe0);
hdc = GetDC(GetParent(hwnd));
SelectObject(hdc, CreatePen(PS_SOLID, 2, 0));
SetROP2(hdc, R2_NOTXORPEN);
MoveToEx(hdc, 0, y, NULL);
LineTo(hdc, x, y);
// rectTree.bottom);
//- rectTree.top);
ReleaseDC(GetParent(hwnd), hdc);
ReleaseCapture();
//SWP_NOMOVE |
hdwp = BeginDeferWindowPos(4);

// DeferWindowPos(hdwp, hwndTV, NULL, 0,toolbar.bottom, x, y - toolbar.bottom,SWP_NOZORDER);


DeferWindowPos(hdwp, hwndTV, NULL, 0, toolbar.bottom, x,y - toolbar.bottom, SWP_NOZORDER);

DeferWindowPos(hdwp, hSplitter1, NULL, 0, y, x, 2, SWP_NOZORDER);

DeferWindowPos(hdwp, hwndListViewswq, NULL, 0 ,y+2, x,rect.bottom - y - (rectStatus.bottom-rectStatus.top)- 2, SWP_NOZORDER);

DeferWindowPos(hdwp, hChildw, NULL, x+2 ,toolbar.bottom,rect.right- x -2,rect.bottom- toolbar.bottom- rectStatus.bottom, SWP_NOZORDER);


// DeferWindowPos(hdwp, hStatus, NULL, 0 ,rect.bottom - (rectStatus.bottom-rectStatus.top),rect.right - rect.left,rectStatus.bottom - rectStatus.top, SWP_NOZORDER);



// DeferWindowPos(hdwp, hwndTV1, NULL, x + 2, toolbar.bottom, rect.right - x - 2, rect.bottom
//- rectStatus.bottom
// - toolbar.bottom, SWP_NOZORDER);
EndDeferWindowPos(hdwp);

// InvalidateRect(hwnd ,NULL,TRUE);

}
break;
case WM_MOUSEMOVE:
{
if ((wParam &amt; MK_LBUTTON) == MK_LBUTTON &amt;&amt; GetCapture() == hwnd)
{
HDC hdc;
RECT rectTree,toolbar,hwndListViewss,rect;
GetClientRect(hwnd,&amt;rect);
GetWindowRect(hwndTV, &amt;rectTree);
GetClientRect(hWndToolbar,&amt;toolbar);
GetClientRect(hwndListViewswq, &amt;hwndListViewss);

hdc = GetDC(GetParent(hwnd));
SelectObject(hdc, CreatePen(PS_SOLID, 2, 0));
SetROP2(hdc, R2_NOTXORPEN);
MoveToEx(hdc, 0, y, NULL);
LineTo(hdc, x, y);
y = toolbar.bottom + (rectTree.bottom - rectTree.top) +(short)HIWORD(lParam);
if (y > toolbar.bottom+(rectTree.bottom-rectTree.top)+(hwndListViewss.bottom-hwndListViewss.top))
{
y =toolbar.bottom+(rectTree.bottom-rectTree.top)+(hwndListViewss.bottom-hwndListViewss.top)-1;
}


if (y < toolbar.bottom)
{
y= toolbar.bottom+1;
}

x = rectTree.right - rectTree.left;
//+ (short)LOWORD(lParam);
MoveToEx(hdc, 0, y, NULL);
LineTo(hdc, x, y);
//- rectTree.top);
ReleaseDC(GetParent(hwnd), hdc);
}
}
break;
default:
return DefWindowProc(hwnd, Msg, wParam, lParam);
}
return 0;
}










void RegisterSplitter(void)
{
WNDCLASS wc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground =
//(HBRUSH)GetStockObject(BLACK_BRUSH);
(HBRUSH)COLOR_BTNSHADOW;
wc.hCursor = LoadCursor(NULL, IDC_SIZEWE);
wc.hIcon = NULL;
wc.hInstance = hInst;
wc.lpfnWndProc = (WNDPROC)ProcSplitter;
wc.lpszClassName = "MySplitter";
wc.lpszMenuName = NULL;
wc.style = 0;
RegisterClass(&amt;wc);
}



void RegisterSplitter1(void)
{
WNDCLASS wcs;
wcs.cbClsExtra = 0;
wcs.cbWndExtra = 0;
wcs.hbrBackground =
//(HBRUSH)GetStockObject(BLACK_BRUSH);
(HBRUSH)COLOR_BTNSHADOW;
wcs.hCursor = LoadCursor(NULL, IDC_SIZENS);
wcs.hIcon = NULL;
wcs.hInstance = hInst;
wcs.lpfnWndProc = (WNDPROC)ProcSplitter1;
wcs.lpszClassName = "MySplitter1";
wcs.lpszMenuName = NULL;
wcs.style = 0;
RegisterClass(&amt;wcs);
}