Probleme mit SplitterControl



  • Ich benötige ein vertikales SplitterControl und habe aktuell verschiedene Probleme...

    1. Wie kann ich beim verschieben des Splitters, das flackern der Controls verhindern/reduzieren?

    2. Falsche Darstellung, wenn ich den Code zu einem vertikalen Splitter abändere..

    3. Die Statusbar wird durch das SplitterControl versteckt. Muss ich hier mittels GetWindowRect und Ermittlung der Statusbarhöhe in Pixel das ganze ermitteln oder wie gehe ich am besten vor?

    // Win32Project_Splitter.cpp : Defines the entry point for the application.
    //
    
    #include "stdafx.h"
    #include "Win32Project_Splitter.h"
    
    #define MAX_LOADSTRING 100
    
    // Global Variables:
    HINSTANCE hInst;								// current instance
    TCHAR szTitle[MAX_LOADSTRING];					// The title bar text
    TCHAR szWindowClass[MAX_LOADSTRING];			// the main window class name
    
    #include "Commctrl.h"
    #pragma comment(lib, "Comctl32.lib")
    
    #include "Commdlg.h"
    #pragma comment(lib, "Comdlg32.lib")
    
    // Forward declarations of functions included in this code module:
    ATOM				MyRegisterClass(HINSTANCE hInstance);
    BOOL				InitInstance(HINSTANCE, int);
    LRESULT CALLBACK	WndProc(HWND, UINT, WPARAM, LPARAM);
    INT_PTR CALLBACK	About(HWND, UINT, WPARAM, LPARAM);
    
    int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
                         _In_opt_ HINSTANCE hPrevInstance,
                         _In_ LPTSTR    lpCmdLine,
                         _In_ int       nCmdShow)
    {
    	UNREFERENCED_PARAMETER(hPrevInstance);
    	UNREFERENCED_PARAMETER(lpCmdLine);
    
     	// TODO: Place code here.
    	MSG msg;
    	HACCEL hAccelTable;
    
    	// Initialize global strings
    	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
    	LoadString(hInstance, IDC_WIN32PROJECT_SPLITTER, szWindowClass, MAX_LOADSTRING);
    	MyRegisterClass(hInstance);
    
    	// Perform application initialization:
    	if (!InitInstance (hInstance, nCmdShow))
    	{
    		return FALSE;
    	}
    
    	hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WIN32PROJECT_SPLITTER));
    
    	// Main message loop:
    	while (GetMessage(&msg, NULL, 0, 0))
    	{
    		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
    		{
    			TranslateMessage(&msg);
    			DispatchMessage(&msg);
    		}
    	}
    
    	return (int) msg.wParam;
    }
    
    UINT StatusBarStyles = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | SBARS_SIZEGRIP |
    WS_CLIPCHILDREN;
    
    //
    //  FUNCTION: MyRegisterClass()
    //
    //  PURPOSE: Registers the window class.
    //
    ATOM MyRegisterClass(HINSTANCE hInstance)
    {
    	WNDCLASSEX wcex;
    
    	wcex.cbSize = sizeof(WNDCLASSEX);
    
    	wcex.style			= CS_HREDRAW | CS_VREDRAW;
    	wcex.lpfnWndProc	= WndProc;
    	wcex.cbClsExtra		= 0;
    	wcex.cbWndExtra		= 0;
    	wcex.hInstance		= hInstance;
    	wcex.hIcon			= LoadIcon(hInstance, MAKEINTRESOURCE(IDI_WIN32PROJECT_SPLITTER));
    	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
    	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW+1);
    	wcex.lpszMenuName	= MAKEINTRESOURCE(IDC_WIN32PROJECT_SPLITTER);
    	wcex.lpszClassName	= szWindowClass;
    	wcex.hIconSm		= LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
    
    	return RegisterClassEx(&wcex);
    }
    
    //
    //   FUNCTION: InitInstance(HINSTANCE, int)
    //
    //   PURPOSE: Saves instance handle and creates main window
    //
    //   COMMENTS:
    //
    //        In this function, we save the instance handle in a global variable and
    //        create and display the main program window.
    //
    BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
    {
       HWND hWnd;
    
       hInst = hInstance; // Store instance handle in our global variable
    
       hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
          CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
    
       if (!hWnd)
       {
          return FALSE;
       }
    
       ShowWindow(hWnd, nCmdShow);
       UpdateWindow(hWnd);
    
       return TRUE;
    }
    
    HWND CreateStatusBar(HWND Parent, DWORD Style)
    {
    	HWND StatusBar;
    
    	//StatusBar = CreateWindow(STATUSCLASSNAME, NULL, Style,
    	//	0, 0, 0, 0, Parent, NULL, GetModuleHandle(0), NULL);
    
    	StatusBar = CreateWindowEx(0, STATUSCLASSNAME, NULL,
    		Style | SBT_OWNERDRAW, 0, 0, 0, 0,
    		Parent, NULL, GetModuleHandle(0), NULL);
    
    	return StatusBar;
    
    }
    
    //
    //  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
    //
    //  PURPOSE:  Processes messages for the main window.
    //
    //  WM_COMMAND	- process the application menu
    //  WM_PAINT	- Paint the main window
    //  WM_DESTROY	- post a quit message and return
    //
    //
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	int wmId, wmEvent;
    	PAINTSTRUCT ps;
    	HDC hdc;
    
    	RECT		rect;
    	static HCURSOR 	hCursor;
    	static BOOL	bSplitterMoving;
    	static DWORD	dwSplitterPos;
    	static HWND	hWnd1, hWnd2;
    
    	static HWND hStatusBar, hComboBox;
    
    	switch (message)
    	{
    	case WM_CREATE:
    
    		hWnd1 = CreateWindowEx(WS_EX_CLIENTEDGE,
    			L"static", 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,
    			L"static", NULL,
    			WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_VSCROLL,
    			0, 0, 0, 0,
    			hWnd, (HMENU)2,
    			hInst, NULL);
    
    		hStatusBar = CreateStatusBar(hWnd, StatusBarStyles);
    
    		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 ((wParam != SIZE_MINIMIZED) && (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_SIZE:
    		/*
    		If window is shrunk so that splitter now lies outside the
    		window boundaries, move the splitter within the window.
    		*/
    		if ((wParam != SIZE_MINIMIZED) && (HIWORD(lParam) < dwSplitterPos))
    			dwSplitterPos = HIWORD(lParam) - 10;
    
    		/* Adjust the children's size and position */
    		MoveWindow(hWnd1, 0, 0, dwSplitterPos - 1, LOWORD(lParam) - dwSplitterPos - 2, TRUE);
    		MoveWindow(hWnd2, dwSplitterPos + 2,       0, LOWORD(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.right)
    					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_COMMAND:
    		wmId    = LOWORD(wParam);
    		wmEvent = HIWORD(wParam);
    		// Parse the menu selections:
    		switch (wmId)
    		{
    		case IDM_\1:
    			DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
    			break;
    		case IDM_EXIT:
    			DestroyWindow(hWnd);
    			break;
    		default:
    			return DefWindowProc(hWnd, message, wParam, lParam);
    		}
    		break;
    	case WM_PAINT:
    		hdc = BeginPaint(hWnd, &ps);
    		// TODO: Add any drawing code here...
    		EndPaint(hWnd, &ps);
    		break;
    	case WM_DESTROY:
    		PostQuitMessage(0);
    		break;
    	default:
    		return DefWindowProc(hWnd, message, wParam, lParam);
    	}
    	return 0;
    }
    
    // Message handler for about box.
    INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	UNREFERENCED_PARAMETER(lParam);
    	switch (message)
    	{
    	case WM_INITDIALOG:
    		return (INT_PTR)TRUE;
    
    	case WM_COMMAND:
    		if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
    		{
    			EndDialog(hDlg, LOWORD(wParam));
    			return (INT_PTR)TRUE;
    		}
    		break;
    	}
    	return (INT_PTR)FALSE;
    }
    


  • Als erstes würde ich mal einen Splitterbalken einsetzen, wie z.B. im Outlook realisiert (gefällt mir persönlich besser).

    zu 1. "WM_SIZE" abfangen und alle Controls mittels

    hdpd = BeginDeferWindowPos(...);
    hdpd = DeferWindowPos(hdpd, .......);
    hdpd = DeferWindowPos(hdpd, .......);
    hdpd = DeferWindowPos(hdpd, .......);
    hdpd = DeferWindowPos(hdpd, .......);
    EndDeferWindowPos(hdpd);

    resizen

    zu 3. "WM_MOUSEMOVE" abfangen und vor dem Zeichnen des Splitterbalkens die Entfernung zur Oberkannte des Statusfensters prüfen und bei Unterschreitung das Zeichnen des Splitterbalkens unterbinden. An dieser Stelle die zuletzt gezeichnete Position speichern. Nun "WM_LBUTTONUP" abfangen. Die Grössenänderung der Fenster würde ich erst jetzt auslösen, dann flackert es am wenigsten.


Anmelden zum Antworten