+++ /dev/null
-#pragma once
-
-
-
-namespace nlite{
-
-
-
-
- const static LPCTSTR LISTVIEW_EX = TEXT("NLITE_LISTVIEW");
-
-
- const static UINT_PTR headerHaight = 20;
-
- template<typename TBase>
- class ATL_NO_VTABLE CListViewEx:public CWindowImpl<TBase>{
-
- private:
- TBase *t;
-
-
- protected:
-
- VOID Lock(){
- ccs.Lock();
- }
-
- VOID Unlock(){
- ccs.Unlock();
- }
-
- protected:
-
- CHeaderCtrl header;
- CListBox listBox;
- CComAutoCriticalSection ccs;
-
-
-#define NLITE_HEADER_ID (257)
-#define NLITE_LIST_ID (258)
- const UINT headerID;
- const UINT listBoxID;
- HFONT hHeaderFontNew;
- SCROLLINFO hScrollInfo;
-
-
- public:
-
- CListViewEx():
- headerID(NLITE_HEADER_ID),
- listBoxID(NLITE_LIST_ID),
- t((TBase*)this),
- hScrollInfo()
- {
- hScrollInfo.fMask = SIF_ALL;
- hScrollInfo.cbSize = sizeof(hScrollInfo);
- LOGFONT lf = {0};
- lf.lfHeight = 10;
- lf.lfCharSet = SHIFTJIS_CHARSET;
-
-
- hHeaderFontNew = CreateFontIndirect(&lf);
-
-
- }
-
- ~CListViewEx(){
-
- DeleteObject(hHeaderFontNew);
-
- }
-
-
- DECLARE_WND_CLASS_EX(LISTVIEW_EX,0,COLOR_BACKGROUND)
- //\83\81\83b\83Z\81[\83W\83}\83b\83v
- BEGIN_MSG_MAP(tn)
- MSG_WM_CREATE(OnCreate)
- MSG_WM_DESTROY(OnDestroy)
- MSG_WM_DRAWITEM(OnDrawItem)
- MSG_WM_MEASUREITEM(OnMersureItem)
- MSG_WM_SIZING(OnSizing)
- MSG_WM_SIZE(OnSize)
- MSG_WM_PAINT(OnPaint)
- MSG_WM_HSCROLL(OnHScroll)
- MSG_WM_ERASEBKGND(OnEraseBkgnd)
- COMMAND_CODE_HANDLER_EX(LBN_DBLCLK,OnListBoxDoubleClick)
- NOTIFY_CODE_HANDLER_EX(HDN_ITEMCHANGED ,OnheaderItemChanged)
- NOTIFY_CODE_HANDLER_EX(HDN_ENDDRAG ,OnHeaderEndDrag)
- END_MSG_MAP()
-
-
- ///
- ///\94w\8ci\95`\89æ\8f\88\97\9d
- ///
- VOID OnPaint(HDC wParam){
- PAINTSTRUCT paintStruct;
- HDC paintDC = this->BeginPaint(&paintStruct);
- HPEN hPen = (HPEN)GetStockPen(NULL_PEN);
- HPEN oldPen = (HPEN)::SelectObject(paintDC,hPen);
- HBRUSH brush = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
- HBRUSH oldBrush = (HBRUSH)::SelectObject(paintDC,brush);
-
- ::Rectangle(paintDC,paintStruct.rcPaint.left,paintStruct.rcPaint.top,paintStruct.rcPaint.right,paintStruct.rcPaint.bottom);
- this->EndPaint(&paintStruct);
- ::SelectObject(paintDC,oldBrush);
- ::SelectObject(paintDC,oldPen);
-
- return;
- }
-
- //\83T\83C\83Y\95Ï\8dX\92\86
- VOID OnSizing(UINT wParam,LPRECT lParam){
-
- RECT client;
- GetClientRect(&client);
-
- ChangeSize( _WTYPES_NS::CSize(client.right - client.left,client.bottom - client.top));
-
-
- return;
-
- }
-
- //\83T\83C\83Y\95Ï\8dX\8cã
- LRESULT OnSize(UINT wParam,SIZE lParam){
- ChangeSize(lParam);
-
- return 0;
- }
-
- //\83T\83C\83Y\95Ï\8dX\8f\88\97\9d
- VOID ChangeSize(const SIZE& client){
- listBox.MoveWindow(0,headerHaight,hScrollInfo.nMax,client.cy - headerHaight);
- hScrollInfo.nPage = client.cx;
- this->SetScrollInfo(SB_HORZ,&hScrollInfo);
- RECT bkRect = {0};
- bkRect.right = client.cx - hScrollInfo.nMax;
- bkRect.bottom = client.cy;
- this->InvalidateRect(&bkRect);
-
- return;
- }
-
- //\83`\83\89\83c\83L\82ð\82È\82\82·
- LRESULT OnEraseBkgnd(HDC wParam){
-
- return TRUE;
- }
-
-
- VOID OnDestroy(){
- t->OnDestroy();
- header.DestroyWindow();
- listBox.DestroyWindow();
- return;
-
- }
-
- LRESULT OnheaderItemChanged(LPNMHDR lParam){
-
- if(lParam->hwndFrom == header.m_hWnd){
-
- t->OnHeaderItemChanged();
-
- INT_PTR itemCount = header.GetItemCount();
- RECT itemSizeRect;
- hScrollInfo.nMax = 0;
- for(INT_PTR imtemIndex = 0;imtemIndex < itemCount;imtemIndex++){
- header.GetItemRect(imtemIndex,&itemSizeRect);
- hScrollInfo.nMax += itemSizeRect.right - itemSizeRect.left;
-
- }
-
- this->SetScrollInfo(SB_HORZ,&hScrollInfo,TRUE);
- DecisionHorzSize();
-
- }
-
- return 0;
- }
-
- LRESULT OnHeaderEndDrag(LPNMHDR lParam){
-
- if(lParam->hwndFrom == header.m_hWnd){
-
- listBox.InvalidateRect(NULL,TRUE);
-
- }
-
- return 0;
- }
-
-
- LRESULT OnListBoxDoubleClick(UINT uNotifyCode, int nID, CWindow wndCtl){
-
- if(wndCtl.m_hWnd == listBox.m_hWnd){
-
- t->OnListBoxDoubleClick();
- }
-
- return 0;
- }
-
- ///
- ///\89¡\83X\83N\83\8d\81[\83\8b\8e\9e\82Ì\8f\88\97\9d
- ///
- VOID OnHScroll(INT_PTR loWParam,SHORT hiWParam,HWND lParam){
-
-
- INT_PTR dy;
- switch(loWParam){
-
- case SB_THUMBTRACK:
- dy = hiWParam - hScrollInfo.nPos;
- break;
-
- default:
- dy = 0;
- break;
-
- }
-
-
- hScrollInfo.nPos += dy;
- RECT headerPosRect;
- RECT listBoxPosRect;
- header.GetWindowRect(&headerPosRect);
- listBox.GetWindowRect(&listBoxPosRect);
- INT_PTR moveRange = -(hScrollInfo.nPos);
- headerPosRect.bottom -= headerPosRect.top;
- headerPosRect.top = 0;
- headerPosRect.right += moveRange - headerPosRect.left;
- headerPosRect.left = moveRange;
-
- listBoxPosRect.bottom -= (listBoxPosRect.top - headerHaight);
- listBoxPosRect.top = headerHaight;
- listBoxPosRect.right += moveRange - listBoxPosRect.left;
- listBoxPosRect.left = moveRange;
-
- header.MoveWindow(&headerPosRect);
- listBox.MoveWindow(&listBoxPosRect);
-
-
-
-
- HDWP hDwp = BeginDeferWindowPos(2);
-
- header.DeferWindowPos(hDwp,header.m_hWnd,headerPosRect.left,headerPosRect.top,headerPosRect.right,headerPosRect.bottom,SWP_NOSIZE | SWP_NOZORDER);
- listBox.DeferWindowPos(hDwp,listBox.m_hWnd,listBoxPosRect.left,listBoxPosRect.top,listBoxPosRect.right,listBoxPosRect.bottom,SWP_NOSIZE | SWP_NOZORDER);
-
- EndDeferWindowPos(hDwp);
-
-
- this->SetScrollInfo(SB_HORZ,&hScrollInfo);
-
-
- return;
- }
-
- LRESULT OnCreate(LPCREATESTRUCT lpcs){
- header.Create(m_hWnd,0,WC_HEADER,WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | HDS_BUTTONS | HDS_HOTTRACK |HDS_DRAGDROP | HDS_FULLDRAG ,0,headerID);
- listBox.Create(m_hWnd,0,WC_LISTBOX,WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_CLIPCHILDREN | LBS_OWNERDRAWVARIABLE | LBS_NOTIFY | LBS_NOREDRAW ,0,listBoxID);
- listBox.SetFont(AtlGetDefaultGuiFont());
-
-
- return 0;
- }
-
-
-
- protected:
- HWND Create(HWND hWndParent,ATL::_U_MENUorID menuOrID){
-
- return __super::Create(hWndParent,0,LISTVIEW_EX,WS_VISIBLE | WS_CHILD | WS_HSCROLL | WS_BORDER,0,menuOrID);
-
- }
-
- VOID AddHeader(LPHEADERSINFO infos){
-
-
- header.SetFont(hHeaderFontNew);
-
- HDITEM item;
- item.mask = HDI_FORMAT | HDI_TEXT | HDI_WIDTH;
- item.fmt = HDF_CENTER | HDF_STRING;
-
-
- for(UINT_PTR index = 0;index < infos->count ;++index){
-
- item.pszText = infos->columns[index];
-
- item.cxy = infos->holizensize[index];
- hScrollInfo.nMax += infos->holizensize[index];
- header.InsertItem(index,&item);
- }
-
- this->SetScrollInfo(SB_HORZ,&hScrollInfo,TRUE);
- DecisionHorzSize();
- return;
- }
-
- VOID DecisionHorzSize(){
-
-
- HDWP hWindowPosInfo = BeginDeferWindowPos(2);
- RECT bkWindowRect;
- this->GetClientRect(&bkWindowRect);
- header.DeferWindowPos(hWindowPosInfo,header.m_hWnd,0,0,hScrollInfo.nMax,headerHaight,SWP_NOZORDER | SWP_NOMOVE);
- listBox.DeferWindowPos(hWindowPosInfo,header.m_hWnd,0,0,hScrollInfo.nMax,bkWindowRect.bottom - headerHaight,SWP_NOZORDER | SWP_NOMOVE);
-
- EndDeferWindowPos(hWindowPosInfo);
- bkWindowRect.left = hScrollInfo.nMax;
-
- this->InvalidateRect(&bkWindowRect);
-
- return;
- }
-
- VOID OnMersureItem(UINT wParam, LPMEASUREITEMSTRUCT lParam){
-
- if(lParam->CtlID == listBoxID){
-
- t->OnMersureItem(lParam);
-
- }
-
- return;
- }
-
- VOID OnDrawItem(UINT wParam,LPDRAWITEMSTRUCT lParam){
-
- switch(wParam){
-
- case NLITE_LIST_ID:
-
- if(lParam->hwndItem == listBox.m_hWnd && listBox.GetCount() > 0){
-
- t->OnDrawList(lParam);
-
- }
-
- break;
-
- }
-
- return;
- }
-
-
- };
-
-
-
-}
\ No newline at end of file