Example #1
0
void ipod_browse_photo_dialog::on_size (HWND wnd, unsigned width, unsigned height)
{
	HWND wnd_close = GetDlgItem(wnd, IDCANCEL);
	HWND wnd_next = GetDlgItem(wnd, IDC_NEXT);
	HWND wnd_last = GetDlgItem(wnd, IDC_LAST);
	HWND wnd_prev = GetDlgItem(wnd, IDC_PREVIOUS);
	HWND wnd_nextf = GetDlgItem(wnd, IDC_NEXT_FORMAT);
	HWND wnd_prevf = GetDlgItem(wnd, IDC_PREVIOUS_FORMAT);
	HDWP dwp = BeginDeferWindowPos(6);
	RECT rc_close, rc_next, rc_next_format, rc_prev, rc_prev_format, rc_last;
	GetWindowRect(wnd_close, &rc_close);
	GetRelativeRect(wnd_next, wnd, &rc_next);
	GetRelativeRect(wnd_last, wnd, &rc_last);
	GetRelativeRect(wnd_nextf, wnd, &rc_next_format);
	GetRelativeRect(wnd_prev, wnd, &rc_prev);
	GetRelativeRect(wnd_prevf, wnd, &rc_prev_format);
	unsigned cy_close = rc_close.bottom - rc_close.top;
	unsigned cx_close = rc_close.right - rc_close.left;
	dwp = DeferWindowPos(dwp, m_viewer.get_wnd(), NULL, 0, 0, width, height-cy_close-2, SWP_NOZORDER);
	dwp = DeferWindowPos(dwp, wnd_close, NULL, width-cx_close, height-cy_close, cx_close, cy_close, SWP_NOZORDER|SWP_NOSIZE);
	int cx = width-cx_close-2-rc_next.right+rc_next.left;
	dwp = DeferWindowPos(dwp, wnd_last, NULL, cx, height-cy_close, 0, 0, SWP_NOZORDER|SWP_NOSIZE);
	dwp = DeferWindowPos(dwp, wnd_next, NULL, cx -= (rc_last.right-rc_last.left +2), height-cy_close, 0, 0, SWP_NOZORDER|SWP_NOSIZE);
	dwp = DeferWindowPos(dwp, wnd_prev, NULL, cx -= (rc_prev.right-rc_prev.left +2), height-cy_close, 0, 0, SWP_NOZORDER|SWP_NOSIZE);
	dwp = DeferWindowPos(dwp, wnd_nextf, NULL, cx -= (rc_next_format.right-rc_next_format.left + 2), height-cy_close,0, 0, SWP_NOZORDER|SWP_NOSIZE);
	dwp = DeferWindowPos(dwp, wnd_prevf, NULL, cx -= (rc_prev_format.right-rc_prev_format.left + 2), height-cy_close, 0, 0, SWP_NOZORDER|SWP_NOSIZE);
	EndDeferWindowPos(dwp);
}
Example #2
0
bool splitter_window_impl::find_by_divider_pt(POINT & pt, unsigned & p_out)
{
	unsigned n, count = m_panels.get_count();
	for (n = 0; n<count; n++)
	{
		pfc::refcounted_object_ptr_t<panel> p_item = m_panels.get_item(n);

		if (p_item->m_wnd_child)
		{

			RECT rc_area;
			GetRelativeRect(p_item->m_wnd_child, m_wnd, &rc_area);

			if (PtInRect(&rc_area, pt)) return false;

			bool in_divider = false;
			if (get_orientation() == vertical)
			{
				in_divider = (pt.y >= rc_area.bottom) && (pt.y < (rc_area.bottom + (LONG)get_panel_divider_size(n)));
			}
			else
			{
				in_divider = pt.x >= rc_area.right && pt.x < (rc_area.right + (LONG)get_panel_divider_size(n));
			}
			if (in_divider)
			{
				p_out = n;
				return true;
			}
		}

	}
	return false;
}
void playlist_view::move_header(bool redraw, bool update)
{

	RECT rc_playlist, rc_header;
	GetClientRect(wnd_playlist, &rc_playlist);
	GetRelativeRect(wnd_header, wnd_playlist, &rc_header);
	int header_height = calculate_header_height();

	if (rc_header.left != 0 - horizontal_offset ||
		rc_header.top != 0 ||
		rc_header.right - rc_header.left != rc_playlist.right - rc_playlist.left + horizontal_offset ||
		rc_header.bottom - rc_header.top != header_height)
	{
		SendMessage(wnd_header, WM_SETREDRAW, FALSE, 0);
		if (rc_header.bottom - rc_header.top != header_height)
		{
			RECT playlist, redraw;
			get_playlist_rect(&playlist);
			ScrollWindowEx(wnd_playlist, 0, (header_height - rc_header.bottom), &playlist, &playlist, 0, &redraw, 0);
			//			RedrawWindow(wnd_playlist,&redraw,0,RDW_INVALIDATE|RDW_UPDATENOW);
		}
		SetWindowPos(wnd_header, 0, 0 - horizontal_offset, 0, rc_playlist.right - rc_playlist.left + horizontal_offset, header_height, SWP_NOZORDER);
		if (cfg_nohscroll && update) rebuild_header(false);
		SendMessage(wnd_header, WM_SETREDRAW, TRUE, 0);
		if (redraw) RedrawWindow(wnd_header, 0, 0, RDW_UPDATENOW | RDW_INVALIDATE);
	}

}
Example #4
0
void CFWL_Form::Layout() {
  m_rtRelative = GetRelativeRect();

#if _FX_OS_ == _FX_OS_MACOSX_
  IFWL_ThemeProvider* theme = GetAvailableTheme();
  m_fCXBorder = theme ? theme->GetCXBorderSize() : 0.0f;
  m_fCYBorder = theme ? theme->GetCYBorderSize() : 0.0f;
#endif
}
Example #5
0
void IFWL_Widget::DrawBorder(CFX_Graphics* pGraphics,
                             CFWL_Part iPartBorder,
                             IFWL_ThemeProvider* pTheme,
                             const CFX_Matrix* pMatrix) {
  CFX_RectF rtRelative;
  GetRelativeRect(rtRelative);
  CFWL_ThemeBackground param;
  param.m_pWidget = this;
  param.m_iPart = iPartBorder;
  param.m_pGraphics = pGraphics;
  if (pMatrix)
    param.m_matrix.Concat(*pMatrix, true);
  param.m_rtPart = rtRelative;
  pTheme->DrawBackground(&param);
}
Example #6
0
FWL_WidgetHit IFWL_Widget::HitTest(FX_FLOAT fx, FX_FLOAT fy) {
  CFX_RectF rtClient;
  GetClientRect(rtClient);
  if (rtClient.Contains(fx, fy))
    return FWL_WidgetHit::Client;
  if (HasEdge()) {
    CFX_RectF rtEdge;
    GetEdgeRect(rtEdge);
    if (rtEdge.Contains(fx, fy))
      return FWL_WidgetHit::Edge;
  }
  if (HasBorder()) {
    CFX_RectF rtRelative;
    GetRelativeRect(rtRelative);
    if (rtRelative.Contains(fx, fy))
      return FWL_WidgetHit::Border;
  }
  return FWL_WidgetHit::Unknown;
}
LRESULT splitter_window_impl::on_message(HWND wnd, UINT msg, WPARAM wp, LPARAM lp)
{
	switch (msg)
	{
	case WM_NCCREATE:
		m_wnd = wnd;
		g_instances.add_item(this);
		break;
	case WM_CREATE:
		if (!g_count++)
		{
			g_font_menu_horizontal = uCreateMenuFont();
			g_font_menu_vertical = uCreateMenuFont(true);
		}
		refresh_children();
		break;
	case WM_DESTROY:
		destroy_children();
		if (!--g_count)
		{
			g_font_menu_horizontal.release();
			g_font_menu_vertical.release();
		}
		break;
	case WM_NCDESTROY:
		g_instances.remove_item(this);
		m_wnd = NULL;
		break;
	case WM_SHOWWINDOW:
		if (wp == TRUE && lp == 0)
		{
			unsigned n, count = m_panels.get_count();
			for (n = 0; n<count; n++)
			{
				ShowWindow(m_panels[n]->m_wnd_child, SW_SHOWNORMAL);
				ShowWindow(m_panels[n]->m_wnd, SW_SHOWNORMAL);
			}
			RedrawWindow(wnd, 0, 0, RDW_UPDATENOW | RDW_ALLCHILDREN);

		}
		break;
	case WM_WINDOWPOSCHANGED:
	{
		LPWINDOWPOS lpwp = (LPWINDOWPOS)lp;
		if (!(lpwp->flags & SWP_NOSIZE))
		{
			on_size_changed(lpwp->cx, lpwp->cy);
		}
	}
	break;
	/*case WM_SIZE:
	on_size_changed(LOWORD(lp), HIWORD(lp));
	break;*/
	case WM_GETMINMAXINFO:
	{
		LPMINMAXINFO lpmmi = (LPMINMAXINFO)lp;

		lpmmi->ptMinTrackSize.y = 0;
		lpmmi->ptMinTrackSize.x = 0;
		lpmmi->ptMaxTrackSize.y = get_orientation() == vertical ? 0 : MAXLONG;
		lpmmi->ptMaxTrackSize.x = get_orientation() == horizontal ? 0 : MAXLONG;

		unsigned n, count = m_panels.get_count();
		bool b_found = false;

		for (n = 0; n<count; n++)
		{
			MINMAXINFO mmi;
			memset(&mmi, 0, sizeof(MINMAXINFO));
			mmi.ptMaxTrackSize.x = MAXLONG;
			mmi.ptMaxTrackSize.y = MAXLONG;

			if (m_panels[n]->m_wnd_child)
			{
				b_found = true;
				unsigned divider_size = get_panel_divider_size(n);

				unsigned caption_height = m_panels[n]->m_show_caption ? g_get_caption_size() : 0;
				if (m_panels[n]->m_hidden)
				{
					if (get_orientation() == horizontal)
					{
						if (m_panels[n]->m_caption_orientation == vertical)
						{
							mmi.ptMinTrackSize.x = caption_height;
							mmi.ptMaxTrackSize.x = caption_height;
						}
					}
					else
					{
						if (m_panels[n]->m_caption_orientation == horizontal)
						{
							mmi.ptMinTrackSize.y = caption_height;
							mmi.ptMaxTrackSize.y = caption_height;
						}
					}
				}
				else
				{
					SendMessage(m_panels[n]->m_wnd_child, WM_GETMINMAXINFO, 0, (LPARAM)&mmi);
					if (caption_height)
					{
						if (m_panels[n]->m_caption_orientation == horizontal)
						{
							mmi.ptMinTrackSize.y += caption_height;
							if (mmi.ptMaxTrackSize.y < MAXLONG - (long)caption_height) mmi.ptMaxTrackSize.y += caption_height;
							else mmi.ptMaxTrackSize.y = MAXLONG;
						}
						else
						{
							mmi.ptMinTrackSize.x += caption_height;
							if (mmi.ptMaxTrackSize.x < MAXLONG - (long)caption_height) mmi.ptMaxTrackSize.x += caption_height;
							else mmi.ptMaxTrackSize.x = MAXLONG;
						}
					}
				}

				if (m_panels[n]->m_show_toggle_area && !m_panels[n]->m_autohide)
				{
					mmi.ptMinTrackSize.x++;
					if (mmi.ptMaxTrackSize.x < MAXLONG)
						mmi.ptMaxTrackSize.x++;
				}


				if (get_orientation() == vertical)
				{
					lpmmi->ptMinTrackSize.y += mmi.ptMinTrackSize.y + divider_size;

					lpmmi->ptMinTrackSize.x = max(mmi.ptMinTrackSize.x, lpmmi->ptMinTrackSize.x);

					if (lpmmi->ptMaxTrackSize.y <= MAXLONG - mmi.ptMaxTrackSize.y && lpmmi->ptMaxTrackSize.y + mmi.ptMaxTrackSize.y <= MAXLONG - (long)divider_size)
					{
						lpmmi->ptMaxTrackSize.y += mmi.ptMaxTrackSize.y + divider_size;
					}
					else
					{
						lpmmi->ptMaxTrackSize.y = MAXLONG;
					}
					lpmmi->ptMaxTrackSize.x = min(mmi.ptMaxTrackSize.x, lpmmi->ptMaxTrackSize.x);
				}
				else
				{
					lpmmi->ptMinTrackSize.x += mmi.ptMinTrackSize.x + divider_size;
					lpmmi->ptMinTrackSize.y = max(mmi.ptMinTrackSize.y, lpmmi->ptMinTrackSize.y);
					if (lpmmi->ptMaxTrackSize.x <= MAXLONG - mmi.ptMaxTrackSize.x && lpmmi->ptMaxTrackSize.x + mmi.ptMaxTrackSize.x <= MAXLONG - (long)divider_size)
					{
						lpmmi->ptMaxTrackSize.x += mmi.ptMaxTrackSize.x + divider_size;
					}
					else
					{
						lpmmi->ptMaxTrackSize.x = MAXLONG;
					}
					lpmmi->ptMaxTrackSize.y = min(mmi.ptMaxTrackSize.y, lpmmi->ptMaxTrackSize.y);
				}
			}
		}
		if (b_found)
		{
			if (get_orientation() == vertical)
				lpmmi->ptMaxTrackSize.x = max(lpmmi->ptMaxTrackSize.x, lpmmi->ptMinTrackSize.x);
			else
				lpmmi->ptMaxTrackSize.y = max(lpmmi->ptMaxTrackSize.y, lpmmi->ptMinTrackSize.y);
		}
		else
		{
			if (get_orientation() == vertical)
				lpmmi->ptMaxTrackSize.y = MAXLONG;
			else
				lpmmi->ptMaxTrackSize.x = MAXLONG;
		}

		if (0)
		{
			lpmmi->ptMinTrackSize.y = 0;
			if (get_orientation() == horizontal) lpmmi->ptMaxTrackSize.x = 0;
			lpmmi->ptMinTrackSize.x = 0;
			if (get_orientation() == vertical) lpmmi->ptMaxTrackSize.y = 0;
		}
	}
	return 0;
	case WM_MOUSEHOVER:
	{
		POINT pt = { GET_X_LPARAM(lp), GET_Y_LPARAM(lp) };
		HWND child = RealChildWindowFromPoint(wnd, pt);
		if (child == wnd)
		{
			unsigned p_panel = -1;
			bool b_have_next = false;
			bool b_on_divider = false;

			b_on_divider = find_by_divider_pt(pt, p_panel);

			if (b_on_divider)
			{
				if (p_panel < m_panels.get_count())
				{
					b_have_next = (p_panel + 1 < m_panels.get_count());
				}

				if (is_index_valid(p_panel))
					start_autohide_dehide(p_panel);
			}
		}

	}
	break;
	case WM_LBUTTONDOWN:
	case WM_MOUSEMOVE:
	{
		if (m_panels.get_count())
		{

			POINT pt = { GET_X_LPARAM(lp), GET_Y_LPARAM(lp) };
			HWND child = RealChildWindowFromPoint(wnd, pt);
			if (child == wnd)
			{
				unsigned p_panel = -1;
				bool b_have_next = false;
				bool b_on_divider = false;
				if (m_panel_dragging_valid)
				{
					b_on_divider = true;
					p_panel = m_panel_dragging;
				}
				else
					b_on_divider = find_by_divider_pt(pt, p_panel);

				if (b_on_divider)
				{
					if (p_panel < m_panels.get_count())
					{
						b_have_next = (p_panel + 1 < m_panels.get_count());
					}

					if (msg == WM_MOUSEMOVE && ((is_index_valid(p_panel) && m_panels[p_panel]->m_autohide) || (b_have_next && m_panels[p_panel + 1]->m_autohide)))
					{
						if (cfg_sidebar_use_custom_show_delay && !cfg_sidebar_show_delay)
						{
							if ((is_index_valid(p_panel)))
							{
								start_autohide_dehide(p_panel);
							}
						}
						else
						{
							TRACKMOUSEEVENT tme;
							memset(&tme, 0, sizeof(TRACKMOUSEEVENT));
							tme.cbSize = sizeof(TRACKMOUSEEVENT);
							tme.dwFlags = TME_QUERY;
							tme.hwndTrack = wnd;
							_TrackMouseEvent(&tme);

							if (!(tme.dwFlags & TME_HOVER))
							{
								memset(&tme, 0, sizeof(TRACKMOUSEEVENT));
								tme.cbSize = sizeof(TRACKMOUSEEVENT);
								tme.hwndTrack = wnd;
								tme.dwHoverTime = cfg_sidebar_use_custom_show_delay ? cfg_sidebar_show_delay : HOVER_DEFAULT;
								tme.dwFlags = TME_HOVER;
								_TrackMouseEvent(&tme);
							}
						}

					}
				}

				if (b_on_divider && is_index_valid(p_panel) && can_resize_divider(p_panel))
				{
					SetCursor(LoadCursor(0, get_orientation() == horizontal ? IDC_SIZEWE : IDC_SIZENS));

					if (msg == WM_LBUTTONDOWN)
					{
						save_sizes();

						m_panel_dragging = p_panel;
						SetCapture(wnd);

						m_last_position = (get_orientation() == vertical ? pt.y : pt.x);
						m_panel_dragging_valid = true;
					}
				}
				else
				{
					if (!(wp & MK_LBUTTON)) SetCursor(LoadCursor(0, IDC_ARROW));
					m_panel_dragging_valid = false;
				}
			}

			if (m_panel_dragging_valid && wp & MK_LBUTTON && is_index_valid(m_panel_dragging))
			{
				int new_height = m_last_position - (get_orientation() == vertical ? pt.y : pt.x);
				int delta = (get_orientation() == vertical ? pt.y : pt.x) - m_last_position;
				//console::formatter() << "before or: pt = " << pt.y << "," << pt.x << " lastpos: " << m_last_position << " enddelta: " << delta;
				auto & p_panel = m_panels[m_panel_dragging];
				if (p_panel->m_hidden && delta)
				{
					p_panel->m_hidden = false;
					p_panel->m_size = 0;
					get_host()->on_size_limit_change(get_wnd(), uie::size_limit_all);
				}
				int delta_changed = override_size(m_panel_dragging, delta);
				m_last_position = (get_orientation() == vertical ? pt.y : pt.x) + delta_changed;
				on_size_changed();
				if (delta + delta_changed)
					start_autohide_dehide(m_panel_dragging);
			}
		}
		//msg_last = msg;
		//lp_last = lp;
		//wp_last = wp;

	}
	break;
	case WM_LBUTTONDBLCLK:
	{
		POINT pt = { GET_X_LPARAM(lp), GET_Y_LPARAM(lp) };
		HWND child = ChildWindowFromPoint(wnd, pt);
		if (child == wnd)
		{
			unsigned p_panel = -1;
			if (find_by_divider_pt(pt, p_panel) && is_index_valid(p_panel))
			{
				bool b_have_next = is_index_valid(p_panel + 1);
				if (m_panels[p_panel]->m_locked && !m_panels[p_panel]->m_autohide && (!b_have_next || !m_panels[p_panel + 1]->m_locked))
				{
					m_panels[p_panel]->m_hidden = !m_panels[p_panel]->m_hidden;
					get_host()->on_size_limit_change(get_wnd(), uie::size_limit_all);
					on_size_changed();
				}
				else if (!m_panels[p_panel]->m_locked && b_have_next && m_panels[p_panel]->m_locked && !m_panels[p_panel]->m_autohide)
				{
					m_panels[p_panel + 1]->m_hidden = !m_panels[p_panel]->m_hidden;
					get_host()->on_size_limit_change(get_wnd(), uie::size_limit_all);
					on_size_changed();
				}
			}
		}
	}
	break;
	case WM_LBUTTONUP:
		if (m_panel_dragging_valid)
		{
			m_panel_dragging_valid = false;
			if (GetCapture() == wnd)
				ReleaseCapture();
			//SetCursor(LoadCursor(0, IDC_ARROW));
		}
		break;
#if 0
	case WM_PAINT:
	{
		PAINTSTRUCT ps;
		BeginPaint(wnd, &ps);
		COLORREF cr = GetSysColor(COLOR_3DFACE);
		gdi_object_t<HBRUSH>::ptr_t br_line = CreateSolidBrush(/*RGB(226, 226, 226)*/cr);

		t_size n, count = m_panels.get_count();
		for (n = 0; n + 1<count; n++)
		{
			pfc::refcounted_object_ptr_t<panel> p_item = m_panels.get_item(n);

			if (p_item->m_wnd_child)
			{
				RECT rc_area;
				GetRelativeRect(p_item->m_wnd_child, m_wnd, &rc_area);
				if (get_orientation() == vertical)
				{
					rc_area.top = rc_area.bottom;
					rc_area.bottom += 2;
					//FillRect(ps.hdc, &rc_area, GetSysColorBrush(COLOR_WINDOW));
					//rc_area.top++;
				}
				else
				{
					rc_area.left = rc_area.right;
					rc_area.right += 2;
					//FillRect(ps.hdc, &rc_area, GetSysColorBrush(COLOR_WINDOW));
					//rc_area.right--;
				}
				FillRect(ps.hdc, &rc_area, br_line);
			}
		}

		EndPaint(wnd, &ps);

	}
	;
#endif
#if 0
	case WM_CONTEXTMENU:
		if ((HWND)wp == wnd)
		{
			window_transparent_fill m_trans_fill;

			if (m_layout_editing_active)
			{
				RECT rc;
				GetRelativeRect(wnd, HWND_DESKTOP, &rc);
				ShowWindow(m_trans_fill.create(get_wnd(), 0, ui_helpers::window_position_t(rc)), SW_SHOWNORMAL);
				POINT pt = { GET_X_LPARAM(lp), GET_Y_LPARAM(lp) };

				HMENU menu = CreatePopupMenu();
				HMENU menu_add = CreatePopupMenu();
				uie::window_info_list_simple panels;
				g_get_panel_list(panels);
				enum { ID_CLOSE = 1, ID_ADD_BASE = 2 };
				g_append_menu_panels(menu_add, panels, ID_ADD_BASE);
				pfc::string8 temp;
				get_name(temp);
				uAppendMenu(menu, MF_STRING | MF_GRAYED, (UINT_PTR)0, temp);
				uAppendMenu(menu, MF_MENUBREAK, (UINT_PTR)0, NULL);
				AppendMenu(menu, MF_STRING | MF_POPUP, (UINT_PTR)menu_add, L"Add panel");

				int cmd = TrackPopupMenu(menu, TPM_RIGHTBUTTON | TPM_NONOTIFY | TPM_RETURNCMD, pt.x, pt.y, 0, m_trans_fill.get_wnd(), 0);
				DestroyMenu(menu);
				m_trans_fill.destroy();

				if (cmd)
				{
					if (cmd >= ID_ADD_BASE && cmd < panels.get_count() + ID_ADD_BASE)
					{
						pfc::refcounted_object_ptr_t<panel> ptr = new panel;
						ptr->m_guid = panels[cmd - ID_ADD_BASE].guid;
						m_panels.add_item(ptr);
						refresh_children();
						get_host()->on_size_limit_change(get_wnd(), uie::size_limit_all);
						uie::splitter_window_v2_ptr sw2;
						if (ptr->m_child.is_valid() && ptr->m_child->service_query_t(sw2))
						{
							sw2->enter_layout_editing_mode();
						}
					}
				}
			}
			return 0;
		}
		break;
#endif
	}
	return DefWindowProc(wnd, msg, wp, lp);
}
Example #8
0
LRESULT CALLBACK ColumnTreeWndProc(HWND hwnd, UINT iMessage, WPARAM
    wParam, LPARAM lParam)
{
    HTREEITEM titem;
    HD_LAYOUT hdl;
    WINDOWPOS wp;
    COLUMNINFO *ptr;
    RECT r,  *rp;
    HD_ITEM hie;
    TCHeader *h;
    HD_NOTIFY *n;
    TV_DISPINFO *t;
    LPTV_INSERTSTRUCT is;
    int i;
    TV_ITEM item;
    TCData *td;
    TV_HITTESTINFO tvh;
    TREEINFO *treeinfo;
    PAINTSTRUCT ps;
    HDC dc;
    NM_TREEVIEW *ntv;
    if (iMessage >= TV_FIRST && iMessage < TV_FIRST + 100)
    {
        ptr = (COLUMNINFO*)GetWindowLong(hwnd, 0);
        switch (iMessage)
        {
            case TVM_HITTEST:
                tvh.pt = ((TV_HITTESTINFO*)lParam)->pt;
                ptr = (COLUMNINFO*)GetWindowLong(hwnd, 0);
                GetRelativeRect(hwnd, ptr->hwndTree, &r);
                tvh.pt.x -= r.left;
                tvh.pt.y -= r.top;
                if ((titem = TreeView_HitTest(ptr->hwndTree, &tvh)))
                {
                    ((TV_HITTESTINFO*)lParam)->flags = tvh.flags;
                    ((TV_HITTESTINFO*)lParam)->hItem = tvh.hItem;
                }
                return (LRESULT)titem;
            case TVM_INSERTITEM:
                is = (LPTV_INSERTSTRUCT)lParam;
                is->UNNAMED_UNION item.mask |= TVIF_TEXT | TVIF_PARAM;
                is->UNNAMED_UNION item.pszText = LPSTR_TEXTCALLBACK;
                titem = (HTREEITEM)SendMessage(ptr->hwndTree, iMessage, wParam,
                    lParam);
                return (LRESULT)titem;
            default:
                return SendMessage(ptr->hwndTree, iMessage, wParam, lParam);
        }
    }
    else if (iMessage >= HDM_FIRST && iMessage < HDM_FIRST + 100)
    {
        ptr = (COLUMNINFO*)GetWindowLong(hwnd, 0);
        return SendMessage(ptr->hwndHeader, iMessage, wParam, lParam);
    }
    switch (iMessage)
    {
        case WM_ERASEBKGND:
            return 1;
        case WM_NOTIFY:
            n = (HD_NOTIFY*)lParam;
            ptr = (COLUMNINFO*)GetWindowLong(hwnd, 0);
            switch (n->hdr.code)
            {
            case NM_RCLICK:
                #ifdef XXXXX
                    ptr = (COLUMNINFO*)GetWindowLong(hwnd, 0);
                    GetCursorPos(&pos);
                    ScreenToClient(ptr->hwndTree, &pos);
                    titem = TreeView_HitTest(ptr->hwndTree, &pos);
                    for (i = 0; i < ptr->displaycount; i++)
                    if (titem == ptr->displaylist[i])
                    {
                        ptr->sel = i;
                        InvalidateRect(ptr->hwndTree, 0, 0);
                        break;
                    }
                #endif 
                return SendMessage(GetParent(hwnd), iMessage, wParam, lParam);
            case TVN_SELCHANGING:
                return TRUE;
            case HDN_ENDTRACK:
                SendMessage(ptr->hwndTree, TCF_SETDIVIDER, 0, n->pitem->cxy);
                InvalidateRect(ptr->hwndTree, 0, 1);
                return 0;
            case TVN_GETDISPINFO:
                t = (LPNMTVDISPINFO)n;
                if (TreeView_GetItemRect(ptr->hwndTree, t->item.hItem, &r, TRUE)
                    )
                {
                    if (ptr->displaycount < DISPLAY_MAX)
                        ptr->displaylist[ptr->displaycount++] = t->item.hItem;
                    strcpy(t->item.pszText, "");
//                    t->item.cchTextMax = 0;
                }
                return 0;
            case TVN_DELETEITEM:
                ntv = (NM_TREEVIEW*)lParam;
                if (ptr->displaycount)
                    for (i = 0; i < ptr->displaycount; i++)
                if (ptr->displaylist[i] == ntv->itemOld.hItem)
                {
                    ptr->sel =  - 1;
                    memcpy(&ptr->displaylist[i], &ptr->displaylist[i + 1], (ptr
                        ->displaycount - i - 1) *sizeof(HTREEITEM));
                    ptr->displaycount--;
                    return 0;
                }
                return 0;
            }
            // fall through 
        case WM_COMMAND:
            return SendMessage(GetParent(hwnd), iMessage, wParam, lParam);
        case WM_CREATE:
            ptr = (COLUMNINFO*)calloc(1, sizeof(COLUMNINFO)
                );
            ptr->displaycount = 0;
            ptr->sel =  - 1;
            SetWindowLong(hwnd, 0, (int)ptr);
            GetClientRect(hwnd, &r);
            ptr->hwndHeader = CreateWindow(WC_HEADER, 0, WS_CLIPSIBLINGS |
                WS_CHILD | HDS_HORZ | WS_BORDER, r.left, r.top, r.right -
                r.left, r.bottom - r.top, hwnd, 0, (HINSTANCE)GetWindowLong
                (GetParent(hwnd), GWL_HINSTANCE), 0);
            hdl.prc = &r;
            hdl.pwpos = &wp;
            SendMessage(ptr->hwndHeader, HDM_LAYOUT, 0, (LPARAM) &hdl);
            //         wp.x += 2*GetSystemMetrics(SM_CXDLGFRAME );
            //         wp.cx -= 4 * GetSystemMetrics(SM_CXDLGFRAME) ;
            //         wp.y += 2*GetSystemMetrics(SM_CYDLGFRAME );
            //         wp.cy -= 4 * GetSystemMetrics(SM_CYDLGFRAME) ;
            ptr->watchFont = CreateFontIndirect(&systemDialogFont);
            SendMessage(ptr->hwndHeader, WM_SETFONT, (WPARAM)ptr->watchFont, 0);
            SetWindowPos(ptr->hwndHeader, wp.hwndInsertAfter, wp.x, wp.y, wp.cx,
                wp.cy, wp.flags | SWP_SHOWWINDOW);
            r.left = wp.x;
            r.right = wp.x + wp.cx;
            r.top = wp.y + wp.cy;
            ptr->hwndTree = CreateWindowEx(0, szextTreeWindClassName, 0,
                WS_CLIPSIBLINGS | WS_VISIBLE | WS_CHILD | WS_BORDER |
                TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS, r.left, r.top,
                r.right - r.left, r.bottom - r.top, hwnd, (HMENU)1000, 
                (HINSTANCE)GetWindowLong(GetParent(hwnd), GWL_HINSTANCE), 0);
            SendMessage(ptr->hwndTree, WM_SETFONT, (WPARAM)ptr->watchFont, 0);
            hie.mask = HDI_WIDTH;
            SendMessage(ptr->hwndHeader, HDM_GETITEM, 0, (LPARAM) &hie);
            SendMessage(ptr->hwndTree, TCF_SETDIVIDER, 0, hie.cxy);
            break;

        case WM_DESTROY:
            ptr = (COLUMNINFO*)GetWindowLong(hwnd, 0);
            DestroyWindow(ptr->hwndHeader);
            DeleteObject(ptr->watchFont);
            free((void*)ptr);
            break;
        case WM_LBUTTONDOWN:
        case WM_RBUTTONDOWN:
            break;
        case WM_SIZE:
            ptr = (COLUMNINFO*)GetWindowLong(hwnd, 0);
            r.left = r.top = 0;
            r.right = LOWORD(lParam);
            r.bottom = HIWORD(lParam);
            hdl.prc = &r;
            hdl.pwpos = &wp;
            SendMessage(ptr->hwndHeader, HDM_LAYOUT, 0, (LPARAM) &hdl);
            //         wp.x += 2*GetSystemMetrics(SM_CXDLGFRAME );
            //         wp.cx -= 4 * GetSystemMetrics(SM_CXDLGFRAME) ;
            //         wp.y += 2*GetSystemMetrics(SM_CYDLGFRAME );
            //         wp.cy -= 4 * GetSystemMetrics(SM_CYDLGFRAME) ;
            SetWindowPos(ptr->hwndHeader, wp.hwndInsertAfter, wp.x, wp.y, wp.cx,
                wp.cy, wp.flags);
            r.left = wp.x;
            r.right = wp.x + wp.cx;
            r.top = wp.y + wp.cy;
            MoveWindow(ptr->hwndTree, r.left, r.top, r.right - r.left, r.bottom
                - r.top, 0);
            GetClientRect(ptr->hwndHeader, &r);
            hie.mask = HDI_WIDTH;
            hie.cxy = (r.right - r.left) / 2;
            SendMessage(ptr->hwndHeader, HDM_SETITEM, 0, (LPARAM) &hie);
            SendMessage(ptr->hwndHeader, HDM_SETITEM, 1, (LPARAM) &hie);
            SendMessage(ptr->hwndTree, TCF_SETDIVIDER, 0, hie.cxy);
            InvalidateRect(ptr->hwndHeader, 0, 1);
            InvalidateRect(ptr->hwndTree, 0, 1);
            break;
        case TCF_SETHEADER:
            ptr = (COLUMNINFO*)GetWindowLong(hwnd, 0);
            h = (TCHeader*)lParam;
            GetWindowRect(ptr->hwndHeader, &r);
            hie.mask = HDI_TEXT | HDI_FORMAT | HDI_WIDTH;
            if (h->colBmp1)
                    hie.mask |= HDI_BITMAP;
            hie.pszText = h->colText1;
            hie.hbm = h->colBmp1;
            hie.cxy = (r.right - r.left) / 2;
            hie.cchTextMax = strlen(h->colText1);
            hie.fmt = HDF_LEFT | HDF_STRING;
            SendMessage(ptr->hwndHeader, HDM_INSERTITEM, 100, (LPARAM) &hie);
            hie.mask = HDI_TEXT | HDI_FORMAT | HDI_WIDTH;
            if (h->colBmp2)
                hie.mask |= HDI_BITMAP;
            hie.pszText = h->colText2;
            hie.hbm = h->colBmp2;
            hie.cxy = (r.right - r.left) / 2;
            hie.cchTextMax = strlen(h->colText2);
            hie.fmt = HDF_LEFT | HDF_STRING;
            SendMessage(ptr->hwndHeader, HDM_INSERTITEM, 100, (LPARAM) &hie);
            SendMessage(ptr->hwndTree, TCF_SETDIVIDER, 0, hie.cxy);
            return 0;
        case WM_PAINT:
            dc = BeginPaint(hwnd, &ps);
            EndPaint(hwnd, &ps);
            break;
        case WM_ACTIVATEME:
            SendMessage(GetParent(hwnd), WM_ACTIVATEME, 0, 0);
            break;
        case WM_SETFONT:
        case WM_GETFONT:
            ptr = (COLUMNINFO*)GetWindowLong(hwnd, 0);
            return SendMessage(ptr->hwndTree, iMessage, wParam, lParam);
        case TCN_PAINT:
            rp = (RECT*)lParam;
            ptr = (COLUMNINFO*)GetWindowLong(hwnd, 0);
            {
                hie.mask = HDI_WIDTH;
                SendMessage(ptr->hwndHeader, HDM_GETITEM, 0, (LPARAM) &hie);
                hie.cxy -= GetSystemMetrics(SM_CXBORDER);
                rp->left = hie.cxy;
                if (rp->left < rp->right)
                {
                    LOGBRUSH lbrush;
                    HBRUSH graybrush;
                    HDC dc = (HDC)wParam;
                    int lined = FALSE;
                    HFONT font = (HFONT)SendMessage(ptr->hwndTree, WM_GETFONT,
                        0, 0);
                    lbrush.lbStyle = BS_SOLID;
                    lbrush.lbColor = 0xff0000;
                    graybrush = CreateBrushIndirect(&lbrush);
//                    dc = GetDC(ptr->hwndTree);
                    font = SelectObject(dc, font);
                    if (GetWindowLong(hwnd, GWL_STYLE) &TCS_LINE)
                    {
                        HPEN pen;
                        pen = CreatePen(PS_SOLID, 1, 0);

                        lined = TRUE;
                        pen = SelectObject(dc, pen);
                        MoveToEx(dc, rp->left, rp->top, 0);
                        LineTo(dc, rp->left, rp->bottom + 1);
                        pen = SelectObject(dc, pen);
                        DeleteObject(pen);
                    }
                    for (i = 0; i < ptr->displaycount; i++)
                    {
                        COLORREF color, bgcolor;
                        item.hItem = ptr->displaylist[i];
                        item.mask = TVIF_PARAM;
                        TreeView_GetItem(ptr->hwndTree, &item);
                        td = (TCData*)item.lParam;
                        TreeView_GetItemRect(ptr->hwndTree, ptr->displaylist[i],
                            &r, TRUE);
                        if (td->col1Text)
                        {
                            HRGN rgn;
                            rgn = CreateRectRgn(r.left, r.top, rp->left - 2,
                                r.bottom);
                            SelectClipRgn(dc, rgn);
                            if (ptr->sel == i)
                            {
                                color = SetTextColor(dc, RetrieveSysColor(COLOR_WINDOW));
                                bgcolor = SetBkColor(dc, td->col1Color);
                            }
                            else
                                color = SetTextColor(dc, td->col1Color);
                            TextOut(dc, r.left, r.top, td->col1Text, strlen(td
                                ->col1Text));
                            SetTextColor(dc, color);
                            if (ptr->sel == i)
                                SetBkColor(dc, bgcolor);
                            SelectClipRgn(dc, NULL);
                            DeleteObject(rgn);
                        }
                        if (td->col2Text)
                        {
                            if (ptr->sel == i)
                            {
                                color = SetTextColor(dc, RetrieveSysColor(COLOR_WINDOW));
                                bgcolor = SetBkColor(dc, td->col2Color);
                            }
                            else
                                color = SetTextColor(dc, td->col2Color);
                            TextOut(dc, rp->left + (lined ? 3 : 0), r.top, td
                                ->col2Text, strlen(td->col2Text));
                            SetTextColor(dc, color);
                            if (ptr->sel == i)
                                SetBkColor(dc, bgcolor);
                        }
                    }
                    SelectObject(dc, font);
//                    ReleaseDC(ptr->hwndTree, dc);
                    DeleteObject(graybrush);

                }
                ptr->displaycount = 0;
            }
            break;
    }
    return DefWindowProc(hwnd, iMessage, wParam, lParam);
}