summaryrefslogtreecommitdiff
path: root/Shutdown/ItemDlg.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Shutdown/ItemDlg.cpp')
-rw-r--r--Shutdown/ItemDlg.cpp195
1 files changed, 195 insertions, 0 deletions
diff --git a/Shutdown/ItemDlg.cpp b/Shutdown/ItemDlg.cpp
new file mode 100644
index 0000000..04c6264
--- /dev/null
+++ b/Shutdown/ItemDlg.cpp
@@ -0,0 +1,195 @@
+// ItemDlg.cpp : implementation file
+//
+
+#include "stdafx.h"
+#include "ItemDlg.h"
+
+
+
+/////////////////////////////////////////////////////////////////////////////
+// CItemDlg dialog
+
+
+CItemDlg::CItemDlg()
+ : CDialogImplEx(IDD), CPersistPosWindow<CItemDlg>(_T("Item"))
+{
+ m_hIcon = ::LoadIcon(_Module.m_hInst, MAKEINTRESOURCE(IDR_MAINFRAME));
+ m_bCancel = false;
+}
+
+
+/////////////////////////////////////////////////////////////////////////////
+// CItemDlg message handlers
+
+//////////////////////////////////////////////////////////////////
+// Since we can't really cancel the current component
+// Set flag and wait till there's a chance to close
+
+LRESULT CItemDlg::OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
+{
+ g_site.Fire_Cancel();
+ m_bCancel = true;
+
+ // Give a visual indication that request has been handled
+ SetDlgItemText(IDCANCEL, _T("Cancelling..."));
+ ::EnableWindow(GetDlgItem(IDCANCEL), FALSE);
+
+ return 0;
+}
+
+LRESULT CItemDlg::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+{
+ OnCancel(0, 0, NULL, bHandled);
+ return 0;
+}
+
+//////////////////////////////////////////////////////////////////
+// InitDialog (what more can I say)
+
+LRESULT CItemDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+{
+ // Set the icon for this dialog.
+ SetIcon(m_hIcon, TRUE); // Set big icon
+ SetIcon(m_hIcon, FALSE); // Set small icon
+
+
+ // Create the small icon image list.
+ m_ImageListSmall.Create(IDB_CHECKS,
+ 16,
+ 0, // list won't grow
+ RGB(255, 0, 255));
+
+ // Set Mask color for Image Lists
+ m_ImageListSmall.SetBkColor(CLR_NONE);
+
+ m_ctlItems = GetDlgItem(IDC_ITEMS);
+
+ // Associate the image lists with the list view control.
+ m_ctlItems.SetImageList(m_ImageListSmall, LVSIL_SMALL);
+
+
+
+ // We need at least one bogus column since we're using
+ // report view
+
+ LV_COLUMN lvC; // list view column structure
+
+ // Now initialize the columns you will need.
+ // Initialize the LV_COLUMN structure.
+ // The mask specifies that the fmt, width, pszText, and subitem members
+ // of the structure are valid.
+ lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
+ lvC.fmt = LVCFMT_LEFT; // left-align column
+ lvC.cx = 200; // width of column in pixels
+ lvC.iSubItem = 0;
+ lvC.pszText = "Item";
+
+ if (m_ctlItems.InsertColumn(0, &lvC) == -1)
+ return true;
+
+
+ // Fill List Control
+ // Get Names of Windows Components
+ // string_array was passed in Create
+ // Loop through Items and get the names for Dialog box
+ for(int nCnt = 0; nCnt < g_aComponents.size(); nCnt++)
+ {
+
+ // If it's a Windows Component
+ if(g_aComponents[nCnt]->GetType() == COMPONENT_WIN)
+
+ // If it's currently active
+ if(g_aComponents[nCnt]->IsEnabled())
+
+ // Add it's name
+ m_ctlItems.InsertItem(LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM,
+ nCnt, g_aComponents[nCnt]->GetName(), 0, 0, 0, nCnt);
+
+ }
+
+ // Try and hide the control as best we can
+ m_ctlItems.SetBkColor(::GetSysColor(COLOR_3DFACE));
+ m_ctlItems.SetTextBkColor(::GetSysColor(COLOR_3DFACE));
+
+
+ // Make sure the column (although hidden from dlg template)
+ // is the width of control
+
+ RECT rect;
+ m_ctlItems.GetClientRect(&rect);
+ m_ctlItems.SetColumnWidth(0, rect.right);
+
+
+ // See if we can get the Window Position
+ if(!LoadPosition(_Module.m_settings))
+ {
+ // Move the Window to 50, 50
+ GetWindowRect(&rect);
+ MoveWindow(50, 50, rect.right - rect.left, rect.bottom - rect.top);
+ }
+
+ return TRUE; // return TRUE unless you set the focus to a control
+ // EXCEPTION: OCX Property Pages should return FALSE
+}
+
+LRESULT CItemDlg::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+{
+ SavePosition(_Module.m_settings);
+ return 0;
+}
+
+//////////////////////////////////////////////////////////////////
+// Gives the item a pointer image and scrolls it into view
+
+bool CItemDlg::SetCurrentItem(int nItem)
+{
+ // Setup Structures
+ LV_ITEM lv;
+
+ lv.mask = LVIF_IMAGE;
+ lv.iSubItem = 0;
+ lv.iItem = nItem;
+ lv.iImage = 1;
+
+
+ // Scroll to item
+ m_ctlItems.EnsureVisible(nItem, false);
+
+ // Give the item the right image
+ return m_ctlItems.SetItem(&lv) ? true : false;
+}
+
+//////////////////////////////////////////////////////////////////
+// Gives the item a tick or cross image depending on bState
+
+bool CItemDlg::CheckOffItem(int nItem, bool bState /*= true*/)
+{
+ // Setup Structures
+ LV_ITEM lv;
+
+ lv.mask = LVIF_IMAGE;
+ lv.iSubItem = 0;
+ lv.iItem = nItem;
+ lv.iImage = bState ? 2 : 3; // Image 2 is tick, 3 is cross
+
+ // Set right image for item
+ return m_ctlItems.SetItem(&lv) ? true : false;
+
+}
+
+LRESULT CItemDlg::OnSetFocusItems(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
+{
+ CancelItemSelection();
+ return 0;
+}
+
+
+void CItemDlg::CancelItemSelection()
+{
+ // Deselect All
+ for(int nCnt = 0; nCnt < m_ctlItems.GetItemCount(); nCnt ++)
+ // Set right state for item
+ ListView_SetItemState(m_ctlItems, nCnt, 0, (UINT)-1);
+
+ GotoDlgCtrl(GetDlgItem(IDCANCEL));
+}