From 6efc67d7e2163fd19deed4d3d3db37704a367bc4 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 7 Dec 2014 20:16:58 -0500 Subject: [PATCH] More header control stuff: resize handling/header control repositioning. --- wintable/new/header.h | 17 ++++++++++++++++- wintable/new/main.c | 2 ++ wintable/new/resize.h | 17 +++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 wintable/new/resize.h diff --git a/wintable/new/header.h b/wintable/new/header.h index 213516a..374aaa4 100644 --- a/wintable/new/header.h +++ b/wintable/new/header.h @@ -4,6 +4,7 @@ static void makeHeader(struct table *t, HINSTANCE hInstance) { t->header = CreateWindowExW(0, WC_HEADERW, L"", + // don't set WS_VISIBLE; according to MSDN we create the header hidden as part of setting the initial position (http://msdn.microsoft.com/en-us/library/windows/desktop/ff485935%28v=vs.85%29.aspx) // TODO WS_BORDER? // TODO is HDS_HOTTRACK needed? WS_CHILD | HDS_FULLDRAG | HDS_HORZ | HDS_HOTTRACK, @@ -21,5 +22,19 @@ static void destroyHeader(struct table *t) static void repositionHeader(struct table *t) { - // TODO http://msdn.microsoft.com/en-us/library/windows/desktop/hh298357%28v=vs.85%29.aspx + RECT r; + WINDOWPOS wp; + HDLAYOUT l; + + if (GetClientRect(t->hwnd, &r) == 0) + panic("error getting client rect for Table header repositioning"); + l.prc = &r; + l.pwpos = ℘ + if (SendMessageW(t->header, HDM_LAYOUT, 0, (LPARAM) (&l)) == FALSE) + panic("error getting new Table header position"); + if (SetWindowPos(t->header, wp.hwndInsertAfter, + wp.x, wp.y, wp.cx, wp.cy, + // see above on showing the header here instead of in the CreateWindowExW() call + wp.flags | SWP_SHOWWINDOW) == 0) + panic("error repositioning Table header"); } diff --git a/wintable/new/main.c b/wintable/new/main.c index 496af07..84508bb 100644 --- a/wintable/new/main.c +++ b/wintable/new/main.c @@ -56,10 +56,12 @@ struct table { #include "events.h" #include "header.h" #include "children.h" +#include "resize.h" static const handlerfunc handlers[] = { eventHandlers, childrenHandlers, + resizeHandler, NULL, }; diff --git a/wintable/new/resize.h b/wintable/new/resize.h new file mode 100644 index 0000000..1c5307e --- /dev/null +++ b/wintable/new/resize.h @@ -0,0 +1,17 @@ +// 7 december 2014 + +// TODO why doesn't this trigger on first show? + +HANDLER(resizeHandler) +{ + WINDOWPOS *wp; + + if (uMsg != WM_WINDOWPOSCHANGED) + return FALSE; + wp = (WINDOWPOS *) lParam; + if ((wp->flags & SWP_NOSIZE) != 0) + return FALSE; + repositionHeader(t); + *lResult = 0; + return TRUE; +}