Beispiel #1
0
void __fastcall TEditTiffForm::DeleteMenuItemClick(TObject *Sender) {
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
    if (!EditConfig("Удалить")) return;

    if (!DeleteTicStartEnd()) return;

    tb->SetPage(tic.Start - 1);
    SetupPageComboBox(tb->GetNPages(), tb->GetPage());
    Fog1->Invalidate();
}
Beispiel #2
0
void __fastcall TEditTiffForm::AppendMenuItemClick(TObject *Sender) {
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
    if (!EditConfig("Добавить")) return;

    if (!PrintFile()) return;

    int pos = tb->GetNPages();
    tb->InsPages(10000);

    tb->SetPage(pos);
    SetupPageComboBox(tb->GetNPages(), tb->GetPage());
    Fog1->Invalidate();
}
Beispiel #3
0
void __fastcall TEditTiffForm::ConfigSpeedButtonClick(TObject *Sender) {
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
    int FirstEnumPage = tic.FirstEnumPage;
    int FirstPageNum = tic.FirstPageNum;
    if (!EditConfig("Параметры")) return;
    if (tic.FirstEnumPage != 0 && tic.FirstPageNum != 0) {
        EnumTiffPages();
        if (tic.FirstEnumPage != FirstEnumPage || tic.FirstPageNum != FirstPageNum) {
            tb->changed = true;
        }
        Fog1->Invalidate();
    }
}
Beispiel #4
0
void __fastcall TEditTiffForm::ReplaceMenuItemClick(TObject *Sender) {
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
    if (!EditConfig("Заменить")) return;
    // Application->MessageBox("Якобы заменяет страницы", "Инфо", 0);

    if (!DeleteTicStartEnd()) return;

    if (!PrintFile()) return;

    int pos = tic.Start - 1;
    tb->InsPages(pos);

    tb->SetPage(pos);
    SetupPageComboBox(tb->GetNPages(), tb->GetPage());
    Fog1->Invalidate();

}
Beispiel #5
0
void __fastcall TEditTiffForm::RotateSpeedButtonClick(TObject *Sender) {
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
    if (!EditConfig("Перевернуть")) return;
    // Application->MessageBox("Якобы переворачивание страницы", "Инфо", 0);
    int p = tb->GetPage() + 1;
    int n;

    if (p >= tic.FirstEnumPage) {
        n = p - tic.FirstEnumPage + tic.FirstPageNum;
    } else {
        n = 0;
    }

    tb->FlipCurPage(n);
    EnumTiffPages();
    Fog1->Invalidate();
}
Beispiel #6
0
/*  This function is called by the Windows function DispatchMessage()  */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
  static UINT s_uTaskbarRestart;
  int i;

  switch (message) {
    case WM_CREATE:       

      /* Save Window Handle */
      o.hWnd = hwnd;

      s_uTaskbarRestart = RegisterWindowMessage(TEXT("TaskbarCreated"));

      WTSRegisterSessionNotification(hwnd, NOTIFY_FOR_THIS_SESSION);

      /* Load application icon */
      HICON hIcon = LoadLocalizedIcon(ID_ICO_APP);
      if (hIcon) {
        SendMessage(hwnd, WM_SETICON, (WPARAM) (ICON_SMALL), (LPARAM) (hIcon));
        SendMessage(hwnd, WM_SETICON, (WPARAM) (ICON_BIG), (LPARAM) (hIcon));
      }

      CreatePopupMenus();	/* Create popup menus */  
      ShowTrayIcon();
      if (o.allow_service[0]=='1' || o.service_only[0]=='1')
        CheckServiceStatus();	// Check if service is running or not
      if (!AutoStartConnections()) {
        SendMessage(hwnd, WM_CLOSE, 0, 0);
        break;
      }
      break;
    	
    case WM_NOTIFYICONTRAY:
      OnNotifyTray(lParam); 	// Manages message from tray
      break;

    case WM_COMMAND:
      if ( (LOWORD(wParam) >= IDM_CONNECTMENU) && (LOWORD(wParam) < IDM_CONNECTMENU + MAX_CONFIGS) ) {
        StartOpenVPN(&o.conn[LOWORD(wParam) - IDM_CONNECTMENU]);
      }
      if ( (LOWORD(wParam) >= IDM_DISCONNECTMENU) && (LOWORD(wParam) < IDM_DISCONNECTMENU + MAX_CONFIGS) ) {
        StopOpenVPN(&o.conn[LOWORD(wParam) - IDM_DISCONNECTMENU]);
      }
      if ( (LOWORD(wParam) >= IDM_STATUSMENU) && (LOWORD(wParam) < IDM_STATUSMENU + MAX_CONFIGS) ) {
        ShowWindow(o.conn[LOWORD(wParam) - IDM_STATUSMENU].hwndStatus, SW_SHOW);
      }
      if ( (LOWORD(wParam) >= IDM_VIEWLOGMENU) && (LOWORD(wParam) < IDM_VIEWLOGMENU + MAX_CONFIGS) ) {
        ViewLog(LOWORD(wParam) - IDM_VIEWLOGMENU);
      }
      if ( (LOWORD(wParam) >= IDM_EDITMENU) && (LOWORD(wParam) < IDM_EDITMENU + MAX_CONFIGS) ) {
        EditConfig(LOWORD(wParam) - IDM_EDITMENU);
      }
#ifndef DISABLE_CHANGE_PASSWORD
      if ( (LOWORD(wParam) >= IDM_PASSPHRASEMENU) && (LOWORD(wParam) < IDM_PASSPHRASEMENU + MAX_CONFIGS) ) {
        ShowChangePassphraseDialog(&o.conn[LOWORD(wParam) - IDM_PASSPHRASEMENU]);
      }
#endif
      if (LOWORD(wParam) == IDM_SETTINGS) {
        ShowSettingsDialog();
      }
      if (LOWORD(wParam) == IDM_CLOSE) {
        CloseApplication(hwnd);
      }
      if (LOWORD(wParam) == IDM_SERVICE_START) {
        MyStartService();
      }
      if (LOWORD(wParam) == IDM_SERVICE_STOP) {
        MyStopService();
      }     
      if (LOWORD(wParam) == IDM_SERVICE_RESTART) MyReStartService();
      break;
	    
    case WM_CLOSE:
      CloseApplication(hwnd);
      break;

    case WM_DESTROY:
      WTSUnRegisterSessionNotification(hwnd);
      StopAllOpenVPN();	
      OnDestroyTray();          /* Remove Tray Icon and destroy menus */
      PostQuitMessage (0);	/* Send a WM_QUIT to the message queue */
      break;

    case WM_QUERYENDSESSION:
      return(TRUE);

    case WM_ENDSESSION:
      StopAllOpenVPN();
      OnDestroyTray();
      break;

    case WM_WTSSESSION_CHANGE:
      switch (wParam) {
        case WTS_SESSION_LOCK:
          o.session_locked = TRUE;
          break;
        case WTS_SESSION_UNLOCK:
          o.session_locked = FALSE;
          if (CountConnState(suspended) != 0)
            ResumeConnections();
          break;
      }
      break;

    case WM_POWERBROADCAST:
      switch (wParam) {
        case PBT_APMSUSPEND:
          if (o.disconnect_on_suspend[0] == '1')
            {
              /* Suspend running connections */
              for (i=0; i<o.num_configs; i++)
                {
                  if (o.conn[i].state == connected)
                SuspendOpenVPN(i);
                }

              /* Wait for all connections to suspend */
              for (i=0; i<10; i++, Sleep(500))
                if (CountConnState(suspending) == 0) break;
            }
          return FALSE;

        case PBT_APMRESUMESUSPEND:
        case PBT_APMRESUMECRITICAL:
          if (CountConnState(suspended) != 0 && !o.session_locked)
            ResumeConnections();
          return FALSE;
      }

    default:			/* for messages that we don't deal with */
      if (message == s_uTaskbarRestart)
        {
          /* Explorer has restarted, re-register the tray icon. */
          ShowTrayIcon();
          CheckAndSetTrayIcon();
          break;
        }      
      return DefWindowProc (hwnd, message, wParam, lParam);
  }

  return 0;
}
Beispiel #7
0
/*  This function is called by the Windows function DispatchMessage()  */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	static UINT s_uTaskbarRestart;
	int i;

	switch (message) {
	case WM_CREATE:       

		/* Save Window Handle */
		o.hWnd = hwnd;

		s_uTaskbarRestart = RegisterWindowMessage(TEXT("TaskbarCreated"));

		CreatePopupMenus();	/* Create popup menus */  
		LoadAppIcon();		/* Load App Icon */
		ShowTrayIcon();
		if (o.allow_service[0]=='1' || o.service_only[0]=='1')
		CheckServiceStatus();	// Check if service is running or not
		if (!AutoStartConnections()) {
			SendMessage(hwnd, WM_CLOSE, 0, 0);
			break;
		}
		break;
		
	case WM_NOTIFYICONTRAY:
		OnNotifyTray(lParam); 	// Manages message from tray
		return TRUE;
		
	case WM_COMMAND:
		if ( (LOWORD(wParam) >= IDM_CONNECTMENU) && (LOWORD(wParam) < IDM_CONNECTMENU + MAX_CONFIGS) ) {
			StartOpenVPN(LOWORD(wParam) - IDM_CONNECTMENU);
		}
		if ( (LOWORD(wParam) >= IDM_DISCONNECTMENU) && (LOWORD(wParam) < IDM_DISCONNECTMENU + MAX_CONFIGS) ) {
			StopOpenVPN(LOWORD(wParam) - IDM_DISCONNECTMENU);
		}
		if ( (LOWORD(wParam) >= IDM_STATUSMENU) && (LOWORD(wParam) < IDM_STATUSMENU + MAX_CONFIGS) ) {
			ShowWindow(o.cnn[LOWORD(wParam) - IDM_STATUSMENU].hwndStatus, SW_SHOW);
		}
		if ( (LOWORD(wParam) >= IDM_VIEWLOGMENU) && (LOWORD(wParam) < IDM_VIEWLOGMENU + MAX_CONFIGS) ) {
			ViewLog(LOWORD(wParam) - IDM_VIEWLOGMENU);
		}
		if ( (LOWORD(wParam) >= IDM_EDITMENU) && (LOWORD(wParam) < IDM_EDITMENU + MAX_CONFIGS) ) {
			EditConfig(LOWORD(wParam) - IDM_EDITMENU);
		}
#ifndef DISABLE_CHANGE_PASSWORD
		if ( (LOWORD(wParam) >= IDM_PASSPHRASEMENU) && (LOWORD(wParam) < IDM_PASSPHRASEMENU + MAX_CONFIGS) ) {
			ShowChangePassphraseDialog(LOWORD(wParam) - IDM_PASSPHRASEMENU);
		}
#endif
		if (LOWORD(wParam) == IDM_PROXY) {
			ShowProxySettingsDialog();
		}
		if (LOWORD(wParam) == IDM_ABOUT) {
			DialogBox(o.hInstance, (LPCTSTR)IDD_ABOUTDIALOG, NULL, (DLGPROC)AboutDialogFunc);
		}
		if (LOWORD(wParam) == IDM_CLOSE) {
			CloseApplication(hwnd);
		}
		if (LOWORD(wParam) == IDM_SERVICE_START) {
			MyStartService();
		}
		if (LOWORD(wParam) == IDM_SERVICE_STOP) {
			MyStopService();
		}     
		if (LOWORD(wParam) == IDM_SERVICE_RESTART) MyReStartService();
		break;
		
	case WM_CLOSE:
		CloseApplication(hwnd);
		break;

	case WM_DESTROY:
		StopAllOpenVPN();	
		OnDestroyTray();          /* Remove Tray Icon and destroy menus */
		PostQuitMessage (0);	/* Send a WM_QUIT to the message queue */
		break;

	case WM_QUERYENDSESSION:
		return(TRUE);

	case WM_ENDSESSION:
		StopAllOpenVPN();
		OnDestroyTray();
		break;

	case WM_POWERBROADCAST:
		switch (wParam) {
		case PBT_APMSUSPEND:
			if (o.disconnect_on_suspend[0] == '1')
			{
				/* Suspend running connections */
				for (i=0; i<o.num_configs; i++)
				{
					if (o.cnn[i].connect_status == CONNECTED)
					SuspendOpenVPN(i);
				}

				/* Wait for all connections to suspend */
				for (i=0; i<10; i++, Sleep(500))
				if (CountConnectedState(SUSPENDING) == 0) break;
			}
			return FALSE;

		case PBT_APMRESUMESUSPEND:
		case PBT_APMRESUMECRITICAL:
			for (i=0; i<o.num_configs; i++)
			{
				/* Restart suspend connections */
				if (o.cnn[i].connect_status == SUSPENDED)
				StartOpenVPN(i);

				/* If some connection never reached SUSPENDED state */
				if (o.cnn[i].connect_status == SUSPENDING)
				StopOpenVPN(i);
			}
			return FALSE;
		}

	default:			/* for messages that we don't deal with */
		if (message == s_uTaskbarRestart)
		{
			/* Explorer has restarted, re-register the tray icon. */
			ShowTrayIcon();
			CheckAndSetTrayIcon();
			break;
		}      
		return DefWindowProc (hwnd, message, wParam, lParam);
	}

	return 0;
}
// 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;
}