Example #1
0
INT_PTR CDialogInstall::OnInitDialog(WPARAM wParam, LPARAM lParam)
{
	static const ControlTemplate::Control s_Controls[] =
	{
		CT_ICON(Id_HeaderIcon, 0,
			10, 10, 24, 24,
			WS_VISIBLE, 0),

		CT_LABEL(Id_HeaderTitleLabel, 2,
			40, 6, 250, 14,
			WS_VISIBLE | SS_ENDELLIPSIS | SS_NOPREFIX, 0),

		CT_LABEL(-1, 3,
			40, 20, 250, 9,
			WS_VISIBLE | SS_ENDELLIPSIS | SS_NOPREFIX, 0),

		CT_BUTTON(Id_InstallButton, 1,
			199, 191, 70, 14,
			WS_VISIBLE | WS_TABSTOP | BS_DEFPUSHBUTTON, 0),

		CT_BUTTON(Id_CancelButton, 13,
			274, 191, 70, 14,
			WS_VISIBLE | WS_TABSTOP | BS_DEFPUSHBUTTON, 0),

		CT_TAB(Id_Tab, 0,
			-2, 36, 400, 150,
			WS_VISIBLE | WS_TABSTOP | TCS_FIXEDWIDTH, 0)  // Last for correct tab order.
	};

	CreateControls(s_Controls, _countof(s_Controls), m_Font, GetString);
	
	m_TabContents.Create(m_Window);
	m_TabContents.Activate();

	SendMessage(m_Window, WM_SETICON, ICON_SMALL, (LPARAM)GetIcon(IDI_APPICON, false));

	HWND item = GetControl(Id_HeaderIcon);
	Static_SetIcon(item, GetIcon(IDI_APPICON, true));
	
	item = GetControl(Id_HeaderTitleLabel);
	SendMessage(item, WM_SETFONT, (WPARAM)m_FontBold, 0);

	item = GetControl(Id_InstallButton);
	SendMessage(m_Window, WM_NEXTDLGCTL, (WPARAM)item, TRUE);
	if (Platform::IsAtLeastWinVista() && !Util::IsProcessUserAdmin())
	{
		Button_SetElevationRequiredState(item, TRUE);
	}

	return TRUE;
}
Example #2
0
void CFilesHashDlg::SetCtrls(BOOL working)
{
	if(working)
	{
		DragAcceptFiles(FALSE);
		m_btnOpen.EnableWindow(FALSE);
		m_btnStop.EnableWindow(TRUE);
		m_btnClr.EnableWindow(FALSE);
		m_btnCopy.EnableWindow(FALSE);
		m_btnFind.EnableWindow(FALSE);
		m_btnContext.EnableWindow(FALSE);
		m_chkUppercase.EnableWindow(FALSE);
		GotoDlgCtrl(&m_btnStop);
	}
	else
	{
		m_btnOpen.EnableWindow(TRUE);
		m_btnStop.EnableWindow(FALSE);
		m_btnClr.EnableWindow(TRUE);
		m_btnCopy.EnableWindow(TRUE);
		m_btnFind.EnableWindow(TRUE);
		if(m_bLimited)
		{
			Button_SetElevationRequiredState(m_btnContext.GetSafeHwnd(), TRUE);
			//m_btnContext.SetWindowText(MAINDLG_CONTEXT_INIT);
			//m_btnContext.EnableWindow(FALSE);
		}
		else
		{
			Button_SetElevationRequiredState(m_btnContext.GetSafeHwnd(), FALSE);
			//m_btnContext.EnableWindow(TRUE);
		}
		m_btnContext.EnableWindow(TRUE);
		m_chkUppercase.EnableWindow(TRUE);
		GotoDlgCtrl(&m_btnOpen);
		DragAcceptFiles();
	}
}
BOOL
InstallPackageDialog::OnInitDialog ()
{
    BOOL ret = CDialog::OnInitDialog();
    try
    {
        string repository;
        RepositoryType repositoryType (RepositoryType::Unknown);
        if (pManager->TryGetDefaultPackageRepository(repositoryType, repository))
        {
            FormatControlText (IDC_EDIT_REPOSITORY_LOCATION,
                               "%s",
                               repository.c_str());
        }
        else
        {
            FormatControlText (IDC_EDIT_REPOSITORY_LOCATION,
                               "%s",
                               T_("<Random package repository>"));
        }
        if (IsWindowsVista() && SessionWrapper(true)->IsAdminMode())
        {
            HWND hwnd = ::GetDlgItem(m_hWnd, IDOK);
            if (hwnd == 0)
            {
                UNEXPECTED_CONDITION ("InstallPackageDialog::OnInitDialog");
            }
            Button_SetElevationRequiredState (hwnd, TRUE);
        }
    }
    catch (const MiKTeXException & e)
    {
        ErrorDialog::DoModal (this, e);
    }
    catch (const exception & e)
    {
        ErrorDialog::DoModal (this, e);
    }
    return (ret);
}
Example #4
0
BOOL OnInitDialog(HWND hWnd, HWND hwndFocus, LPARAM lParam)
{
    // 获取并显示即使在还没有为当前用户提升权限的前提下,拥有此进程的主访
    // 问令牌的用户是否是本地管理员组的成员。(IsUserInAdminGroup)。
    HWND hInAdminGroupLabel = GetDlgItem(hWnd, IDC_INADMINGROUP_STATIC);
    try
    {
        BOOL const fInAdminGroup = IsUserInAdminGroup();
        SetWindowText(hInAdminGroupLabel, fInAdminGroup ? L"是" : L"否");
    }
    catch (DWORD dwError)
    {
        SetWindowText(hInAdminGroupLabel, L"N/A");
        ReportError(L"IsUserInAdminGroup", dwError);
    }

     // 获取并显示是否此进程以管理员身份运行。(IsRunAsAdmin)。
    HWND hIsRunAsAdminLabel = GetDlgItem(hWnd, IDC_ISRUNASADMIN_STATIC);
    try
    {
        BOOL const fIsRunAsAdmin = IsRunAsAdmin();
        SetWindowText(hIsRunAsAdminLabel, fIsRunAsAdmin ? L"是" : L"否");
    }
    catch (DWORD dwError)
    {
        SetWindowText(hIsRunAsAdminLabel, L"N/A");
        ReportError(L"IsRunAsAdmin", dwError);
    }
    

     // 获取并显示进程权限提升信息(IsProcessElevated)和完整性级别(GetProcessIntegrityLevel)
    // 注意:这些信息在Windows Vista之前的Windows中不存在。

    HWND hIsElevatedLabel = GetDlgItem(hWnd, IDC_ISELEVATED_STATIC);
    HWND hILLabel = GetDlgItem(hWnd, IDC_IL_STATIC);

    OSVERSIONINFO osver = { sizeof(osver) };
    if (GetVersionEx(&osver) && osver.dwMajorVersion >= 6)
    {
        // 运行于Windows Vista或后续版本(主版本号 >= 6)。
        try
        {
            // 获取并显示进程权限提升信息
            BOOL const fIsElevated = IsProcessElevated();
            SetWindowText(hIsElevatedLabel, fIsElevated ? L"是" : L"否");

            // 如果进程尚未被提升,更新“自我提升权限”按钮以在UI中显示UAC盾形
            // 图标。宏Button_SetElevationRequiredState(在Commctrl.h中定义)用
            // 于显示或隐藏按钮上的盾形图标。你也可以通过调用SHGetStockIconInfo
            // (参量SIID_SHIELD)来获取此图标。
            HWND hElevateBtn = GetDlgItem(hWnd, IDC_ELEVATE_BN);
            Button_SetElevationRequiredState(hElevateBtn, !fIsElevated);
        }
        catch (DWORD dwError)
        {
            SetWindowText(hIsElevatedLabel, L"N/A");
            ReportError(L"IsProcessElevated", dwError);
        }

        try
        {
            // 获取并显示进程的完整性级别
            DWORD const dwIntegrityLevel = GetProcessIntegrityLevel();
            switch (dwIntegrityLevel)
            {
            case SECURITY_MANDATORY_UNTRUSTED_RID: SetWindowText(hILLabel, L"不信任"); break;
            case SECURITY_MANDATORY_LOW_RID: SetWindowText(hILLabel, L"低"); break;
            case SECURITY_MANDATORY_MEDIUM_RID: SetWindowText(hILLabel, L"中"); break;
            case SECURITY_MANDATORY_HIGH_RID: SetWindowText(hILLabel, L"高"); break;
            case SECURITY_MANDATORY_SYSTEM_RID: SetWindowText(hILLabel, L"系统"); break;
            default: SetWindowText(hILLabel, L"未知"); break;
            }
        }
        catch (DWORD dwError)
        {
            SetWindowText(hILLabel, L"N/A");
            ReportError(L"GetProcessIntegrityLevel", dwError);
        }
    }
    else
    {
        SetWindowText(hIsElevatedLabel, L"N/A");
        SetWindowText(hILLabel, L"N/A");
    }

    return TRUE;
}
BOOL Dlg_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam) 
{   
   chSETDLGICONS(hwnd, IDI_PROCESSINFO);

   /* Is set to TRUE if the Administrator privileges 
    * are available; either because running elevated
    * or simply because UAC has been disabled.
	*/
   BOOL bCanReadSystemProcesses = FALSE;

   /* Show if we are running with filtered token or not */
   if (GetProcessElevation(&s_elevationType, &s_bIsAdmin)) 
   {
      /* prefix title with elevation */
      TCHAR szTitle[64];

      switch(s_elevationType) 
	  {
         /* Default user or UAC is disabled */
         case TokenElevationTypeDefault:  
            if (IsUserAnAdmin()) 
			{
               _tcscpy_s(
				   szTitle, 
				   _countof(szTitle), 
                   TEXT("Default Administrator: ")); 
               bCanReadSystemProcesses = true;
            } 
			else 
			{
               _tcscpy_s(
				   szTitle, 
				   _countof(szTitle), 
                   TEXT("Default: ")); 
            }
         break;
         /* Process has been successfully elevated */
         case TokenElevationTypeFull:
            if (IsUserAnAdmin()) 
			{
               _tcscpy_s(
				   szTitle, 
				   _countof(szTitle), 
                   TEXT("Elevated Administrator: ")); 
               bCanReadSystemProcesses = true;
            } 
			else 
			{
               _tcscpy_s(
				   szTitle, 
				   _countof(szTitle), 
                   TEXT("Elevated: ")); 
            }
         break;
         /* Process is running with limited privileges */
         case TokenElevationTypeLimited:
            if (s_bIsAdmin) 
			{
               _tcscpy_s(
				   szTitle, 
				   _countof(szTitle), 
                   TEXT("Filtered Administrator: ")); 
            } 
			else 
			{
               _tcscpy_s(
				   szTitle, 
				   _countof(szTitle), 
                   TEXT("Filtered: ")); 
            }
         break;
      }

      /* Update the dialog title based on the elevation level */
      GetWindowText(
		  hwnd, 
		  _tcschr(szTitle, TEXT('\0')), 
         _countof(szTitle) - _tcslen(szTitle));
      SetWindowText(hwnd, szTitle);

      /* Add the "shield" icon if needed to allow the user
       * to restart the application with elevated privileges
	   */
      if (!bCanReadSystemProcesses) 
	  {
         Button_SetElevationRequiredState(
            GetDlgItem(hwnd, IDC_BTN_SYSTEM_PROCESSES), 
               !bCanReadSystemProcesses);
      } 
	  else 
	  {
         /* No need to show the button... */
         ShowWindow(GetDlgItem(hwnd, IDC_BTN_SYSTEM_PROCESSES), SW_HIDE);
         
         /* ... and the combo-box can take the whole width of the dialog box */
         MoveWindow(GetDlgItem(hwnd, IDC_BTN_SYSTEM_PROCESSES), 
            0, 0, 0, 0, FALSE);
      }
   }
   
   /* Hide the module-helper listbox. */
   ShowWindow(GetDlgItem(hwnd, IDC_MODULEHELP), SW_HIDE);

   /* Have the results window use a fixed-pitch font */
   SetWindowFont(
	   GetDlgItem(hwnd, IDC_RESULTS), 
       GetStockFont(ANSI_FIXED_FONT), 
	   FALSE);

   /* By default, show the running processes */
   Dlg_PopulateProcessList(hwnd);

   return(TRUE);
}
Example #6
0
static INT_PTR CALLBACK DlgUpdate(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	HWND hwndList = GetDlgItem(hDlg, IDC_LIST_UPDATES);

	switch (message) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hDlg);
		SendMessage(hwndList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES);
		SendMessage(hDlg, WM_SETICON, ICON_SMALL, (LPARAM)Skin_GetIcon("check_update"));
		SendMessage(hDlg, WM_SETICON, ICON_BIG, (LPARAM)Skin_GetIcon("check_update", 1));
		{
			OSVERSIONINFO osver = { sizeof(osver) };
			if (GetVersionEx(&osver) && osver.dwMajorVersion >= 6)
			{
				wchar_t szPath[MAX_PATH];
				GetModuleFileName(NULL, szPath, SIZEOF(szPath));
				TCHAR *ext = _tcsrchr(szPath, '.');
				if (ext != NULL)
					*ext = '\0';
				_tcscat(szPath, _T(".test"));
				HANDLE hFile = CreateFile(szPath, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
				if (hFile == INVALID_HANDLE_VALUE)
					// Running Windows Vista or later (major version >= 6).
					Button_SetElevationRequiredState(GetDlgItem(hDlg, IDOK), !IsProcessElevated());
				else
				{
					CloseHandle(hFile);
					DeleteFile(szPath);
				}
			}
			LVCOLUMN lvc = {0};
			// Initialize the LVCOLUMN structure.
			// The mask specifies that the format, width, text, and
			// subitem members of the structure are valid.
			lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT;
			lvc.fmt = LVCFMT_LEFT;

			lvc.iSubItem = 0;
			lvc.pszText = TranslateT("Component Name");
			lvc.cx = 220; // width of column in pixels
			ListView_InsertColumn(hwndList, 0, &lvc);

			lvc.iSubItem = 1;
			lvc.pszText = TranslateT("State");
			lvc.cx = 120 - GetSystemMetrics(SM_CXVSCROLL); // width of column in pixels
			ListView_InsertColumn(hwndList, 1, &lvc);

			//enumerate plugins, fill in list
			ListView_DeleteAllItems(hwndList);
			///
			LVGROUP lvg;
			lvg.cbSize = sizeof(LVGROUP);
			lvg.mask = LVGF_HEADER | LVGF_GROUPID;

			lvg.pszHeader = TranslateT("Plugins");
			lvg.iGroupId = 1;
			ListView_InsertGroup(hwndList, 0, &lvg);
			
			lvg.pszHeader = TranslateT("Miranda NG Core");
			lvg.iGroupId = 2;
			ListView_InsertGroup(hwndList, 0, &lvg);

			lvg.pszHeader = TranslateT("Languages");
			lvg.iGroupId = 3;
			ListView_InsertGroup(hwndList, 0, &lvg);

			lvg.pszHeader = TranslateT("Icons");
			lvg.iGroupId = 4;
			ListView_InsertGroup(hwndList, 0, &lvg);
			
			ListView_EnableGroupView(hwndList, TRUE);

			bool enableOk = false;
			OBJLIST<FILEINFO> &todo = *(OBJLIST<FILEINFO> *)lParam;
			for (int i = 0; i < todo.getCount(); ++i) {
				LVITEM lvI = {0};
				lvI.mask = LVIF_TEXT | LVIF_PARAM | LVIF_GROUPID | LVIF_NORECOMPUTE;
				lvI.iGroupId = (_tcsstr(todo[i].tszOldName, _T("Plugins")) != NULL) ? 1 : 
					((_tcsstr(todo[i].tszOldName, _T("Languages")) != NULL) ? 3 : 
						((_tcsstr(todo[i].tszOldName, _T("Icons")) != NULL) ? 4 : 2));
				lvI.iSubItem = 0;
				lvI.lParam = (LPARAM)&todo[i];
				lvI.pszText = todo[i].tszOldName;
				lvI.iItem = i;
				ListView_InsertItem(hwndList, &lvI);

				ListView_SetCheckState(hwndList, lvI.iItem, todo[i].bEnabled);
				if (todo[i].bEnabled)
					enableOk = true;

				SetStringText(hwndList,i,todo[i].bDeleteOnly ? TranslateT("Deprecated!") : TranslateT("Update found!"));
			}
			if(enableOk)
				EnableWindow(GetDlgItem(hDlg, IDOK), TRUE);
		}

		bShowDetails = false;
		ResizeVert(hDlg, 60);

		// do this after filling list - enables 'ITEMCHANGED' below
		SetWindowLongPtr(hDlg, GWLP_USERDATA, lParam);
		Utils_RestoreWindowPositionNoSize(hDlg, 0, MODNAME, "ConfirmWindow");
		return TRUE;

	case WM_NOTIFY:
		if (((LPNMHDR) lParam)->hwndFrom == hwndList) {
			switch (((LPNMHDR) lParam)->code) {
			case LVN_ITEMCHANGED:
				if (GetWindowLongPtr(hDlg, GWLP_USERDATA)) {
					NMLISTVIEW *nmlv = (NMLISTVIEW *)lParam;
					if ((nmlv->uNewState ^ nmlv->uOldState) & LVIS_STATEIMAGEMASK) {
						LVITEM lvI = {0};
						lvI.iItem = nmlv->iItem;
						lvI.iSubItem = 0;
						lvI.mask = LVIF_PARAM;
						ListView_GetItem(hwndList, &lvI);

						FILEINFO *p = (FILEINFO*)lvI.lParam;
						db_set_b(NULL, DB_MODULE_FILES, StrToLower(_T2A(p->tszOldName)), p->bEnabled = ListView_GetCheckState(hwndList, nmlv->iItem));

						// Toggle the Download button
						bool enableOk = false;
						OBJLIST<FILEINFO> &todo = *(OBJLIST<FILEINFO> *)GetWindowLongPtr(hDlg, GWLP_USERDATA);
						for (int i=0; i < todo.getCount(); ++i) {
							if (todo[i].bEnabled) {
								enableOk = true;
								break;
							}
						}
						EnableWindow(GetDlgItem(hDlg, IDOK), enableOk ? TRUE : FALSE);
					}
				}
				break;
			}
		}
		break;

	case WM_COMMAND:
		if (HIWORD( wParam ) == BN_CLICKED) {
			switch(LOWORD(wParam)) {
			case IDOK:
				EnableWindow( GetDlgItem(hDlg, IDOK), FALSE);
				EnableWindow( GetDlgItem(hDlg, IDC_SELALL), FALSE);
				EnableWindow( GetDlgItem(hDlg, IDC_SELNONE), FALSE);

				mir_forkthread(ApplyUpdates, hDlg);
				return TRUE;

			case IDC_DETAILS:
				bShowDetails = !bShowDetails;
				ResizeVert(hDlg, bShowDetails ? 242 : 60);
				SetDlgItemText(hDlg, IDC_DETAILS, (bShowDetails ? TranslateT("<< Details") : TranslateT("Details >>")));
				break;

			case IDC_SELALL:
				SelectAll(hDlg, true);
				break;

			case IDC_SELNONE:
				SelectAll(hDlg, false);
				break;

			case IDCANCEL:
				DestroyWindow(hDlg);
				return TRUE;
			}
		}
		break;

	case UM_ERROR:
		MessageBox(hDlg, TranslateT("Update failed! One of the components wasn't downloaded correctly. Try it again later."), TranslateT("Plugin Updater"), MB_OK | MB_ICONERROR);
		DestroyWindow(hDlg);
		break;

	case WM_CLOSE:
		DestroyWindow(hDlg);
		break;

	case WM_DESTROY:
		Skin_ReleaseIcon((HICON)SendMessage(hDlg, WM_SETICON, ICON_SMALL, 0));
		Utils_SaveWindowPosition(hDlg, NULL, MODNAME, "ConfirmWindow");
		hwndDialog = NULL;
		delete (OBJLIST<FILEINFO> *)GetWindowLongPtr(hDlg, GWLP_USERDATA);
		SetWindowLongPtr(hDlg, GWLP_USERDATA, 0);
#if MIRANDA_VER >= 0x0A00
		db_set_dw(NULL, MODNAME, DB_SETTING_LAST_UPDATE, time(NULL));
#endif
		mir_forkthread(InitTimer, 0);
		break;
	}

	return FALSE;
}
Example #7
0
INT_PTR CALLBACK DlgList(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	HWND hwndList = GetDlgItem(hDlg, IDC_LIST_UPDATES);

	switch (message) {
	case WM_INITDIALOG:
		hwndDialog = hDlg;
		TranslateDialogDefault( hDlg );
		oldWndProc = (WNDPROC)SetWindowLongPtr(hwndList, GWLP_WNDPROC, (LONG_PTR)PluginListWndProc);

		SendMessage(hDlg, WM_SETICON, ICON_BIG, (LPARAM)Skin_GetIcon("plg_list", 1));
		SendMessage(hDlg, WM_SETICON, ICON_SMALL, (LPARAM)Skin_GetIcon("plg_list"));
		{
			HIMAGELIST hIml = ImageList_Create(16, 16, ILC_MASK | ILC_COLOR32, 4, 0);
			ImageList_AddIconFromIconLib(hIml, "info");
			ListView_SetImageList(hwndList, hIml, LVSIL_SMALL);

			OSVERSIONINFO osver = { sizeof(osver) };
			if (GetVersionEx(&osver) && osver.dwMajorVersion >= 6) {
				wchar_t szPath[MAX_PATH];
				GetModuleFileName(NULL, szPath, SIZEOF(szPath));
				TCHAR *ext = _tcsrchr(szPath, '.');
				if (ext != NULL)
					*ext = '\0';
				_tcscat(szPath, _T(".test"));
				HANDLE hFile = CreateFile(szPath, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
				if (hFile == INVALID_HANDLE_VALUE)
					// Running Windows Vista or later (major version >= 6).
					Button_SetElevationRequiredState(GetDlgItem(hDlg, IDOK), !IsProcessElevated());
				else {
					CloseHandle(hFile);
					DeleteFile(szPath);
				}
			}
			RECT r;
			GetClientRect(hwndList, &r);

			///
			LVCOLUMN lvc = {0};
			lvc.mask = LVCF_WIDTH | LVCF_TEXT;
			//lvc.fmt = LVCFMT_LEFT;

			lvc.pszText = TranslateT("Component Name");
			lvc.cx = 220; // width of column in pixels
			ListView_InsertColumn(hwndList, 0, &lvc);

			lvc.pszText = L"";
			lvc.cx = 32 - GetSystemMetrics(SM_CXVSCROLL); // width of column in pixels
			ListView_InsertColumn(hwndList, 1, &lvc);

			lvc.pszText = TranslateT("State");
			lvc.cx = 100 - GetSystemMetrics(SM_CXVSCROLL); // width of column in pixels
			ListView_InsertColumn(hwndList, 2, &lvc);

			///
			LVGROUP lvg;
			lvg.cbSize = sizeof(LVGROUP);
			lvg.mask = LVGF_HEADER | LVGF_GROUPID;

			lvg.pszHeader = TranslateT("Plugins");
			lvg.iGroupId = 1;
			ListView_InsertGroup(hwndList, 0, &lvg);

			lvg.pszHeader = TranslateT("Icons");
			lvg.iGroupId = 2;
			ListView_InsertGroup(hwndList, 0, &lvg);

			lvg.pszHeader = TranslateT("Other");
			lvg.iGroupId = 3;
			ListView_InsertGroup(hwndList, 0, &lvg);

			ListView_EnableGroupView(hwndList, TRUE);

			///
			SendMessage(hwndList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES | LVS_EX_CHECKBOXES | LVS_EX_LABELTIP);
			ListView_DeleteAllItems(hwndList);

			///
			OBJLIST<FILEINFO> &todo = *(OBJLIST<FILEINFO> *)lParam;
			for (int i = 0; i < todo.getCount(); ++i) {
				int groupId = 3;
				LVITEM lvi = {0};
				lvi.mask = LVIF_PARAM | LVIF_GROUPID | LVIF_TEXT | LVIF_IMAGE;
				
				if (_tcschr(todo[i].tszOldName, L'\\') != NULL)
					groupId = _tcsstr(todo[i].tszOldName, L"Plugins") != NULL ? 1 : 2;

				lvi.iItem = i;
				lvi.lParam = (LPARAM)&todo[i];
				lvi.iGroupId = groupId;
				lvi.iImage = -1;
				lvi.pszText = todo[i].tszOldName;
				int iRow = ListView_InsertItem(hwndList, &lvi);

				if (iRow != -1) {
					lvi.iItem = iRow;
					if (groupId == 1) {
						lvi.mask = LVIF_IMAGE;
						lvi.iSubItem = 1;
						lvi.iImage = 0;
						ListView_SetItem(hwndList, &lvi);
					}
				}
				todo[i].bEnabled = false;
			}
			HWND hwOk = GetDlgItem(hDlg, IDOK);
			EnableWindow(hwOk, false);
		}

		// do this after filling list - enables 'ITEMCHANGED' below
		SetWindowLongPtr(hDlg, GWLP_USERDATA, lParam);
		Utils_RestoreWindowPosition(hDlg, 0, MODNAME, "ListWindow");
		return TRUE;

	case WM_NOTIFY:
		if (((LPNMHDR) lParam)->hwndFrom == hwndList) {
			switch (((LPNMHDR) lParam)->code) {
			case LVN_ITEMCHANGED:
				if (GetWindowLongPtr(hDlg, GWLP_USERDATA)) {
					NMLISTVIEW *nmlv = (NMLISTVIEW *)lParam;

					LVITEM lvI = {0};
					lvI.iItem = nmlv->iItem;
					lvI.iSubItem = 0;
					lvI.mask = LVIF_PARAM;
					ListView_GetItem(hwndList, &lvI);

					OBJLIST<FILEINFO> &todo = *(OBJLIST<FILEINFO> *)GetWindowLongPtr(hDlg, GWLP_USERDATA);
					if ((nmlv->uNewState ^ nmlv->uOldState) & LVIS_STATEIMAGEMASK) {
						todo[lvI.iItem].bEnabled = ListView_GetCheckState(hwndList, nmlv->iItem);

						bool enableOk = false;
						for (int i=0; i < todo.getCount(); ++i) {
							if (todo[i].bEnabled) {
								enableOk = true;
								break;
							}
						}
						HWND hwOk = GetDlgItem(hDlg, IDOK);
						EnableWindow(hwOk, enableOk ? TRUE : FALSE);
					}
				}
				break;
			}
		}
		break;

	case WM_COMMAND:
		if (HIWORD( wParam ) == BN_CLICKED) {
			switch(LOWORD(wParam)) {
			case IDOK:
				EnableWindow( GetDlgItem(hDlg, IDOK), FALSE);
				EnableWindow( GetDlgItem(hDlg, IDC_SELNONE), FALSE);

				mir_forkthread(ApplyDownloads, hDlg);
				return TRUE;

			case IDC_SELNONE:
				SelectAll(hDlg, false);
				break;

			case IDCANCEL:
				DestroyWindow(hDlg);
				return TRUE;
			}
		}
		break;

	case WM_SIZE: // make the dlg resizeable
		if (!IsIconic(hDlg)) {
			UTILRESIZEDIALOG urd = { sizeof(urd) };
			urd.hInstance = hInst;
			urd.hwndDlg = hDlg;
			urd.lpTemplate = MAKEINTRESOURCEA(IDD_LIST);
			urd.pfnResizer = ListDlg_Resize;
			CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM)&urd);
		}
		break;

	case WM_GETMINMAXINFO: 
		{
			LPMINMAXINFO mmi = (LPMINMAXINFO)lParam;

			// The minimum width in points
			mmi->ptMinTrackSize.x = 370;
			// The minimum height in points
			mmi->ptMinTrackSize.y = 300;
		}
		break;

	case WM_DESTROY:
		Utils_SaveWindowPosition(hDlg, NULL, MODNAME, "ListWindow");
		Skin_ReleaseIcon((HICON)SendMessage(hDlg, WM_SETICON, ICON_BIG, 0));
		Skin_ReleaseIcon((HICON)SendMessage(hDlg, WM_SETICON, ICON_SMALL, 0));
		hwndDialog = NULL;
		delete (OBJLIST<FILEINFO> *)GetWindowLongPtr(hDlg, GWLP_USERDATA);
		SetWindowLongPtr(hDlg, GWLP_USERDATA, 0);
		break;
	}

	return FALSE;
}
//
//  FUNCTION: SetButtonShield(HWND)
//
//  PURPOSE: Places the Shield Icon on the button referenced by hwnd.
//
//  COMMENTS:
//		hwndButton - handle to the button that should recieve the shield icon.
//		This call is in it's own function here for clarity.
//		An application must be manifested to use comctl32.dll version 6 to gain this functionality:
//			In VS, add to ProjectProperties->Linker->Manifest File->Additional Manifest Dependencies:
//			"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'"
//
LRESULT ElevationManager::SetButtonShield(HWND hwndButton){

	return Button_SetElevationRequiredState(hwndButton, TRUE);

}
// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	UNREFERENCED_PARAMETER(lParam);
	switch (message)
	{
	case WM_INITDIALOG:
		{
			HWND hwndOwner = GetDesktopWindow(); 
			RECT rc, rcDlg, rcOwner; 

			GetWindowRect(hwndOwner, &rcOwner); 
			GetWindowRect(hDlg, &rcDlg); 
			CopyRect(&rc, &rcOwner); 

			SetWindowTextA(GetDlgItem(hDlg,IDC_INSTRUCTIONS),"DropboxFilter is a program that hooks into dropbox and adds filter capabilities.\n\nThere is two ways to install it.\n\n1. AppInit Dll's\n\tThis method is a bit intrusive, anal virus scanners might detect this as a threat. But, it will not disappear when Dropbox is automatically updated.\n\n2. Piggyback start up launching.\n\tThis method will replace the dropbox system start with its own. When dropbox is automatically updated it might remove this and thereby disabling DropboxFilter without you noticing.\n\nAppInit method is recommended.");
			if(!IsElevated()) {
				Button_SetElevationRequiredState(GetDlgItem(hDlg,IDC_INSTALL_APPINIT),TRUE);
				Button_SetElevationRequiredState(GetDlgItem(hDlg,IDC_INSTALL_PIGGYBACK),TRUE);
				Button_SetElevationRequiredState(GetDlgItem(hDlg,IDC_UNINSTALL),TRUE);
			}
			// Offset the owner and dialog box rectangles so that right and bottom 
			// values represent the width and height, and then offset the owner again 
			// to discard space taken up by the dialog box. 

			OffsetRect(&rcDlg, -rcDlg.left, -rcDlg.top); 
			OffsetRect(&rc, -rc.left, -rc.top); 
			OffsetRect(&rc, -rcDlg.right, -rcDlg.bottom); 

			// The new position is the sum of half the remaining space and the owner's 
			// original position. 

			SetWindowPos(hDlg, 
				HWND_TOP, 
				rcOwner.left + (rc.right / 2), 
				rcOwner.top + (rc.bottom / 2), 
				0, 0,          // Ignores size arguments. 
				SWP_NOSIZE);
			if(lParam) {
				if(IsElevated()) {
					PostMessage(hDlg,WM_COMMAND,lParam,0);
				} else {
					MessageBox(NULL,"Could not elevate process rights. Your user needs to have admin rights to install this program","Cant elevate",MB_OK);
				}
			}
		}
		return (INT_PTR)TRUE;

	case WM_COMMAND:
		switch(LOWORD(wParam)) {
		case ID_CLOSE:
		case IDCANCEL:
			EndDialog(hDlg, LOWORD(wParam));
			return (INT_PTR)TRUE;
		case IDC_INSTALL_APPINIT:
			Elevate(hDlg,IDC_INSTALL_APPINIT);
			if(!Install()) {
				return TRUE;
			}
			if(!InstallAppInit()) {
				return TRUE;
			}
			MessageBoxA(NULL,"Install done.\n\nStart dropbox manualy from the start menu.","Installed",MB_OK);
			return TRUE;
		case IDC_INSTALL_PIGGYBACK:
			Elevate(hDlg,IDC_INSTALL_PIGGYBACK);
			if(!Install()) {
				return TRUE;
			}
			if(!InstallPiggyback()) {
				return TRUE;
			}
			MessageBoxA(NULL,"Install done.\n\nStart dropbox manualy from the startup folder on the start menu.","Installed",MB_OK);
			return TRUE;
		case IDC_UNINSTALL:
			Elevate(hDlg,IDC_INSTALL_PIGGYBACK);
			UnInstall();
			UnInstallPiggyback();
			UnInstallAppInit();
			MessageBoxA(NULL,"UnInstall done.\n\nStart dropbox manualy from the start menu.","UnInstalled",MB_OK);
			return TRUE;
		case IDC_EDIT_CONFIG:
			EditConfig();
			return TRUE;
		}
		break;
	}
	return (INT_PTR)FALSE;
}