Пример #1
0
BOOL CSmartFieldListBox::FinishEdit(BOOL fValidate /*=TRUE*/, BOOL fByReturn /*=FALSE*/)
{
	if (!EditDialog())
	{
		return INHERITED::FinishEdit(fValidate, fByReturn);
	}
	return FALSE;
}
Пример #2
0
//
// Handle control notifications
//
LRESULT ExemptionsDialog::OnNotifyControl(
		IN INT ControlId,
		IN HWND ControlWindow,
		IN UINT Code,
		IN PVOID Notify)
{
	LRESULT Result = 0;

	switch (ControlId)
	{
		//
		// Exemption list drop down
		//
		case EXEMPTIONS_DROPDOWN_SELECTION:
			switch (Code)
			{
				//
				// When the user changes selections
				//
				case CBN_SELCHANGE:
					{
						LRESULT Selection = SendMessage(
								GetControl(
									ControlId),
								CB_GETCURSEL,
								0,
								0);

						if (Selection == 0)
							DisplayApplicationExemptions();
						else if (Selection == 1)
							DisplayDirectoryExemptions();
						else
							DisplayImageFileExemptions();
					}
					break;
				default:
					break;
			}
			break;
		//
		// Add button
		//
		case EXEMPTIONS_BUTTON_ADD:
			switch (Code)
			{
				//
				// When the user wants to add a new exemption
				//
				case BN_CLICKED:
					{
						AddEditExemptionDialog AddDialog(
								GlobalScope,
								CurrentExemptionType,
								NULL);

						AddDialog.Create(
								GetWindow(),
								TRUE);

						SetForegroundWindow(
								GetWindow());

						DisplayExemptions(
								CurrentExemptionType);
					}
					break;
				default:
					break;
			}
			break;
		//
		// Edit button
		//
		case EXEMPTIONS_BUTTON_EDIT:
			switch (Code)
			{
				//
				// When the user wants to edit an exemption
				//
				case BN_CLICKED:
					{
						LPTSTR NtFilePath = GetCurrentSelectionNtFilePath();

						//
						// If we get back a valid path
						//
						if (NtFilePath)
						{
							AddEditExemptionDialog EditDialog(
									GlobalScope,
									CurrentExemptionType,
									NtFilePath);

							EditDialog.Create(
									GetWindow(),
									TRUE);

							SetForegroundWindow(
									GetWindow());
						}
						else
						{
							LPTSTR ErrorString = Locale::LoadStringDefault(
									IDS_NO_FILE_SELECTED,
									TEXT("You must select at least one file."));

							if (ErrorString)
							{
								MessageBox(
										GetWindow(),
										ErrorString,
										NULL,
										MB_ICONEXCLAMATION | MB_OK);

								Locale::FreeString(
										ErrorString);
							}
						}
					}
					break;
				default:
					break;
			}
			break;
		//
		// Remove button
		//
		case EXEMPTIONS_BUTTON_REMOVE:
			switch (Code)
			{
				case BN_CLICKED:
					{
						BOOLEAN Refresh = FALSE;
						LRESULT SelCount;
						LPDWORD SelIndexes;
						LONG    Index;
						HWND    ExemptionList;

						ExemptionList = GetControl(
									EXEMPTIONS_LIST_APPLIED);

						//
						// Get the number of selected items
						//
						if ((SelCount = SendMessage(
								ExemptionList,
								LB_GETSELCOUNT,
								0,
								0)) == LB_ERR)
							break;

						if (SelCount == 0)
						{
							LPTSTR ErrorString = Locale::LoadStringDefault(
									IDS_NO_FILE_SELECTED,
									TEXT("You must select at least one file."));

							if (ErrorString)
							{
								MessageBox(
										GetWindow(),
										ErrorString,
										NULL,
										MB_ICONEXCLAMATION | MB_OK);

								Locale::FreeString(
										ErrorString);
							}

							break;
						}

						//
						// Allocate storage for the selected indexes and query each
						// them
						//
						SelIndexes = (LPDWORD)malloc(sizeof(DWORD) * SelCount);

						if ((!SelIndexes) ||
						    (SendMessage(
								ExemptionList,
								LB_GETSELITEMS,
								(WPARAM)(LRESULT)SelCount,
								(WPARAM)(LPDWORD)SelIndexes) == LB_ERR))
						{
							if (SelIndexes)
								free(
										SelIndexes);
							break;
						}

						//
						// Enumerate the returned selected indexes, removing each one
						//
						for (Index = 0;
						     Index < SelCount;
						     Index++)
						{
							LPTSTR NtFilePath = (LPTSTR)SendMessage(
									ExemptionList,
									LB_GETITEMDATA,
									SelIndexes[Index],
									0);

							//
							// If the NT file path is valid...
							//
							if ((NtFilePath) &&
							    (NtFilePath != (LPTSTR)LB_ERR))
							{
								DWORD Result;

								//
								// Remove the path from the current exemption type
								//
								if ((Result = RemoveExemptionFromCurrentType(
										NtFilePath)) != ERROR_SUCCESS)
								{
									LPTSTR ErrorString;
									TCHAR  Error[256] = { 0 };

									ErrorString = Locale::LoadStringDefault(
											IDS_ERROR_COULD_NOT_REMOVE_EXEMPTION,
											TEXT("The exemption could not be removed (error %lu):\n\n%s"));

									if (ErrorString)
									{
										_sntprintf_s(
												Error,
												sizeof(Error) - sizeof(TCHAR),
												ErrorString,
												Result,
												NtFilePath);

										MessageBox(
												GetWindow(),
												Error,
												NULL,
												MB_ICONERROR | MB_OK);

										Locale::FreeString(
												ErrorString);
									}
								}
								else
									Refresh = TRUE;
							}
						}
								
						if (Refresh)
							DisplayExemptions(
									CurrentExemptionType);

						free(
								SelIndexes);
					}
					break;
				default:
					break;
			}
			break;
		//
		// Flush button
		//
		case EXEMPTIONS_BUTTON_FLUSH:
			switch (Code)
			{
				case BN_CLICKED:
					{
						DWORD Result;

						if ((Result = FlushExemptionsFromCurrentType()) != ERROR_SUCCESS)
						{
							LPTSTR ErrorString;
							TCHAR  Error[256] = { 0 };

							ErrorString = Locale::LoadStringDefault(
									IDS_ERROR_COULD_NOT_FLUSH_EXEMPTIONS,
									TEXT("The exemptions could not be flushed (error %lu)."));

							if (ErrorString)
							{
								_sntprintf_s(
										Error,
										sizeof(Error) - sizeof(TCHAR),
										ErrorString,
										Result);

								MessageBox(
										GetWindow(),
										Error,
										NULL,
										MB_ICONERROR | MB_OK);

								Locale::FreeString(
										ErrorString);
							}
						}
						else
							DisplayExemptions(
									CurrentExemptionType);
					}
					break;
				default:
					break;
			}
			break;
		default:
			break;
	}

	return Result;
}