October 27th, 2012 08:43 AM
#1
List-box does not fills correctly window space in on my own coded class "splitter"
I have implemented window class (so called "splitter") and have a problem. It means - this class works fine for text-edits, buttons, normal (usual windows) - all I have tested except form list-box. List-box docks badly - it does not fills all space which it is supposed to do. Some place is not filled correctly what makes for my class troubles. How can I it solve?
Code:
#include "SplitterWindow.h"
#include "stdafx.h"
#include <wchar.h>
bool InitializeSplitter(HINSTANCE hInstance);
HWND CreateSplitterWindow(HINSTANCE hInstance, HWND hwnd1, HWND hwnd2, wchar_t title[0x100],
HBRUSH brush, BOOL horizontal);
LRESULT CALLBACK SplitterWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
typedef struct _SplitterInfo
{
HWND hWnd1;
HWND hWnd2;
HCURSOR hCursor;
BOOL bSplitterMoving;
DWORD dwSplitterPos;
BOOL horizontal;
HBRUSH brush; // debug purposes
wchar_t title[0x100]; // debug purposes
} SplitterInfo;
bool InitializeSplitter(HINSTANCE hInstance)
{
WNDCLASS wndclass;
wndclass.style = 0; //CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = SplitterWndProc;
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 = L"SPLITTER";
if (RegisterClass(&wndclass))
return true;
else
return false;
}
HWND CreateSplitterWindow(HINSTANCE hInstance, HWND hwnd1, HWND hwnd2, wchar_t title[0x100],
HBRUSH brush, BOOL horizontal)
{
HWND hwnd = CreateWindowEx(0, L"SPLITTER", L"Splitter",
WS_POPUP | WS_CLIPCHILDREN,
CW_USEDEFAULT, CW_USEDEFAULT,
400, 300,
NULL, NULL,
hInstance, NULL);
if (hwnd == NULL)
return NULL;
SetParent(hwnd1, hwnd);
SetParent(hwnd2, hwnd);
SplitterInfo *info = (SplitterInfo *)GlobalAlloc(GPTR, sizeof(SplitterInfo));
info->hWnd1 = hwnd1;
info->hWnd2 = hwnd2;
info->brush = brush;
wcscpy(info->title, title);
if (horizontal)
info->hCursor = LoadCursor(NULL, IDC_SIZENS);
else
info->hCursor = LoadCursor(NULL, IDC_SIZEWE);
info->bSplitterMoving = FALSE;
info->dwSplitterPos = 300;
info->horizontal = horizontal;
ShowWindow(hwnd1, TRUE);
ShowWindow(hwnd2, TRUE);
UpdateWindow(hwnd1);
UpdateWindow(hwnd2);
SetWindowLong(hwnd, GWL_USERDATA, (LONG)info);
return hwnd;
}
LRESULT CALLBACK SplitterWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
HINSTANCE hInst;
RECT rect;
SplitterInfo *info = (SplitterInfo *)GetWindowLong(hWnd, GWL_USERDATA);
switch (uMsg)
{
case WM_PAINT:
{
if (info==NULL)
break;
PAINTSTRUCT ps;
RECT rect;
GetClientRect(hWnd, &rect);
HDC hdc = BeginPaint(hWnd, &ps);
FillRect(hdc, &rect, info->brush);
EndPaint(hWnd, &ps);
}
break;
case WM_CLOSE:
return 0;
case WM_SIZE:
if (info == NULL)
break;
if (info->horizontal)
{
/*
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) < info->dwSplitterPos))
info->dwSplitterPos = HIWORD(lParam) - 10;
/* Adjust the children's size and position */
MoveWindow(info->hWnd1, 0, 0, LOWORD(lParam), info->dwSplitterPos - 1, TRUE);
MoveWindow(info->hWnd2, 0, info->dwSplitterPos+2, LOWORD(lParam) , HIWORD(lParam) - info->dwSplitterPos - 2, TRUE);
}
else
{
if ((wParam != SIZE_MINIMIZED) && (LOWORD(lParam) < info->dwSplitterPos))
info->dwSplitterPos = LOWORD(lParam) - 10;
MoveWindow(info->hWnd1, 0, 0, info->dwSplitterPos - 1, HIWORD(lParam), TRUE);
MoveWindow(info->hWnd2, info->dwSplitterPos+2, 0, LOWORD(lParam) - info->dwSplitterPos - 2, HIWORD(lParam) , TRUE);
}
return 0;
case WM_MOUSEMOVE:
if (info == NULL)
break;
if (info->horizontal)
{
if (HIWORD(lParam) > 10) // do not allow above this mark
{
SetCursor(info->hCursor);
if ((wParam == MK_LBUTTON) && info->bSplitterMoving)
{
GetClientRect(hWnd, &rect);
if (HIWORD(lParam) > rect.bottom)
return 0;
info->dwSplitterPos = HIWORD(lParam);
SendMessage(hWnd, WM_SIZE, 0, MAKELPARAM(rect.right, rect.bottom));
}
}
}
else
{
if (LOWORD(lParam) > 10) // do not allow above this mark
{
SetCursor(info->hCursor);
if ((wParam == MK_LBUTTON) && info->bSplitterMoving)
{
GetClientRect(hWnd, &rect);
if (LOWORD(lParam) > rect.right)
return 0;
info->dwSplitterPos = LOWORD(lParam);
SendMessage(hWnd, WM_SIZE, 0, MAKELPARAM(rect.right, rect.bottom));
}
}
}
return 0;
/*
case WM_NCHITTEST:
{
wchar_t string[0x100];
swprintf(string, 0x100, L"(%d,%d)", LOWORD(lParam), HIWORD(lParam));
MessageBox(hWnd, string, L"NCHITTEST", MB_ICONINFORMATION | MB_OK);
}
break;
*/
case WM_LBUTTONDOWN:
if (info == NULL)
break;
SetCursor(info->hCursor);
info->bSplitterMoving = TRUE;
SetCapture(hWnd);
return 0;
case WM_LBUTTONUP:
if (info == NULL)
break;
ReleaseCapture();
info->bSplitterMoving = FALSE;
return 0;
case WM_DESTROY:
if (info != NULL)
{
info->hCursor = NULL;
DestroyWindow(info->hWnd1);
DestroyWindow(info->hWnd2);
GlobalFree(info);
SetWindowLong(hWnd, GWL_USERDATA, NULL);
}
return 0;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
October 27th, 2012 10:37 AM
#2
Re: List-box does not fills correctly window space in on my own coded class "splitter
Just create your ListBox with the LBS_NOINTEGRALHEIGHT style set.
October 31st, 2012 04:18 PM
#3
Re: List-box does not fills correctly window space in on my own coded class "splitter
Tags for this Thread
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width
Bookmarks