我现在在单文档视图中添加了几个按钮,每个按钮单击时弹出一个对话框,在对话框中有一些控件,如列表控件、树型控件、编辑控件等,我现在要做到如PP点通界面那样,可以上下拖动,或左右拖动,请问怎么样添加分隔条?如要做到左右拖动,是不是要把左边的控件组放在一个对话框,右边的放在一个对话框,再在中间加分隔条,那应该怎么实现了?有源码更好,多谢帮忙!
解决方案 »
- opc读一次数据,内存就会增加4k,郁闷中...
- 请问:金山卫士这个等待的效果怎么做出来的?
- WSARecv Recv和WSARecvEX的区别是什么
- 如何获取 XML 中的数据
- 请问:大家知道有什么Image DLL可以下在?
- 高手飘过,如何让DialogBar相应鼠标消息?
- 关于"Visual C++中使用OLE DB读写SQL Server简明指南 "的问题
- 关于进程间通讯的问题?
- wrcluomo(落木)、hglcsdn(中文hgl)感谢对我的支持,来领分吧
- vc学的好郁闷啊,散点分发泄一下。
- 请问华为的MT800 ADSL 登陆192.168.1.1 的用户名和密码?
- 求助:播放一段AVI,要循环全屏播放。100分
// 创建分隔条
HWND cwlCreateSplitter(HWND hwndParent, LPRECT lprcWorkArea, HWND hLeftOrTopWnd,
HWND hRightOrBottomWnd, BOOL bLeftToRight)
{
ASSERT(IsWindow(hLeftOrTopWnd));
ASSERT(IsWindow(hRightOrBottomWnd));
#ifdef _DEBUG
RECT rect;
GetWindowRect(hLeftOrTopWnd, &rect);
if (bLeftToRight) {
if (GetRectCX(rect) + lprcWorkArea->left > lprcWorkArea->right) {
ASSERT(FALSE);
return NULL;
}
} else {
if (GetRectCY(rect) + lprcWorkArea->top > lprcWorkArea->bottom) {
ASSERT(FALSE);
return NULL;
}
}
#endif tagSplitterData* pSplitterData = new tagSplitterData;
if (pSplitterData == NULL) { return NULL; }
pSplitterData->hLOT = hLeftOrTopWnd;
pSplitterData->hROB = hRightOrBottomWnd;
pSplitterData->bLOR = bLeftToRight;
pSplitterData->top = lprcWorkArea->top;
pSplitterData->left = lprcWorkArea->left;
pSplitterData->right = lprcWorkArea->right;
pSplitterData->bottom = lprcWorkArea->bottom;
pSplitterData->hParent = hwndParent;
pSplitterData->current = 0;
pSplitterData->hPenObj = NULL;
LPCTSTR Splitter = NULL;
if (bLeftToRight) {
Splitter = TEXT("Cmnlib_HSplitter");
} else {
Splitter = TEXT("Cmnlib_VSplitter");
} WNDCLASSEX wcex;
wcex.cbSize = sizeof(wcex);
if (!GetClassInfoEx(cwlGetInstanceHandle(), Splitter, &wcex)) {
wcex.cbClsExtra = 0;
wcex.cbWndExtra = sizeof(tagSplitterData*);
wcex.hbrBackground = (HBRUSH)COLOR_BTNSHADOW;
wcex.hCursor = LoadCursor(NULL, bLeftToRight ? IDC_SIZEWE : IDC_SIZENS);
wcex.hIcon = wcex.hIconSm = NULL;
wcex.hInstance = cwlGetInstanceHandle();
wcex.lpfnWndProc = (WNDPROC)_SplitterProc_;
wcex.lpszMenuName = NULL;
wcex.lpszClassName = Splitter;
wcex.style = 0;
if (NULL == RegisterClassEx(&wcex)) {
delete pSplitterData;
return NULL;
}
} HWND hWndTemp = CreateWindowEx(0, Splitter, NULL, WS_CHILD | WS_VISIBLE,
0, 0, 0, 0, hwndParent, NULL, cwlGetInstanceHandle(),
(LPVOID)pSplitterData);
if (hWndTemp == NULL) {
delete pSplitterData;
return NULL;
} else {
cwlAdjustSplitter(hWndTemp);
}
return hWndTemp;
}
//========================================================================
// 调整分隔条
BOOL cwlAdjustSplitter(HWND hWnd)
{
tagSplitterData* pSplitterData;
pSplitterData = (tagSplitterData*)GetWindowLong(hWnd, 0);
if (pSplitterData == NULL) {
return FALSE;
}
HDWP hdwp = BeginDeferWindowPos(3);
RECT rcLOT;
GetWindowRect(pSplitterData->hLOT, &rcLOT);
int cx = GetRectCX(rcLOT);
int cy = GetRectCY(rcLOT);
if (pSplitterData->bLOR) { // 从左到右
DeferWindowPos(hdwp, pSplitterData->hLOT, NULL,
pSplitterData->left, pSplitterData->top,cx,
pSplitterData->bottom - pSplitterData->top,
SWP_NOZORDER);
DeferWindowPos(hdwp, hWnd, NULL, pSplitterData->left + cx,
pSplitterData->top, 2, pSplitterData->bottom -
pSplitterData->top, SWP_NOZORDER);
DeferWindowPos(hdwp, pSplitterData->hROB, NULL,
pSplitterData->left + cx + 2, pSplitterData->top,
pSplitterData->right - pSplitterData->left - cx - 2,
pSplitterData->bottom - pSplitterData->top,
SWP_NOZORDER);
} else { // 从上到下
DeferWindowPos(hdwp, pSplitterData->hLOT, NULL,
pSplitterData->left, pSplitterData->top,
pSplitterData->right - pSplitterData->left,
cy, SWP_NOZORDER);
DeferWindowPos(hdwp, hWnd, NULL, pSplitterData->left,
pSplitterData->top + cy, pSplitterData->right -
pSplitterData->left, 2, SWP_NOZORDER);
DeferWindowPos(hdwp, pSplitterData->hROB, NULL,
pSplitterData->left, pSplitterData->top + cy + 2,
pSplitterData->right - pSplitterData->left,
pSplitterData->bottom - pSplitterData->top - cy - 2,
SWP_NOZORDER);
}
EndDeferWindowPos(hdwp);
return TRUE;
}
{
switch(uMsg) {
case WM_CREATE:
{
LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
SetWindowLong(hWnd, 0, (LONG)lpcs->lpCreateParams);/*
RECT rcWnd;
GetWindowRect(hWnd, &rcWnd);
*/ tagSplitterData* pSplitterData;
pSplitterData = (tagSplitterData*)lpcs->lpCreateParams;
if (pSplitterData->bLOR) {
pSplitterData->hPenObj = CreatePen(PS_SOLID,
2/* GetRectCX(rcWnd) */, 0);
} else {
pSplitterData->hPenObj = CreatePen(PS_SOLID,
2/* GetRectCY(rcWnd) */, 0);
}
}
break; case WM_NCDESTROY:
{
tagSplitterData* pSplitterData;
pSplitterData = (tagSplitterData*)GetWindowLong(hWnd, 0);
if (pSplitterData) {
DeletePen(pSplitterData->hPenObj);
delete pSplitterData;
}
}
break; case WM_LBUTTONDOWN:
{
tagSplitterData* pSplitterData;
pSplitterData = (tagSplitterData*)GetWindowLong(hWnd, 0);
if (pSplitterData == NULL) { break; } SetCapture(hWnd); RECT rcLOT;
GetWindowRect(pSplitterData->hLOT, &rcLOT); HDC hdc = GetDC(pSplitterData->hParent);
HPEN pen = SelectPen(hdc, pSplitterData->hPenObj);
int rop = SetROP2(hdc, R2_NOTXORPEN); if (pSplitterData->bLOR) {
pSplitterData->current = pSplitterData->left + GetRectCX(rcLOT);
MoveToEx(hdc, pSplitterData->current, pSplitterData->top,
NULL);
LineTo(hdc, pSplitterData->current, pSplitterData->bottom);
} else {
pSplitterData->current = pSplitterData->top + GetRectCY(rcLOT);
MoveToEx(hdc, pSplitterData->left, pSplitterData->current,
NULL);
LineTo(hdc, pSplitterData->right, pSplitterData->current);
} SetROP2(hdc, rop);
SelectPen(hdc, pen);
ReleaseDC(pSplitterData->hParent, hdc);
}
break; case WM_LBUTTONUP:
{
tagSplitterData* pSplitterData;
pSplitterData = (tagSplitterData*)GetWindowLong(hWnd, 0);
if (pSplitterData == NULL) { break; } HDC hdc = GetDC(pSplitterData->hParent);
HPEN pen = SelectPen(hdc, pSplitterData->hPenObj);
int rop = SetROP2(hdc, R2_NOTXORPEN);
if (pSplitterData->bLOR) {
MoveToEx(hdc, pSplitterData->current, pSplitterData->top,
NULL);
LineTo(hdc, pSplitterData->current, pSplitterData->bottom);
} else {
MoveToEx(hdc, pSplitterData->left, pSplitterData->current,
NULL);
LineTo(hdc, pSplitterData->right, pSplitterData->current);
}
SetROP2(hdc, rop);
SelectPen(hdc, pen);
ReleaseDC(pSplitterData->hParent, hdc); ReleaseCapture(); HDWP hdwp = BeginDeferWindowPos(3);
if (pSplitterData->bLOR) { // 从左到右
DeferWindowPos(hdwp, pSplitterData->hLOT, NULL, 0, 0,
pSplitterData->current - pSplitterData->left,
pSplitterData->bottom - pSplitterData->top,
SWP_NOMOVE | SWP_NOZORDER); DeferWindowPos(hdwp, hWnd, NULL, pSplitterData->current,
pSplitterData->top, 0, 0, SWP_NOSIZE | SWP_NOZORDER); DeferWindowPos(hdwp, pSplitterData->hROB, NULL,
pSplitterData->current + 2, pSplitterData->top,
pSplitterData->right - pSplitterData->current - 2,
pSplitterData->bottom - pSplitterData->top,
SWP_NOZORDER);
} else { // 从上到下
DeferWindowPos(hdwp, pSplitterData->hLOT, NULL, 0, 0,
pSplitterData->right - pSplitterData->left,
pSplitterData->current - pSplitterData->top,
SWP_NOMOVE | SWP_NOZORDER);
DeferWindowPos(hdwp, hWnd, NULL, pSplitterData->left,
pSplitterData->current,0,0,SWP_NOSIZE | SWP_NOZORDER);
DeferWindowPos(hdwp, pSplitterData->hROB, NULL,
pSplitterData->left, pSplitterData->current + 2,
pSplitterData->right - pSplitterData->left,
pSplitterData->bottom - pSplitterData->current - 2,
SWP_NOZORDER);
}
EndDeferWindowPos(hdwp);
}
break; case WM_MOUSEMOVE:
if ((wParam & MK_LBUTTON) == MK_LBUTTON && GetCapture() == hWnd)
{
tagSplitterData* pSplitterData;
pSplitterData = (tagSplitterData*)GetWindowLong(hWnd, 0);
if (pSplitterData == NULL) { break; }
RECT rcLOT;
GetWindowRect(pSplitterData->hLOT, &rcLOT);
HDC hdc = GetDC(pSplitterData->hParent);
HPEN pen = SelectPen(hdc, pSplitterData->hPenObj);
int rop = SetROP2(hdc, R2_NOTXORPEN);
if (pSplitterData->bLOR) {
MoveToEx(hdc, pSplitterData->current, pSplitterData->top,
NULL);
LineTo(hdc, pSplitterData->current, pSplitterData->bottom); pSplitterData->current = pSplitterData->left +
GetRectCX(rcLOT) + (short)LOWORD(lParam);
if (pSplitterData->current < pSplitterData->left + 4) {
pSplitterData->current = pSplitterData->left + 4;
}
if (pSplitterData->current > pSplitterData->right - 6)
{
pSplitterData->current = pSplitterData->right - 6;
} MoveToEx(hdc, pSplitterData->current, pSplitterData->top,
NULL);
LineTo(hdc, pSplitterData->current, pSplitterData->bottom);
} else {
MoveToEx(hdc, pSplitterData->left, pSplitterData->current,
NULL);
LineTo(hdc, pSplitterData->right, pSplitterData->current); pSplitterData->current = pSplitterData->top +
GetRectCY(rcLOT) + (short)HIWORD(lParam);
if (pSplitterData->current < pSplitterData->top + 4) {
pSplitterData->current = pSplitterData->top + 4;
}
if (pSplitterData->current > pSplitterData->bottom - 6) {
pSplitterData->current = pSplitterData->bottom - 6;
} MoveToEx(hdc, pSplitterData->left, pSplitterData->current,
NULL);
LineTo(hdc, pSplitterData->right, pSplitterData->current);
}
SetROP2(hdc, rop);
SelectPen(hdc, pen);
ReleaseDC(pSplitterData->hParent, hdc);
}
return 0; default:
break;
} return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
对话框怎么做到切分窗口呢?
HWND hLOT;
HWND hROB;
BOOL bLOR;
LONG top;
LONG left;
LONG right;
LONG bottom; LONG current;
HWND hParent;
HPEN hPenObj;
};
BOOL cwlAdjustSplitter(HWND hWnd);
HWND cwlCreateSplitter(HWND hwndParent, LPRECT lprcWorkArea, HWND hLeftOrTopWnd,
HWND hRightOrBottomWnd, BOOL bLeftToRight);代码放在 CPP 文件中。
#define GetRectCY(rect) (rect.bottom - rect.top)将 cwlGetInstanceHandle 改为 AfxGetInstanceHandle另外,我的这个代码是在 SDK 下写的,如果你要在 MFC 中使用,需要进行一下转换。
SplitterBar.cpp
D:\MyProgram\WantLink\SplitterBar.cpp(152) : error C2724: '_SplitterProc_' : 'static' should not be used on member functions defined at file scope
D:\MyProgram\WantLink\SplitterBar.cpp(181) : error C2065: 'DeletePen' : undeclared identifier
D:\MyProgram\WantLink\SplitterBar.cpp(193) : error C2660: 'SetCapture' : function does not take 1 parameters
D:\MyProgram\WantLink\SplitterBar.cpp(196) : error C2660: 'GetWindowRect' : function does not take 2 parameters
D:\MyProgram\WantLink\SplitterBar.cpp(198) : error C2660: 'GetDC' : function does not take 1 parameters
D:\MyProgram\WantLink\SplitterBar.cpp(199) : error C2065: 'SelectPen' : undeclared identifier
D:\MyProgram\WantLink\SplitterBar.cpp(199) : error C2440: 'initializing' : cannot convert from 'int' to 'struct HPEN__ *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
D:\MyProgram\WantLink\SplitterBar.cpp(216) : error C2660: 'ReleaseDC' : function does not take 2 parameters
D:\MyProgram\WantLink\SplitterBar.cpp(226) : error C2660: 'GetDC' : function does not take 1 parameters
D:\MyProgram\WantLink\SplitterBar.cpp(227) : error C2440: 'initializing' : cannot convert from 'int' to 'struct HPEN__ *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
D:\MyProgram\WantLink\SplitterBar.cpp(242) : error C2660: 'ReleaseDC' : function does not take 2 parameters
D:\MyProgram\WantLink\SplitterBar.cpp(281) : error C2446: '==' : no conversion from 'struct HWND__ *' to 'class CWnd *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
D:\MyProgram\WantLink\SplitterBar.cpp(281) : error C2230: '==' : indirection to different types
D:\MyProgram\WantLink\SplitterBar.cpp(288) : error C2660: 'GetWindowRect' : function does not take 2 parameters
D:\MyProgram\WantLink\SplitterBar.cpp(290) : error C2660: 'GetDC' : function does not take 1 parameters
D:\MyProgram\WantLink\SplitterBar.cpp(291) : error C2440: 'initializing' : cannot convert from 'int' to 'struct HPEN__ *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
D:\MyProgram\WantLink\SplitterBar.cpp(333) : error C2660: 'ReleaseDC' : function does not take 2 parameters
D:\MyProgram\WantLink\SplitterBar.cpp(341) : error C2660: 'DefWindowProcA' : function does not take 4 parameters
Error executing cl.exe.SplitterBar.obj - 18 error(s), 0 warning(s)
并且还有一些错误
-----------------Configuration: WantLink - Win32 Debug--------------------
Compiling...
SplitterBar.cpp
D:\MyProgram\WantLink\SplitterBar.cpp(181) : error C2065: 'DeletePen' : undeclared identifier
D:\MyProgram\WantLink\SplitterBar.cpp(199) : error C2065: 'SelectPen' : undeclared identifier
D:\MyProgram\WantLink\SplitterBar.cpp(199) : error C2440: 'initializing' : cannot convert from 'int' to 'struct HPEN__ *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
D:\MyProgram\WantLink\SplitterBar.cpp(227) : error C2440: 'initializing' : cannot convert from 'int' to 'struct HPEN__ *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
D:\MyProgram\WantLink\SplitterBar.cpp(291) : error C2440: 'initializing' : cannot convert from 'int' to 'struct HPEN__ *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.SplitterBar.obj - 5 error(s), 0 warning(s)
#define Splitter_Needways_2004_07_01_15_13
#pragma onceBOOL cwlAdjustSplitter(HWND hWnd);
HWND cwlCreateSplitter(HWND hwndParent, LPRECT lprcWorkArea,
HWND hLeftOrTopWnd, HWND hRightOrBottomWnd, BOOL bLeftToRight);#endif
#include "stdafx.h"
#include "windowsx.h"struct tagSplitterData {
HWND hLOT;
HWND hROB;
BOOL bLOR;
LONG top;
LONG left;
LONG right;
LONG bottom; LONG current;
HWND hParent;
HPEN hPenObj;
};// 宏定义
#define GetRectCX(rect) (rect.right - rect.left)
#define GetRectCY(rect) (rect.bottom - rect.top)// 函数原型
static LONG CALLBACK _SplitterProc_(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
出现如下错误:--------------------Configuration: WantLink - Win32 Debug--------------------
Compiling...
SplitterBar.cpp
D:\MyProgram\WantLink\SplitterBar.cpp(152) : error C2724: '_SplitterProc_' : 'static' should not be used on member functions defined at file scope
D:\MyProgram\WantLink\SplitterBar.cpp(281) : error C2446: '==' : no conversion from 'struct HWND__ *' to 'class CWnd *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
D:\MyProgram\WantLink\SplitterBar.cpp(281) : error C2230: '==' : indirection to different types
Error executing cl.exe.
//========================================================================
// 分割窗口的窗口处理程序
static LONG CALLBACK _SplitterProc_(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg) {
case WM_CREATE:
{
LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
SetWindowLong(hWnd, 0, (LONG)lpcs->lpCreateParams);/*
RECT rcWnd;
GetWindowRect(hWnd, &rcWnd);
*/ tagSplitterData* pSplitterData;
pSplitterData = (tagSplitterData*)lpcs->lpCreateParams;
if (pSplitterData->bLOR) {
pSplitterData->hPenObj = CreatePen(PS_SOLID,
2/* GetRectCX(rcWnd) */, 0);
} else {
pSplitterData->hPenObj = CreatePen(PS_SOLID,
2/* GetRectCY(rcWnd) */, 0);
}
}
break; case WM_NCDESTROY:
{
tagSplitterData* pSplitterData;
pSplitterData = (tagSplitterData*)GetWindowLong(hWnd, 0);
if (pSplitterData) {
DeletePen(pSplitterData->hPenObj);
delete pSplitterData;
}
}
break; case WM_LBUTTONDOWN:
{
tagSplitterData* pSplitterData;
pSplitterData = (tagSplitterData*)GetWindowLong(hWnd, 0);
if (pSplitterData == NULL) { break; } SetCapture(hWnd); RECT rcLOT;
GetWindowRect(pSplitterData->hLOT, &rcLOT); HDC hdc = GetDC(pSplitterData->hParent);
HPEN pen = SelectPen(hdc, pSplitterData->hPenObj);
int rop = SetROP2(hdc, R2_NOTXORPEN); if (pSplitterData->bLOR) {
pSplitterData->current = pSplitterData->left + GetRectCX(rcLOT);
MoveToEx(hdc, pSplitterData->current, pSplitterData->top,
NULL);
LineTo(hdc, pSplitterData->current, pSplitterData->bottom);
} else {
pSplitterData->current = pSplitterData->top + GetRectCY(rcLOT);
MoveToEx(hdc, pSplitterData->left, pSplitterData->current,
NULL);
LineTo(hdc, pSplitterData->right, pSplitterData->current);
} SetROP2(hdc, rop);
SelectPen(hdc, pen);
ReleaseDC(pSplitterData->hParent, hdc);
}
break; case WM_LBUTTONUP:
{
tagSplitterData* pSplitterData;
pSplitterData = (tagSplitterData*)GetWindowLong(hWnd, 0);
if (pSplitterData == NULL) { break; } HDC hdc = GetDC(pSplitterData->hParent);
HPEN pen = SelectPen(hdc, pSplitterData->hPenObj);
int rop = SetROP2(hdc, R2_NOTXORPEN);
if (pSplitterData->bLOR) {
MoveToEx(hdc, pSplitterData->current, pSplitterData->top,
NULL);
LineTo(hdc, pSplitterData->current, pSplitterData->bottom);
} else {
MoveToEx(hdc, pSplitterData->left, pSplitterData->current,
NULL);
LineTo(hdc, pSplitterData->right, pSplitterData->current);
}
SetROP2(hdc, rop);
SelectPen(hdc, pen);
ReleaseDC(pSplitterData->hParent, hdc); ReleaseCapture(); HDWP hdwp = BeginDeferWindowPos(3);
if (pSplitterData->bLOR) { // 从左到右
DeferWindowPos(hdwp, pSplitterData->hLOT, NULL, 0, 0,
pSplitterData->current - pSplitterData->left,
pSplitterData->bottom - pSplitterData->top,
SWP_NOMOVE | SWP_NOZORDER); DeferWindowPos(hdwp, hWnd, NULL, pSplitterData->current,
pSplitterData->top, 0, 0, SWP_NOSIZE | SWP_NOZORDER); DeferWindowPos(hdwp, pSplitterData->hROB, NULL,
pSplitterData->current + 2, pSplitterData->top,
pSplitterData->right - pSplitterData->current - 2,
pSplitterData->bottom - pSplitterData->top,
SWP_NOZORDER);
} else { // 从上到下
DeferWindowPos(hdwp, pSplitterData->hLOT, NULL, 0, 0,
pSplitterData->right - pSplitterData->left,
pSplitterData->current - pSplitterData->top,
SWP_NOMOVE | SWP_NOZORDER);
DeferWindowPos(hdwp, hWnd, NULL, pSplitterData->left,
pSplitterData->current,0,0,SWP_NOSIZE | SWP_NOZORDER);
DeferWindowPos(hdwp, pSplitterData->hROB, NULL,
pSplitterData->left, pSplitterData->current + 2,
pSplitterData->right - pSplitterData->left,
pSplitterData->bottom - pSplitterData->current - 2,
SWP_NOZORDER);
}
EndDeferWindowPos(hdwp);
}
break; case WM_MOUSEMOVE:
if ((wParam & MK_LBUTTON) == MK_LBUTTON && GetCapture() == hWnd)
{
tagSplitterData* pSplitterData;
pSplitterData = (tagSplitterData*)GetWindowLong(hWnd, 0);
if (pSplitterData == NULL) { break; }
RECT rcLOT;
GetWindowRect(pSplitterData->hLOT, &rcLOT);
HDC hdc = GetDC(pSplitterData->hParent);
HPEN pen = SelectPen(hdc, pSplitterData->hPenObj);
int rop = SetROP2(hdc, R2_NOTXORPEN);
if (pSplitterData->bLOR) {
MoveToEx(hdc, pSplitterData->current, pSplitterData->top,
NULL);
LineTo(hdc, pSplitterData->current, pSplitterData->bottom); pSplitterData->current = pSplitterData->left +
GetRectCX(rcLOT) + (short)LOWORD(lParam);
if (pSplitterData->current < pSplitterData->left + 4) {
pSplitterData->current = pSplitterData->left + 4;
}
if (pSplitterData->current > pSplitterData->right - 6)
{
pSplitterData->current = pSplitterData->right - 6;
} MoveToEx(hdc, pSplitterData->current, pSplitterData->top,
NULL);
LineTo(hdc, pSplitterData->current, pSplitterData->bottom);
} else {
MoveToEx(hdc, pSplitterData->left, pSplitterData->current,
NULL);
LineTo(hdc, pSplitterData->right, pSplitterData->current); pSplitterData->current = pSplitterData->top +
GetRectCY(rcLOT) + (short)HIWORD(lParam);
if (pSplitterData->current < pSplitterData->top + 4) {
pSplitterData->current = pSplitterData->top + 4;
}
if (pSplitterData->current > pSplitterData->bottom - 6) {
pSplitterData->current = pSplitterData->bottom - 6;
} MoveToEx(hdc, pSplitterData->left, pSplitterData->current,
NULL);
LineTo(hdc, pSplitterData->right, pSplitterData->current);
}
SetROP2(hdc, rop);
SelectPen(hdc, pen);
ReleaseDC(pSplitterData->hParent, hdc);
}
return 0; default:
break;
} return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
// 调整分隔条(在主窗口的大小发生改变时,需要调用这个函数)
BOOL cwlAdjustSplitter(HWND hWnd)
{
tagSplitterData* pSplitterData;
pSplitterData = (tagSplitterData*)GetWindowLong(hWnd, 0);
if (pSplitterData == NULL) {
return FALSE;
}
HDWP hdwp = BeginDeferWindowPos(3);
RECT rcLOT;
GetWindowRect(pSplitterData->hLOT, &rcLOT);
int cx = GetRectCX(rcLOT);
int cy = GetRectCY(rcLOT);
if (pSplitterData->bLOR) { // 从左到右
DeferWindowPos(hdwp, pSplitterData->hLOT, NULL,
pSplitterData->left, pSplitterData->top,cx,
pSplitterData->bottom - pSplitterData->top,
SWP_NOZORDER);
DeferWindowPos(hdwp, hWnd, NULL, pSplitterData->left + cx,
pSplitterData->top, 2, pSplitterData->bottom -
pSplitterData->top, SWP_NOZORDER);
DeferWindowPos(hdwp, pSplitterData->hROB, NULL,
pSplitterData->left + cx + 2, pSplitterData->top,
pSplitterData->right - pSplitterData->left - cx - 2,
pSplitterData->bottom - pSplitterData->top,
SWP_NOZORDER);
} else { // 从上到下
DeferWindowPos(hdwp, pSplitterData->hLOT, NULL,
pSplitterData->left, pSplitterData->top,
pSplitterData->right - pSplitterData->left,
cy, SWP_NOZORDER);
DeferWindowPos(hdwp, hWnd, NULL, pSplitterData->left,
pSplitterData->top + cy, pSplitterData->right -
pSplitterData->left, 2, SWP_NOZORDER);
DeferWindowPos(hdwp, pSplitterData->hROB, NULL,
pSplitterData->left, pSplitterData->top + cy + 2,
pSplitterData->right - pSplitterData->left,
pSplitterData->bottom - pSplitterData->top - cy - 2,
SWP_NOZORDER);
}
EndDeferWindowPos(hdwp);
return TRUE;
}
//========================================================================
// 创建分隔条
HWND cwlCreateSplitter(HWND hwndParent, LPRECT lprcWorkArea, HWND hLeftOrTopWnd,
HWND hRightOrBottomWnd, BOOL bLeftToRight)
{
ASSERT(IsWindow(hLeftOrTopWnd));
ASSERT(IsWindow(hRightOrBottomWnd));
#ifdef _DEBUG
RECT rect;
GetWindowRect(hLeftOrTopWnd, &rect);
if (bLeftToRight) {
if (GetRectCX(rect) + lprcWorkArea->left > lprcWorkArea->right) {
ASSERT(FALSE);
return NULL;
}
} else {
if (GetRectCY(rect) + lprcWorkArea->top > lprcWorkArea->bottom) {
ASSERT(FALSE);
return NULL;
}
}
#endif tagSplitterData* pSplitterData = new tagSplitterData;
if (pSplitterData == NULL) { return NULL; }
pSplitterData->hLOT = hLeftOrTopWnd;
pSplitterData->hROB = hRightOrBottomWnd;
pSplitterData->bLOR = bLeftToRight;
pSplitterData->top = lprcWorkArea->top;
pSplitterData->left = lprcWorkArea->left;
pSplitterData->right = lprcWorkArea->right;
pSplitterData->bottom = lprcWorkArea->bottom;
pSplitterData->hParent = hwndParent;
pSplitterData->current = 0;
pSplitterData->hPenObj = NULL;
LPCTSTR Splitter = NULL;
if (bLeftToRight) {
Splitter = TEXT("Cmnlib_HSplitter");
} else {
Splitter = TEXT("Cmnlib_VSplitter");
} WNDCLASSEX wcex;
wcex.cbSize = sizeof(wcex);
if (!GetClassInfoEx(AfxGetInstanceHandle(), Splitter, &wcex)) {
wcex.cbClsExtra = 0;
wcex.cbWndExtra = sizeof(tagSplitterData*);
wcex.hbrBackground = (HBRUSH)COLOR_BTNSHADOW;
wcex.hCursor = LoadCursor(NULL, bLeftToRight ? IDC_SIZEWE : IDC_SIZENS);
wcex.hIcon = wcex.hIconSm = NULL;
wcex.hInstance = AfxGetInstanceHandle();
wcex.lpfnWndProc = (WNDPROC)_SplitterProc_;
wcex.lpszMenuName = NULL;
wcex.lpszClassName = Splitter;
wcex.style = 0;
if (NULL == RegisterClassEx(&wcex)) {
delete pSplitterData;
return NULL;
}
} HWND hWndTemp = CreateWindowEx(0, Splitter, NULL, WS_CHILD | WS_VISIBLE,
0, 0, 0, 0, hwndParent, NULL, AfxGetInstanceHandle(),
(LPVOID)pSplitterData);
if (hWndTemp == NULL) {
delete pSplitterData;
return NULL;
} else {
cwlAdjustSplitter(hWndTemp);
}
return hWndTemp;
}
SplitterBar.obj : error LNK2001: unresolved external symbol "public: static long __stdcall CSplitterBar::_SplitterProc_(struct HWND__ *,unsigned int,unsigned int,long)" (?_SplitterProc_@CSplitterBar@@SGJPAUHWND__@@IIJ@Z)
Debug/WantLink.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
假设主窗口上有两个控件,其 ID 分别为 IDC_TREE1、IDC_LIST1,现在要让它可以水平切分。 下面的代码是在主窗口的 OnInitDialog 中写的,如果在放在其他地方,可能需要修改一下: RECT rc;
GetClientRect(&rc); // 水平切分(将 TRUE 改变 FALSE 就变成垂直切分了)
cwlCreateSplitter(m_hWnd, &rc, GetDlgItem(IDC_LIST1)->m_hWnd,
GetDlgItem(IDC_LIST2)->m_hWnd, TRUE);
HWND hLeftOrTopWnd, HWND hRightOrBottomWnd, BOOL bLeftToRight);hwndParent 对话框窗口的句柄。
lprcWorkArea 允许切分窗口使用的区域。
hLeftOrTopWnd 左边或上边窗口的句柄
hRightOrBottomWnd 右边或下边窗口的句柄
bLeftToRight 是否是从左到右的方式切分,如果为 FALSE 的话,则为从上到下的切分方式。
RECT rc;
GetClientRect(&rc); // 水平切分(将 TRUE 改变 FALSE 就变成垂直切分了)
CSplitterBar::cwlCreateSplitter(m_hWnd, &rc, GetDlgItem(IDC_DOWNLOADLIST)->m_hWnd,
GetDlgItem(IDC_UP)->m_hWnd, TRUE);
但编译时出现以下错误:
--------------------Configuration: WantLink - Win32 Debug--------------------
Compiling...
DownCencerDialog.cpp
D:\MyProgram\WantLink\DownCencerDialog.cpp(61) : error C2352: 'CSplitterBar::cwlCreateSplitter' : illegal call of non-static member function
d:\myprogram\wantlink\splitterbar.h(29) : see declaration of 'cwlCreateSplitter'
Error executing cl.exe.
到底是什么原因了?请帮下忙!