请教高手怎么用sdk实现spliter?

bsmith 2002-08-02 07:06:26
这好像不是一个通用控件,怎么才能得到它?
...全文
51 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
bsmith 2002-08-12
  • 打赏
  • 举报
回复
3x
masterz 2002-08-02
  • 打赏
  • 举报
回复
http://www.csee.usf.edu/~birla/software/splitter.html
masterz 2002-08-02
  • 打赏
  • 举报
回复
The source code below shows how to implement a splitter window using plain win32 API. It uses the WM_MOUSEMOVE, WM_LBUTTONDOWN and WM_LBUTTONUP events to resize and move two child edit controls. This example can easily be modified to implement a vertical splitter. The code should compile fine with any windows compiler. Visual C++ users can create an empty win32 application and add the following code to a new .c file.


--------------------------------------------------------------------------------

#include <windows.h>

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{

HWND hwnd;
MSG msg;
WNDCLASS wndclass;
static char *szAppName = "Splitter Example";


wndclass.style = 0; //CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_INFORMATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;

RegisterClass(&wndclass);

hwnd = CreateWindow(szAppName, szAppName,
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
CW_USEDEFAULT, CW_USEDEFAULT,
400, 300,
NULL, NULL,
hInstance, NULL);

ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);


while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}




LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
HINSTANCE hInst;
RECT rect;
static HCURSOR hCursor;
static BOOL bSplitterMoving;
static DWORD dwSplitterPos;
static HWND hWnd1, hWnd2;


switch (uMsg)
{
case WM_CREATE:
hInst = ((LPCREATESTRUCT) lParam) -> hInstance;

hWnd1 = CreateWindowEx(WS_EX_CLIENTEDGE,
"edit", NULL,
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | ES_MULTILINE | WS_VSCROLL,
0, 0, 0, 0,
hWnd, (HMENU) 1,
hInst, NULL);

hWnd2 = CreateWindowEx(WS_EX_CLIENTEDGE,
"edit", NULL,
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | ES_MULTILINE | WS_VSCROLL,
0, 0, 0, 0,
hWnd, (HMENU) 2,
hInst, NULL);


hCursor = LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENS));
bSplitterMoving = FALSE;

dwSplitterPos = 130;
return 0;


case WM_SIZE:
/*
If window is shrunk so that splitter now lies outside the
window boundaries, move the splitter within the window.
*/
if (HIWORD(lParam) < dwSplitterPos)
dwSplitterPos = HIWORD(lParam) - 10;

/* Adjust the children's size and position */
MoveWindow(hWnd1, 0, 0, LOWORD(lParam), dwSplitterPos - 1, TRUE);
MoveWindow(hWnd2, 0, dwSplitterPos+2, LOWORD(lParam) , HIWORD(lParam) - dwSplitterPos - 2, TRUE);
return 0;


case WM_MOUSEMOVE:
if (HIWORD(lParam) > 10) // do not allow above this mark
{
SetCursor(hCursor);
if ((wParam == MK_LBUTTON) && bSplitterMoving)
{
GetClientRect(hWnd, &rect);
if (HIWORD(lParam) > rect.bottom)
return 0;

dwSplitterPos = HIWORD(lParam);
SendMessage(hWnd, WM_SIZE, 0, MAKELPARAM(rect.right, rect.bottom));
}
}
return 0;


case WM_LBUTTONDOWN:
SetCursor(hCursor);
bSplitterMoving = TRUE;
SetCapture(hWnd);
return 0;


case WM_LBUTTONUP:
ReleaseCapture();
bSplitterMoving = FALSE;
return 0;


case WM_DESTROY:
PostQuitMessage(0);
return 0;

}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}

16,473

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧