我现在在单文档视图中添加了几个按钮,每个按钮单击时弹出一个对话框,在对话框中有一些控件,如列表控件、树型控件、编辑控件等,我现在要做到如PP点通界面那样,可以上下拖动,或左右拖动,请问怎么样添加分隔条?如要做到左右拖动,是不是要把左边的控件组放在一个对话框,右边的放在一个对话框,再在中间加分隔条,那应该怎么实现了?有源码更好,多谢帮忙!

解决方案 »

  1.   

    //========================================================================
    // 创建分隔条
    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;
    }
      

  2.   


    //========================================================================
    // 调整分隔条
    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;
    }
      

  3.   

    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);
    }
      

  4.   

    就是中间有个分隔条呀,在单文档视图中用SplitterWnd,在对话框中用什么呢?
    对话框怎么做到切分窗口呢?
      

  5.   

    struct tagSplitterData {
    HWND hLOT;
    HWND hROB;
    BOOL bLOR;
    LONG top;
    LONG left;
    LONG right;
    LONG bottom; LONG current;
    HWND hParent;
    HPEN hPenObj;
    };
      

  6.   

    先谢谢needways,能不能讲详细点呀!
      

  7.   

    codeguru上面有,dialog上实现切分窗口的代码
      

  8.   

    findcaiyzh能不能给我一个具体的网址!
      

  9.   

    主要调用这两个函数:
    BOOL cwlAdjustSplitter(HWND hWnd);
    HWND cwlCreateSplitter(HWND hwndParent, LPRECT lprcWorkArea, HWND hLeftOrTopWnd,
    HWND hRightOrBottomWnd, BOOL bLeftToRight);代码放在 CPP 文件中。
      

  10.   

    #include "windowsx.h"#define GetRectCX(rect) (rect.right - rect.left)
    #define GetRectCY(rect) (rect.bottom - rect.top)将 cwlGetInstanceHandle 改为 AfxGetInstanceHandle另外,我的这个代码是在 SDK 下写的,如果你要在 MFC 中使用,需要进行一下转换。
      

  11.   

    这位大哥有没有在MFC下编的呀,传给我一份呀,我的QQ是:24446830
      

  12.   

    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(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)
      

  13.   

    在 CPP 文件的前面加上 _SplitterProc_ 的函数原型。DeletePen 是一个宏,它定义在“windowsx.h”文件中。在 SetCapture、GetWindowRect、GetDC、ReleaseDC、DefWindowProcA 等函数前面加上两个冒号。
      

  14.   

    我在CPP文件的前面加上static LONG CALLBACK _SplitterProc_(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);请问一下这个函数是不是要改是static LONG CALLBACK CSplitterBar::_SplitterProc_(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)呢?
    并且还有一些错误
    -----------------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)
      

  15.   

    重新上传,可以在 MFC 下使用的。Splitter.h#ifndef Splitter_Needways_2004_07_01_15_13
    #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
      

  16.   

    下面的代码是 Splitter.cpp 中的。
      

  17.   


    #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);
      

  18.   

    用static LONG CALLBACK CSplitterBar::_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.
      

  19.   


    //========================================================================
    // 分割窗口的窗口处理程序
    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);
    }
      

  20.   

    //========================================================================
    // 调整分隔条(在主窗口的大小发生改变时,需要调用这个函数)
    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;
    }
      

  21.   


    //========================================================================
    // 创建分隔条
    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;
    }
      

  22.   

    不加则出现以下错误:Linking...
    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.
      

  23.   

    使用示例:
        假设主窗口上有两个控件,其 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);
      

  24.   

    HWND cwlCreateSplitter(HWND hwndParent, LPRECT lprcWorkArea,
    HWND hLeftOrTopWnd, HWND hRightOrBottomWnd, BOOL bLeftToRight);hwndParent        对话框窗口的句柄。
    lprcWorkArea      允许切分窗口使用的区域。
    hLeftOrTopWnd     左边或上边窗口的句柄
    hRightOrBottomWnd 右边或下边窗口的句柄
    bLeftToRight      是否是从左到右的方式切分,如果为 FALSE 的话,则为从上到下的切分方式。
      

  25.   

    BOOL cwlAdjustSplitter(HWND hWnd);hWnd 是 cwlCreateSplitter 函数返回的句柄
      

  26.   

    关键问题是我界面中很多这个的窗口要添加一个分隔条呀,我这些窗口是在SDI中的,我很多地方要用呀,所以我要把它定义为类呀,定义为类怎么调用呀?
      

  27.   

    一样啊。如果类必须从 CWnd 继承的话,你要像我上面说的那样,在一些冲突的函数前面加上两个冒号。
      

  28.   

    我在我要用的对话框 OnInitDialog中写以下代码:
       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.
    到底是什么原因了?请帮下忙!
      

  29.   

    CSplitterBar::cwlCreateSplitter 将改为 cwlCreateSplitter
      

  30.   

    谢谢needways!能不能把你QQ告诉我呀,我有什么问题好象你请教呀!上面的那个我是不是要把那几个按钮和列表控件放在一个CPropertyPage中呀!
      

  31.   

    多用几次 cwlCreateSplitter 就行,或者你改一下原代码也行。