source: trunk/Utilities/FileMappingVirtualAddress/MainDialog.h @ 42

Last change on this file since 42 was 42, checked in by roman, 12 years ago
  • Property svn:keywords set to Id
File size: 4.9 KB
Line 
1////////////////////////////////////////////////////////////
2// MainDialog.h
3//
4// Created by Roman Ryltsov roman@alax.info
5//
6// $Id: MainDialog.h 42 2011-12-15 09:43:16Z roman $
7
8#pragma once
9
10#include <tlhelp32.h>
11#include <atlsecurity.h>
12
13////////////////////////////////////////////////////////////
14// CMainDialog
15
16class CMainDialog : 
17        public CDialogImpl<CMainDialog>,
18        public CDialogResize<CMainDialog>
19{
20public:
21
22        enum { IDD = IDD_MAIN };
23
24BEGIN_MSG_MAP_EX(CMainDialog)
25        //CHAIN_MSG_MAP(CDialogImpl<CMainDialog>)
26        CHAIN_MSG_MAP(CDialogResize<CMainDialog>)
27        MSG_WM_INITDIALOG(OnInitDialog)
28        MSG_WM_DESTROY(OnDestroy)
29        MSG_WM_TIMER(OnTimer)
30        COMMAND_ID_HANDLER_EX(IDCANCEL, OnCancel)
31        MSG_LVN_ITEMCHANGED(IDC_MAIN_LIST, OnListViewItemChanged)
32        //MSG_LVN_GETDISPINFO(IDC_MAIN_LIST, OnListViewGetDispInfo)
33        //MSG_LVN_GETINFOTIP(IDC_MAIN_LIST, OnListViewGetInfoTip)
34        REFLECT_NOTIFICATIONS()
35END_MSG_MAP()
36
37BEGIN_DLGRESIZE_MAP(CMainDialog)
38    DLGRESIZE_CONTROL(IDC_MAIN_LIST, DLSZ_SIZE_X | DLSZ_SIZE_Y)
39    DLGRESIZE_CONTROL(IDCANCEL, DLSZ_MOVE_X)
40END_DLGRESIZE_MAP()
41
42public:
43
44        ////////////////////////////////////////////////////////
45        // Timer identifiers
46
47        enum
48        {
49                TIMER_FIRST = 0,
50                TIMER_UPDATE,
51        };
52
53        ////////////////////////////////////////////////////////
54        // CData
55
56        class CData
57        {
58        private:
59                const SIZE_T m_nSize;
60                CHandle m_FileMappingHandle;
61                VOID* m_pvData;
62
63        public:
64        // CData
65                CData() throw() :
66                        m_nSize(256 << 20), // 256M
67                        m_pvData(NULL)
68                {
69                }
70                ~CData() throw()
71                {
72                        SetMapped(FALSE);
73                }
74                VOID Initialize()
75                {
76                        _A(!((ULONGLONG) m_nSize >> 32));
77                        m_FileMappingHandle.Attach(CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, (DWORD) m_nSize, NULL));
78                        __E(m_FileMappingHandle);
79                }
80                SIZE_T GetSize() const throw()
81                {
82                        return m_nSize;
83                }
84                BOOL IsMapped() const throw()
85                {
86                        return m_pvData != NULL;
87                }
88                VOID SetMapped(BOOL bMapped)
89                {
90                        if(!m_FileMappingHandle)
91                                return;
92                        if(bMapped)
93                        {
94                                if(!m_pvData)
95                                {
96                                        m_pvData = MapViewOfFile(m_FileMappingHandle, FILE_MAP_ALL_ACCESS, 0, 0, m_nSize);
97                                        __E(m_pvData);
98                                }
99                        } else
100                        {
101                                if(m_pvData)
102                                {
103                                        UnmapViewOfFile(m_pvData);
104                                        m_pvData = NULL;
105                                }
106                        }
107                }
108        };
109
110private:
111        CData m_pDatas[64];
112        BOOL m_bActivating;
113        CString m_sDefaultCaption;
114        CRoListViewT<CData*> m_ListView;
115
116public:
117// CMainDialog
118        CMainDialog() throw()
119        {
120        }
121
122// Window message handelrs
123        LRESULT OnInitDialog(HWND, LPARAM)
124        {
125                m_bActivating = TRUE;
126                CWaitCursor WaitCursor;
127                #pragma region Show Platform in Caption
128#if defined(_WIN64)
129                CString sCaption;
130                GetWindowText(sCaption);
131                sCaption += _T(" (x64)");
132                SetWindowText(sCaption);
133#endif // defined(_WIN64)
134                #pragma endregion
135                m_ListView.Initialize(GetDlgItem(IDC_MAIN_LIST));
136                m_ListView.SendMessage(CCM_SETVERSION, COMCTL32_VERSION);
137                _ATLTRY
138                {
139                        for(SIZE_T nIndex = 0; nIndex < DIM(m_pDatas); nIndex++)
140                        {
141                                m_pDatas[nIndex].Initialize();
142                                const INT nItem = m_ListView.InsertItem((INT) nIndex, m_pDatas + nIndex, AtlFormatString(_T("Block %02d"), nIndex));
143                                _A(nItem == (INT) nIndex);
144                                m_ListView.SetItemText(nItem, 1, AtlFormatString(_T("%dM"), m_pDatas[nIndex].GetSize() >> 20));
145                        }
146                }
147                _ATLCATCHALL()
148                {
149                        _Z_EXCEPTION();
150                }
151                GetWindowText(m_sDefaultCaption);
152                DlgResize_Init();
153                _W(CenterWindow());
154                SetTimer(TIMER_UPDATE, 1000); // 1 second
155                m_bActivating = FALSE;
156                return TRUE;
157        }
158        LRESULT OnDestroy()
159        {
160                return 0;
161        }
162        LRESULT OnTimer(UINT_PTR nEvent)
163        {
164                switch(nEvent)
165                {
166                case TIMER_UPDATE:
167                        {
168                                MEMORYSTATUSEX MemoryStatus;
169                                ZeroMemory(&MemoryStatus, sizeof MemoryStatus);
170                                MemoryStatus.dwLength = sizeof MemoryStatus;
171                                _W(GlobalMemoryStatusEx(&MemoryStatus));
172                                SetWindowText(AtlFormatString(_T("%dM / %dM - %s"), (ULONG) ((MemoryStatus.ullTotalVirtual - MemoryStatus.ullAvailVirtual) >> 20), (ULONG) (MemoryStatus.ullTotalVirtual >> 20), m_sDefaultCaption));
173                        }
174                        break;
175                }
176                SetMsgHandled(FALSE);
177                return 0;
178        }
179        LRESULT OnListViewItemChanged(NMLISTVIEW* pHeader)
180        {
181                if(m_bActivating)
182                        return 0;
183                m_ListView.UpdateCheckState(pHeader);
184                _ATLTRY
185                {
186                        for(SIZE_T nIndex = 0; nIndex < DIM(m_pDatas); nIndex++)
187                                m_pDatas[nIndex].SetMapped(m_ListView.GetCheckState((INT) nIndex));
188                }
189                _ATLCATCHALL()
190                {
191                        for(SIZE_T nIndex = 0; nIndex < DIM(m_pDatas); nIndex++)
192                                m_ListView.SetCheckState((INT) nIndex, m_pDatas[nIndex].IsMapped());
193                        _ATLRETHROW;
194                }
195                return 0;
196        }
197        LRESULT OnListViewGetDispInfo(NMLVDISPINFO* pHeader)
198        {
199                CString& sTextBuffer = m_ListView.GetTextBufferString(TRUE);
200                CData* pData = m_ListView.DataFromParameter(pHeader->item.lParam);
201                //sTextBuffer = ...
202                pHeader->item.pszText = m_ListView.GetTextBuffer();
203                return 0;
204        }
205        LRESULT OnCancel(UINT, INT nIdentifier, HWND)
206        {
207                _W(EndDialog(nIdentifier));
208                return 0;
209        }
210};
211
Note: See TracBrowser for help on using the repository browser.