Пример #1
0
static inline void __AddToPath(const TCHAR *path) {
  HKEY env_hkey;
  LONG reg_open_return = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("System\\CurrentControlSet\\Control\\Session Manager\\Environment"), 0, KEY_ALL_ACCESS, &env_hkey);
  if (reg_open_return == ERROR_SUCCESS) {
    DWORD path_original_length;
    RegQueryValueEx(env_hkey, _T("Path"), NULL, NULL, NULL, &path_original_length);
    TCHAR *path_original = (TCHAR *)malloc(path_original_length + sizeof(TCHAR));
    LONG c = RegQueryValueEx(env_hkey, _T("Path"), NULL, NULL, (LPBYTE)path_original, &path_original_length);
    path_original_length /= sizeof(TCHAR);
    TCHAR *path_pos;
    if (path_pos = FindPathInsidePath(path, path_original, NULL)) {
      _ftprintf(stderr, _T("Path already added"));
    } else {
      _ftprintf(stderr, _T("%s\n with length %ld"), path_original, path_original_length);
      TCHAR *path_new = (TCHAR *)malloc((path_original_length + _tcslen(path) + 1) * sizeof(TCHAR));
      _tcsnccpy(path_new, path_original, path_original_length);
      _tcscpy(path_new + path_original_length - 1, _T(";"));
      _tcscpy(path_new + path_original_length, path);
      RegSetValueEx(env_hkey, _T("Path"), 0, REG_EXPAND_SZ, (LPBYTE)path_new, (path_original_length + _tcslen(path) + 1) * sizeof(TCHAR));
    }
    RegCloseKey(env_hkey);
    SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)"Environment", SMTO_ABORTIFHUNG, 3000, NULL);
    SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)L"Environment", SMTO_ABORTIFHUNG, 3000, NULL);
  } else {
    _ftprintf(stderr, _T("Key opened error."));
  }
}
Пример #2
0
void CSocketManager::AppendMessage(LPCTSTR strText )
{
	if (NULL == m_pMsgCtrl)
		return;
/*
	if (::IsWindow( m_pMsgCtrl->GetSafeHwnd() ))
	{
		int nLen = m_pMsgCtrl->GetWindowTextLength();
		m_pMsgCtrl->SetSel(nLen, nLen);
		m_pMsgCtrl->ReplaceSel( strText );
	}
*/
	HWND hWnd = m_pMsgCtrl->GetSafeHwnd();
	DWORD dwResult = 0;
	if (SendMessageTimeout(hWnd, WM_GETTEXTLENGTH, 0, 0, SMTO_NORMAL, 1000L, &dwResult) != 0)
	{
		int nLen = (int) dwResult;
		if (SendMessageTimeout(hWnd, EM_SETSEL, nLen, nLen, SMTO_NORMAL, 1000L, &dwResult) != 0)
		{
			if (SendMessageTimeout(hWnd, EM_REPLACESEL, FALSE, (LPARAM)strText, SMTO_NORMAL, 1000L, &dwResult) != 0)
			{
			}
		}

	}
}
Пример #3
0
HICON GetWindowIcon(HWND windowHandle)
{
	DWORD_PTR hIco = 0;
	int HICON1 = -14;
	int HICONSM = -34;

	SendMessageTimeout(windowHandle, 0x007f, 2, 0, 2, 200, (PDWORD_PTR)hIco);

	if (hIco == 0)
	{
		SendMessageTimeout(windowHandle, 0x007f, 0, 0, 2, 200, (PDWORD_PTR)hIco);
	}

	if (hIco == 0)
	{
		hIco = GetClassLongPtr(windowHandle, HICONSM);
	}

	if (hIco == 0)
	{
		hIco = GetClassLongPtr(windowHandle, HICON1);
	}

	return (HICON)hIco;
	//DWORD_PTR dwReturn = GetClassLongPtr(windowHandle, (-14));
	//return (HICON)dwReturn;
}
Пример #4
0
HICON get_window_icon_big(HWND hwnd, bool allow_from_class)
{
	HICON hIcon = 0;

	SendMessageTimeout(hwnd, WM_GETICON, ICON_BIG, 0, SMTO_ABORTIFHUNG, 1000, (LPDWORD)&hIcon);

	if (!hIcon)
		SendMessageTimeout(hwnd, WM_GETICON, ICON_SMALL2, 0, SMTO_ABORTIFHUNG, 1000, (LPDWORD)&hIcon);

	if (!hIcon)
		SendMessageTimeout(hwnd, WM_GETICON, ICON_SMALL, 0, SMTO_ABORTIFHUNG, 1000, (LPDWORD)&hIcon);

	if (allow_from_class) {
		if (!hIcon)
			hIcon = (HICON)GetClassLong(hwnd, GCL_HICON);

		if (!hIcon)
			hIcon = (HICON)GetClassLong(hwnd, GCL_HICONSM);
	}

	if (!hIcon)
		SendMessageTimeout(hwnd, WM_QUERYDRAGICON, 0, 0, 0, 1000, (LPDWORD)&hIcon);

	return hIcon;
}
Пример #5
0
BOOL apiPauseConsoleOutput(HWND hConWnd, bool bPause)
{
	BOOL bOk = FALSE, bCi = FALSE;
	DWORD_PTR dwRc = 0;
	DWORD nTimeout = 15000;

	if (bPause)
	{
		CONSOLE_CURSOR_INFO ci = {};
		bCi = GetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &ci);

		bOk = (SendMessageTimeout(hConWnd, WM_SYSCOMMAND, 65522, 0, SMTO_NORMAL, nTimeout, &dwRc) != 0);

		// In Win2k we can't be sure about active selection,
		// so we check for cursor height equal to 100%
		gbPauseConsoleWasRequested = (bCi && ci.dwSize < 100);
	}
	else
	{
		bOk = (SendMessageTimeout(hConWnd, WM_KEYDOWN, VK_ESCAPE, 0, SMTO_NORMAL, nTimeout, &dwRc) != 0);
		gbPauseConsoleWasRequested = false;
	}

	return bOk;
}
Пример #6
0
//see Q160957 and http://developer.netscape.com/docs/manuals/communicator/DDE/index.htm
static void GetOpenBrowserUrlsForBrowser(const char *szBrowser, HWND hwndDlg, HWND hwndCombo)
{
	int windowCount, i;
	DWORD *windowId;
	DWORD dwResult;

	ATOM hSzBrowser = GlobalAddAtomA(szBrowser);

	ATOM hSzTopic = GlobalAddAtomA("WWW_ListWindows");
	ddeAcked = 0;
	if ( !SendMessageTimeout(HWND_BROADCAST, WM_DDE_INITIATE, (WPARAM)hwndDlg, MAKELPARAM(hSzBrowser, hSzTopic), SMTO_ABORTIFHUNG|SMTO_NORMAL, DDEMESSAGETIMEOUT, (PDWORD_PTR)&dwResult)
	   || !ddeAcked) {
		GlobalDeleteAtom(hSzTopic);
		GlobalDeleteAtom(hSzBrowser);
		return;
	}
	HGLOBAL hData = DoDdeRequest("WWW_ListWindows", hwndDlg);
	if (hData == NULL) {
		GlobalDeleteAtom(hSzTopic);
		GlobalDeleteAtom(hSzBrowser);
		return;
	}
	int dataLength = GlobalSize(hData)-offsetof(DDEDATA, Value);
	DDEDATA *data = (DDEDATA*)GlobalLock(hData);
	windowCount = dataLength / sizeof(DWORD);
	windowId = (PDWORD)mir_alloc(sizeof(DWORD)*windowCount);
	memcpy(windowId, data->Value, windowCount*sizeof(DWORD));
	GlobalUnlock(hData);
	FreeDdeRequestData(hData);
	PostMessage(hwndDde, WM_DDE_TERMINATE, (WPARAM)hwndDlg, 0);
	GlobalDeleteAtom(hSzTopic);

	hSzTopic = GlobalAddAtomA("WWW_GetWindowInfo");
	ddeAcked = 0;
	if ( !SendMessageTimeout(HWND_BROADCAST, WM_DDE_INITIATE, (WPARAM)hwndDlg, MAKELPARAM(hSzBrowser, hSzTopic), SMTO_ABORTIFHUNG|SMTO_NORMAL, DDEMESSAGETIMEOUT, (PDWORD_PTR)&dwResult)
	   || !ddeAcked) {
		GlobalDeleteAtom(hSzTopic);
		GlobalDeleteAtom(hSzBrowser);
		mir_free(windowId);
		return;
	}
	for (i=0;i<windowCount;i++) {
		if (windowId[i] == 0) break;
		{	char str[16];
			mir_snprintf(str, _countof(str), "%d", windowId[i]);
			hData = DoDdeRequest(str, hwndDlg);
		}
		if (hData != NULL) {
			dataLength = GlobalSize(hData)-offsetof(DDEDATA, Value);
			data = (DDEDATA*)GlobalLock(hData);
			AddBrowserPageToCombo((char*)data->Value, hwndCombo);
			GlobalUnlock(hData);
			FreeDdeRequestData(hData);
		}
	}
	PostMessage(hwndDde, WM_DDE_TERMINATE, (WPARAM)hwndDlg, 0);
	GlobalDeleteAtom(hSzTopic);
	GlobalDeleteAtom(hSzBrowser);
	mir_free(windowId);
}
Пример #7
0
static void setPathForAppDir(bool fRemove)
{
    QCoreApplication &a = *QApplication::instance();

    QSettings settings("HKEY_CURRENT_USER\\Environment", QSettings::NativeFormat);
    QString sPath = settings.value("PATH", QString()).toString();

    if (fRemove) {
        sPath = sPath.remove(QString(";") + a.applicationDirPath());
        sPath = sPath.remove(a.applicationDirPath());
        if (sPath.isEmpty())
            settings.remove("PATH");
        else
            settings.setValue("PATH", sPath);
    }
    else {
        if (sPath.isEmpty())
            settings.setValue("PATH", a.applicationDirPath());
        else if (!sPath.contains(a.applicationDirPath()))
            settings.setValue("PATH", a.applicationDirPath() + ";" + sPath);
        else
            return;
    }

    SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)L"Environment", SMTO_ABORTIFHUNG, 500, NULL);
    SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)"Environment", SMTO_ABORTIFHUNG, 500, NULL);
}
Пример #8
0
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// SHUTdown
HRESULT SHUT(PCTSTR ptzCmd)
{
	Priv(SE_SHUTDOWN_NAME);
	BOOL bReboot = ((*ptzCmd) == 'R') || ((*ptzCmd) == 'r');
	if (ExitWindowsEx(bReboot ? EWX_REBOOT : EWX_POWEROFF, 0))
	{
		return S_OK;
	}

	// End session
	DWORD dwResult;
	SendMessageTimeout(HWND_BROADCAST, WM_QUERYENDSESSION, 0, 0, 0, 2000, &dwResult);
	SendMessageTimeout(HWND_BROADCAST, WM_ENDSESSION, 0, 0, 0, 2000, &dwResult);
	//SendMessageTimeout(HWND_BROADCAST, WM_CLOSE, 0, 0, 0, 2000, &dwResult);
	SendMessageTimeout(HWND_BROADCAST, WM_DESTROY, 0, 0, 0, 2000, &dwResult);

	// Get function address
	typedef DWORD (NTAPI *PNtShutdownSystem)(DWORD dwAction);
	PNtShutdownSystem NtShutdownSystem = (PNtShutdownSystem) GetProcAddress(GetModuleHandle(TEXT("NTDLL")), "NtShutdownSystem");
	if (!NtShutdownSystem)
	{
		return E_FAIL;
	}

	// Shutdown
	return NtShutdownSystem(bReboot ? 1: 2);
}
Пример #9
0
static HICON
get_icon(HWND hwnd, int large)
{
    HICON icon;

    if (!SendMessageTimeout(hwnd, WM_GETICON, large ? ICON_BIG : ICON_SMALL,
                            0, SMTO_ABORTIFHUNG, 1000, (PDWORD_PTR) & icon))
        return NULL;

    if (icon)
        return icon;

    /*
     * Modern versions of Windows uses the voodoo value of 2 instead of 0
     * for the small icons.
     */
    if (!large) {
        if (!SendMessageTimeout(hwnd, WM_GETICON, 2,
                                0, SMTO_ABORTIFHUNG, 1000, (PDWORD_PTR) & icon))
            return NULL;
    }

    if (icon)
        return icon;

    icon = (HICON) GetClassLongPtr(hwnd, large ? GCLP_HICON : GCLP_HICONSM);

    if (icon)
        return icon;

    return NULL;
}
Пример #10
0
void SkypeSend(char *szMsg) {
   COPYDATASTRUCT CopyData;
   int count=0;

   if (!hSkypeWnd) {
	   LOG(("SkypeSend: DAMN! No Skype window handle! :("));
	   return;
   }
   if (strcmp(szMsg, "PING")) {LOG(("> %s", szMsg));}
   CopyData.dwData=0; 
   CopyData.lpData=szMsg; 
   CopyData.cbData=strlen(szMsg)+1;
   while (!SendMessageTimeout(hSkypeWnd, WM_COPYDATA, (WPARAM)hWnd, (LPARAM)&CopyData, SMTO_ABORTIFHUNG, 3000, NULL)) {
	   count++;
	   LOG(("SkypeSend: failed, try #%d", count));
	   if (count==5) {
		   OUTPUT("Sending message to Skype failed too often.");
		   OUTPUT("Skype may have died unexpectedly, I will try to restart it.");
		   ConnectToSkypeAPI((void *)TRUE);
		   OUTPUT("Restart complete. Trying to deliver message one more time.");
		   if (!SendMessageTimeout(hSkypeWnd, WM_COPYDATA, (WPARAM)hWnd, (LPARAM)&CopyData, SMTO_ABORTIFHUNG, 3000, NULL)) {
			   OUTPUT("It still failed. Skype seems to be completely f*cked up. I've given up. Bye..");
			   bail_out(1);
			   break;
		   } else { 
			   OUTPUT("Now it worked! :)");
			   break;
		   }
	   }
	   Sleep(1000);
   }
}
Пример #11
0
static void GetWindowIcons(HWND hwnd, HICON* phIcon, HICON* phIconSm) 
{

	_ASSERT(phIcon);

	BOOL fIsHungApp = FALSE;

	HICON hIcon = NULL;
	if (!SendMessageTimeout(hwnd, WM_GETICON, ICON_BIG, 0, 
							SMTO_ABORTIFHUNG, HUNG_TIMEOUT, (PDWORD_PTR)&hIcon)) {
		DWORD dwErr = GetLastError();
		if (dwErr == 0 || dwErr == 1460) {
			fIsHungApp = TRUE;
			goto _HUNG_ICON;
		}
	}
	if (!hIcon) 
		hIcon = (HICON)(UINT_PTR)GetClassLongPtr(hwnd, GCLP_HICON);

	if (!hIcon) {
	_HUNG_ICON:		
		hIcon = LoadIcon(NULL, IDI_APPLICATION);
	}
	*phIcon = hIcon;

	if (phIconSm) {
		if (fIsHungApp)
			goto _HUNG_ICONSM;
		hIcon = NULL;
		if (!SendMessageTimeout(hwnd, WM_GETICON, ICON_SMALL, 0, 
								SMTO_ABORTIFHUNG, HUNG_TIMEOUT, (PDWORD_PTR)&hIcon)) {
			DWORD dwErr = GetLastError();
			if (dwErr == 0 || dwErr == 1460)
				goto _HUNG_ICONSM;
		}
		if (!hIcon) {
			if (!SendMessageTimeout(hwnd, WM_GETICON, ICON_SMALL2, 0, 
									SMTO_ABORTIFHUNG, HUNG_TIMEOUT, (PDWORD_PTR)&hIcon)) {
				DWORD dwErr = GetLastError();
				if (dwErr == 0 || dwErr == 1460)
					goto _HUNG_ICONSM;
			}
		}
		if (!hIcon) {
			hIcon = (HICON)(UINT_PTR)GetClassLongPtr(hwnd, GCLP_HICONSM);
		}
		if (hIcon) {
			*phIconSm = hIcon;
		} else {
		_HUNG_ICONSM:
			*phIconSm = *phIcon;
		}
	}
}
Пример #12
0
static
int trackbar_r_scroll(HWND hwnd,
                      HWND msg_hwnd, UINT msg,
                      double *delta, int length,
                      int mode)
{
    long min, max, pos, dd;
    double rest;

    if(SendMessageTimeout(hwnd, TBM_GETRANGEMIN, 0, 0,
                          SMTO_ABORTIFHUNG, 500, &min) == 0 ||
       SendMessageTimeout(hwnd, TBM_GETRANGEMAX, 0, 0,
                          SMTO_ABORTIFHUNG, 500, &max) == 0 ||
       SendMessageTimeout(hwnd, TBM_GETPOS, 0, 0,
                          SMTO_ABORTIFHUNG, 500, &pos) == 0) {
        return 0;
    }

    if(mode == 0) {
        dd = get_drag_scroll_delta(length, min, max, 0, *delta, &rest);
    } else if(mode == 1) {
        dd = trunc((*delta) / 100.0 * (max - min));
    } else {
        dd = trunc(*delta);
    }

    if(dd == 0) {
        return 1;
    }

    pos += dd;
    if(pos < min) {
        pos = min;
    } else if(pos > max) {
        pos = max;
    }

    SendMessageTimeout(hwnd, TBM_SETPOS, TRUE, pos,
                       SMTO_ABORTIFHUNG, 500, NULL);
    SendMessageTimeout(msg_hwnd, msg,
                       MAKEWPARAM(TB_THUMBPOSITION, pos),
                       (LPARAM)hwnd,
                       SMTO_ABORTIFHUNG, 500, NULL);

    if(mode == 0) {
        *delta = rest;
    } else if(mode == 1) {
        *delta -= dd * 100.0 / (max - min);
    } else {
        *delta -= dd;
    }

    return 1;
}
Пример #13
0
void CTaskSwitcher32Dlg::FilterList()
{
	m_windowList2.DeleteAllItems();

	window_list *list = window_item::get_window_list();
	CImageList *pImageList = new CImageList(); pImageList->Create( 16, 16, ILC_COLOR32 | ILC_MASK | ILC_PERITEMMIRROR, 0, 10);

	m_windowList2.SetImageList( pImageList, LVSIL_SMALL);
	int default_idx = pImageList->Add( m_hIcon );
		
	for ( unsigned int i = 0; i < list->size(); i++ )
	{
		window_item *item = (*list)[i];
		bool ok = true;
		if ( this->search.length() > 0 )
		{
			int pos = item->get_lower_title().find( this->search ) ; 
			int pos2 = item->get_process_name().find( this->search );
			if ( pos == std::string::npos && pos2 == std::string::npos ) 
				ok = false;
		}
		if ( ok )
		{
			HWND hwnd = item->get_handle();
			HICON hIcon = NULL;
 
			SendMessageTimeout(hwnd, WM_GETICON, ICON_BIG, 0, SMTO_ABORTIFHUNG, 1000, (LPDWORD)&hIcon);
			if (!hIcon) SendMessageTimeout(hwnd, WM_GETICON, ICON_SMALL2, 0, SMTO_ABORTIFHUNG, 1000, (LPDWORD)&hIcon);
 			if (!hIcon) SendMessageTimeout(hwnd, WM_GETICON, ICON_SMALL, 0, SMTO_ABORTIFHUNG, 1000, (LPDWORD)&hIcon);
            if (!hIcon) hIcon = (HICON)GetClassLong(hwnd, GCL_HICON);
            if (!hIcon) hIcon = (HICON)GetClassLong(hwnd, GCL_HICONSM);
        
		
			int imageidx = -1;
			if ( hIcon != NULL )
			{
				HICON iconCopy = CopyIcon( hIcon );				
				imageidx = pImageList->Add( iconCopy );
				DestroyIcon( iconCopy );
			}
			else
			{
				imageidx = 1;
			}
			int idx = m_windowList2.InsertItem( 0, item->get_title().c_str(), imageidx );
			m_windowList2.SetItem(  idx, 1, LVIF_TEXT | LVIF_IMAGE, item->get_process_name().c_str(), imageidx, 0, 0, 0 );
			m_windowList2.SetItemData( idx, (DWORD_PTR) item );
			
		}
	}
	m_windowList2.SetItemState( 0, LVIS_SELECTED, LVIS_SELECTED );
	m_windowList2.SetSelectionMark( 0 );

}
Пример #14
0
HICON GetIcon(HWND iWin)
{
	HICON hIcon = NULL;
	SendMessageTimeout(iWin, WM_GETICON, ICON_BIG, 0, SMTO_ABORTIFHUNG|SMTO_BLOCK, 300, (PDWORD_PTR)&hIcon);
	if (NULL == hIcon) hIcon = (HICON)(DWORD_PTR)GetClassLongPtr(iWin, GCLP_HICON);
	if (NULL == hIcon)
		SendMessageTimeout(iWin, WM_GETICON, ICON_SMALL, 0, SMTO_ABORTIFHUNG|SMTO_BLOCK, 300, (PDWORD_PTR)&hIcon);
	if (NULL == hIcon) hIcon = (HICON)(DWORD_PTR)GetClassLongPtr(iWin, GCLP_HICONSM);
	if (NULL == hIcon) hIcon = LoadIcon(NULL, IDI_APPLICATION);
	return hIcon;
}
Пример #15
0
void CScheduler::Execute(HWND hWnd, const CString& sTaskData)
{
	DWORD_PTR dwResult;

	// Execute the selected scheduled task
	int nAction = _tstoi( sTaskData );
	switch ( nAction )
	{
	case SYSTEM_DIALUP_DC:
		if ( ! hWnd )
		{
			HangUpConnection();
		}
		return;

	case SYSTEM_EXIT:
		// Close remote Shareaza
		if ( hWnd )
		{
			SendMessageTimeout( hWnd, WM_CLOSE, 0, 0, SMTO_NORMAL, 250, &dwResult );
		}
		return;

	case SYSTEM_SHUTDOWN:
		// Begin shutdown
		if ( SetShutdownRights() && ShutDownComputer() )
		{
			// Close remote Shareaza
			if ( hWnd )
			{
				SendMessageTimeout( hWnd, WM_CLOSE, 0, 0, SMTO_NORMAL, 250, &dwResult );
			}
		}
		return;

	case SYSTEM_START:
		// Unexpected
		return;
	}

	// Just pass data to already running Shareaza
	if ( hWnd )
	{
		COPYDATASTRUCT cd =
		{
			COPYDATA_SCHEDULER,
			sTaskData.GetLength() * sizeof( TCHAR ),
			(PVOID)(LPCTSTR)sTaskData
		};
		SendMessageTimeout( hWnd, WM_COPYDATA, NULL, (WPARAM)&cd, SMTO_NORMAL, 250, &dwResult );
	}
}
Пример #16
0
BOOL CSetMainPage::OnApply()
{
    UpdateData();
    Store (m_dwLanguage, m_regLanguage);
    if (m_sMsysGitPath.Compare(CString(m_regMsysGitPath)))
    {
        Store (m_sMsysGitPath, m_regMsysGitPath);
        m_restart = Restart_Cache;
    }
    Store (m_bCheckNewer, m_regCheckNewer);
    Store ((m_bLastCommitTime ? _T("yes") : _T("no")), m_regLastCommitTime);

    CRegString asphack_local(_T("System\\CurrentControlSet\\Control\\Session Manager\\Environment\\SVN_ASP_DOT_NET_HACK"), _T(""), FALSE, HKEY_LOCAL_MACHINE);
    CRegString asphack_user(_T("Environment\\SVN_ASP_DOT_NET_HACK"));
    if (m_bUseDotNetHack)
    {
        asphack_local = _T("*");
        if (asphack_local.LastError)
            asphack_user = _T("*");
        if ((GetEnvironmentVariable(_T("SVN_ASP_DOT_NET_HACK"), NULL, 0)==0)&&(GetLastError()==ERROR_ENVVAR_NOT_FOUND))
        {
            DWORD_PTR dwRet = 0;
            SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)_T("Environment"), SMTO_ABORTIFHUNG, 1000, &dwRet);
            m_restart = Restart_System;
        }
    }
    else
    {
        asphack_local.removeValue();
        asphack_user.removeValue();
        if (GetEnvironmentVariable(_T("SVN_ASP_DOT_NET_HACK"), NULL, 0)!=0)
        {
            DWORD_PTR dwRet = 0;
            SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)_T("Environment"), SMTO_ABORTIFHUNG, 1000, &dwRet);
            m_restart = Restart_System;
        }
    }
    // only complete if the msysgit directory is ok
    if(g_Git.CheckMsysGitDir())
    {
        SetModified(FALSE);
        return ISettingsPropPage::OnApply();
    }
    else
    {
        CMessageBox::Show(NULL,_T("Msys Git Install Path Error"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
        return 0;
    }
}
Пример #17
0
static inline void __RemoveFromPath(const TCHAR *path) {
  HKEY env_hkey;
  LONG reg_open_return = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("System\\CurrentControlSet\\Control\\Session Manager\\Environment"), 0, KEY_ALL_ACCESS, &env_hkey);
  if (reg_open_return == ERROR_SUCCESS) {
    DWORD path_original_length;
    RegQueryValueEx(env_hkey, _T("Path"), NULL, NULL, NULL, &path_original_length);
    TCHAR *path_original = (TCHAR *)malloc(path_original_length + sizeof(TCHAR));
    RegQueryValueEx(env_hkey, _T("Path"), NULL, NULL, (LPBYTE)path_original, &path_original_length);
    path_original_length /= sizeof(TCHAR);
    int path_length = 0;
    TCHAR *path_pos;
    if (path_pos = FindPathInsidePath(path, path_original, &path_length)) {
      TCHAR *path_new = (TCHAR *)malloc((path_original_length - path_length + 1) * sizeof(TCHAR));
      _tcsnccpy(path_new, path_original, path_pos - path_original);
      _tcsnccpy(path_new + (path_pos - path_original), _T(";"), 1);
      _tcsnccpy(path_new + (path_pos - path_original) + 1, path_pos + path_length, path_original + path_original_length - path_pos - path_length);
      TCHAR *path_final = path_new;
      while (path_final < path_new + _tcslen(path_new)) {
        if (*path_final == _T(';')) {
          path_final++;
        } else {
          break;
        }
      }
      int path_final_size = _tcslen(path_final);
      while (path_final_size > 0) {
        if (*(path_final + path_final_size - 1) == _T(';')) {
          path_final_size--;
        } else {
          break;
        }
      }
      path_final[path_final_size] = _T('\0');
      path_final_size++; // RegSetValueEx required NULL terminated size
      path_final_size *= sizeof(TCHAR);

      RegSetValueEx(env_hkey, _T("Path"), 0, REG_EXPAND_SZ, (LPBYTE)path_final, path_final_size);
    } else {
      _ftprintf(stderr, _T("Path already removed"));
    }
    RegCloseKey(env_hkey);
    SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)"Environment", SMTO_ABORTIFHUNG, 3000, NULL);
    SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)L"Environment", SMTO_ABORTIFHUNG, 3000, NULL);

  } else {
    _ftprintf(stderr, _T("Key opened error."));
  }
}
Пример #18
0
void IOHandler::startLoadingAnimation(HWND window) {
	
	RECT rect;
	GetWindowRect(window, &rect);
	if (GameValueProvider::get()->isFullScreen()) {
		rect.right = (int)GetSystemMetrics(SM_CXSCREEN);
		rect.bottom = (int)GetSystemMetrics(SM_CYSCREEN);
	}


	SetWindowPos(animWindow, NULL,
	  	     rect.left,
		     rect.top,
		     rect.right,
		     rect.bottom,
		SWP_NOREDRAW | SWP_SHOWWINDOW | SWP_NOACTIVATE
		);


	//set animWindow to Foreground (to paint over other windows which were activated while playing the game)
	SendMessageTimeout(animWindow, WM_LOADINGSCREEN, 0, 0, SMTO_NORMAL, 3000, NULL);
	//set this window to foreground again
	setWindowToForeground(window);

	SetWindowLong(window, GWL_EXSTYLE, GetWindowLong(window, GWL_EXSTYLE) | WS_EX_LAYERED);
	SetLayeredWindowAttributes(window, RGB(0, 0, 0), (255 * 2) / 100, LWA_ALPHA);
	


	initAnimation(animWindow);
	ShowCursor(false);


}
Пример #19
0
DWORD WINAPI fsUploadsMgr::_threadDeleteUploads(LPVOID lp)
{
	UPLS_LIST *pv = (UPLS_LIST*) lp;

	UINT msg = RegisterWindowMessage (_pszUploadsDeletedNotifyMsg);
	UINT nMemId = InterlockedIncrement (_UplsMgr.m_pnNextSharedMemId);
	CString str; str.Format (_pszSharedMemoryName, nMemId);
	vmsSharedDataT <UINT> gdata (str, FALSE, pv->size ());
	int cUplds = 0;

	for (size_t i = 0; i < pv->size (); i++)
	{
		vmsUploadSmartPtr upl = pv->at (i); 
		
		if ((upl->dwFlags & UF_READONLY) == 0)
		{
			upl->pMgr->StopUploading (TRUE);
			upl->pMgr->DeleteZipFile ();
		}

		if ((upl->dwFlags & UF_DONTNOTIFYABOUTDELETE) == 0)
			gdata [cUplds++] = upl->nID;
	}

	DWORD dw;
	if (cUplds)
		SendMessageTimeout (HWND_BROADCAST, msg, cUplds, nMemId, 0, 5000, &dw);

	delete pv;
	return 0;
}
Пример #20
0
_Check_return_
BOOLEAN ProcessHackerShutdown(
    VOID
    )
{
    HWND WindowHandle;

    WindowHandle = FindWindow(L"ProcessHacker", NULL);

    if (WindowHandle)
    {
        HANDLE processHandle;
        ULONG processID = 0;
        ULONG threadID = GetWindowThreadProcessId(WindowHandle, &processID);

        SendMessageTimeout(WindowHandle, WM_QUIT, 0, 0, SMTO_ABORTIFHUNG | SMTO_BLOCK, 5000, NULL);

        if (NT_SUCCESS(PhOpenProcess(&processHandle, SYNCHRONIZE | PROCESS_TERMINATE, ULongToHandle(processID))))
        {
            //PostMessage(WindowHandle, WM_QUIT, 0, 0);
            // Wait on the process handle, if we timeout, kill it.
            //if (WaitForSingleObject(processHandle, 10000) != WAIT_OBJECT_0)

            NtTerminateProcess(processHandle, 1);
            NtClose(processHandle);
        }
    }

    return FALSE;
}
Пример #21
0
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
  // Retrieve the process and thread id of the current window
  // NOTE: For some reason it catches the wrong thread for the window owner
  DWORD dwProcId, dwThreadId;
  dwThreadId = GetWindowThreadProcessId(hwnd, &dwProcId);

  // If the window's owning process ID is the current process
  if ( dwProcId != GetCurrentProcessId() )
    return TRUE;
  
  // Check if the window is not responding
  if ( SendMessageTimeout(hwnd, WM_NULL, 0, 0, SMTO_ABORTIFHUNG, 5000, nullptr) != 0 )
    return TRUE;

  // The message failed
  
  /*
  // if ( GetLastError() == ERROR_TIMEOUT )
  Thread::lock_mutex();
  
  // WRONG THREAD!!!
  // If the thread exists in our thread pool
  auto i = Thread::threadMap.find(dwThreadId);
  if ( i != Thread::threadMap.end() )
    i->second.breakInfiniteLoop();  // skip all instructions until after the next conditional jump

  Thread::unlock_mutex();*/
  SetLastError(WATCHDOG_ERR);
  return FALSE;
}
/**
 * sendPackage - uses SendMessage(WM_COPYDATA) to do IPC messaging
 *               with the Java AccessBridge DLL
 *
 *               NOTE: WM_COPYDATA is only for one-way IPC; there
 *               is now way to return parameters (especially big ones)
 *               Use sendMemoryPackage() to do that!
 */
LRESULT
AccessBridgeJavaVMInstance::sendPackage(char *buffer, long bufsize) {
    COPYDATASTRUCT toCopy;
    toCopy.dwData = 0;          // 32-bits we could use for something...
    toCopy.cbData = bufsize;
    toCopy.lpData = buffer;

    PrintDebugString("In AccessBridgeVMInstance::sendPackage");
    PrintDebugString("    javaAccessBridgeWindow: %p", javaAccessBridgeWindow);
    /* This was SendMessage.  Normally that is a blocking call.  However, if
     * SendMessage is sent to another process, e.g. another JVM and an incoming
     * SendMessage is pending, control will be passed to the DialogProc to handle
     * the incoming message.  A bug occurred where this allowed an AB_DLL_GOING_AWAY
     * message to be processed deleting an AccessBridgeJavaVMInstance object in
     * the javaVMs chain.  SendMessageTimeout with SMTO_BLOCK set will prevent the
     * calling thread from processing other requests while waiting, i.e control
     * will not be passed to the DialogProc.  Also note that PostMessage or
     * SendNotifyMessage can't be used.  Although they don't allow transfer to
     * the DialogProc they can't be used in cases where pointers are passed.  This
     * is because the referenced memory needs to be available when the other thread
     * gets control.
     */
    UINT flags = SMTO_BLOCK | SMTO_NOTIMEOUTIFNOTHUNG;
    DWORD_PTR out; // not used
    LRESULT lr = SendMessageTimeout( javaAccessBridgeWindow, WM_COPYDATA,
                                     (WPARAM)ourAccessBridgeWindow, (LPARAM)&toCopy,
                                     flags, 4000, &out );
    return lr;
}
Пример #23
0
//------------------------------------------------------------------------------
// 
//------------------------------------------------------------------------------
COMMONEXPORT BOOL _SetForegroundWindowEx ( HWND hWnd )
{
	if (hWnd == NULL)
		return FALSE;
	
	// determine current foreground window
	HWND hWndForeground = ::GetForegroundWindow ();

	if (hWndForeground == NULL)
		return ::SetForegroundWindow (hWnd);

	// check whether it is able to pump messages to avoid deadlocks
	DWORD dwResult = 0;

    if  ( SendMessageTimeout ( hWndForeground, WM_NULL, 0, 0, SMTO_NORMAL, 1000, &dwResult ) == 0 )
		return FALSE;

	int iTID = ::GetWindowThreadProcessId ( hWnd, 0 );
	int iForegroundTID  = ::GetWindowThreadProcessId ( hWndForeground, 0 );
	
	AttachThreadInput (iTID, iForegroundTID, TRUE);
	
	::SetForegroundWindow (hWnd);
	
	AttachThreadInput (iTID, iForegroundTID, FALSE);

    return TRUE;
}
Пример #24
0
static void RemoveMdsPath() {
	DWORD dwReturnValue;
	int found = 0;
	HKEY key = NULL;
	if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,envkey,0,KEY_READ | KEY_WRITE,&key) == ERROR_SUCCESS) {
	    long valtype;
	    unsigned long path_len;
	    if (RegQueryValueEx(key,"PATH",0,&valtype,NULL,&path_len) == ERROR_SUCCESS) {
	      char *path;
	      char *mpath;
	      path = malloc(path_len);
	      RegQueryValueEx(key,"PATH",0,&valtype,path,&path_len);
		  while ((mpath=strstr(path,mdspath)) != (char *)0) {
			  found=1;
			  mpath[0]='\0';
			  strcat(path,mpath+strlen(mdspath));
		  }
		  if (found)
			  RegSetValueEx(key,"PATH",0,REG_EXPAND_SZ,path,(DWORD)strlen(path));
	      free(path);
		}
	}
	if (key != NULL) RegCloseKey(key);
	SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0,
    (LPARAM) "Environment", SMTO_ABORTIFHUNG,
    5000, &dwReturnValue);
	return;
}
Пример #25
0
/// notify
bool notify(void *i_data, size_t i_dataSize)
{
    COPYDATASTRUCT cd;
#ifdef MAYU64
    DWORD_PTR result;
#else  // MAYU64
    DWORD result;
#endif // MAYU64

    DWORD len;
    if (g.m_hMailslot != INVALID_HANDLE_VALUE) {
        BOOL ret;
        ret = WriteFile(g.m_hMailslot, i_data, i_dataSize, &len, NULL);
#ifndef NDEBUG
        if (ret == 0) {
            HOOK_RPT2("MAYU: %S WriteFile to mailslot failed(0x%08x)\r\n", g.m_moduleName, GetLastError());
        } else {
            HOOK_RPT1("MAYU: %S WriteFile to mailslot successed\r\n", g.m_moduleName);
        }
#endif // !NDEBUG
    } else {
        cd.dwData = reinterpret_cast<Notify *>(i_data)->m_type;
        cd.cbData = i_dataSize;
        cd.lpData = i_data;
        if (g.m_hwndTaskTray == 0 || cd.dwData == Notify::Type_threadDetach)
            return false;
        if (!SendMessageTimeout(reinterpret_cast<HWND>(g.m_hwndTaskTray),
                                WM_COPYDATA, NULL, reinterpret_cast<LPARAM>(&cd),
                                SMTO_ABORTIFHUNG | SMTO_NORMAL, 5000, &result)) {
            _RPT0(_CRT_WARN, "MAYU: SendMessageTimeout() timeouted\r\n");
            return false;
        }
    }
    return true;
}
Пример #26
0
/**
	win_env_changed : void -> void
	<doc>Tell that the windows envionment variables were changed in the registry</doc>
**/
static value win_env_changed() {
#	ifdef NEKO_WINDOWS
	DWORD unused;
	SendMessageTimeout(HWND_BROADCAST,WM_SETTINGCHANGE, 0, (LPARAM)"Environment", SMTO_ABORTIFHUNG, 5000, &unused );
#	endif
	return val_null;
}
Пример #27
0
bool
ProgressDialogImpl::HasUserCancelled ()
{
  if (hWindow == 0)
    {
      return (false);
    }

  DWORD_PTR res;

  if (! SendMessageTimeout(hWindow,
			   HASUSERCANCELLED,
			   0,
			   0,
			   0,
			   1000,
			   &res))
    {
      CHECK_WINDOWS_ERROR ("SendMessageTimeout", 0);
      FATAL_MIKTEX_ERROR ("ProgressDialogImpl::HasUserCancelled",
			  T_("The progress window does not respond."),
			  0);
    }

  return (res ? true : false);
}
Пример #28
0
LRESULT CALLBACK
KeyHookMsg(int code, WPARAM w, LPARAM l)
{
	if(code >= 0 && IsWindow(g_targetWnd))
	{
		PKEYINFO keyInfo = (PKEYINFO) &l;

		if(!keyInfo->extended && !keyInfo->alt && !keyInfo->notPressed)
		{
			BYTE keyState[256];
			WORD ch=0;

			GetKeyboardState(keyState);
			keyState[VK_CONTROL] = 0;
			if(ToAscii((UINT) w, keyInfo->scanCode, keyState, &ch, 0) == 1)
			{

				SendMessageTimeout(	g_targetWnd,
									g_callbackMsg, 
									ch, 
									l, 
									SMTO_BLOCK|SMTO_ABORTIFHUNG, 
									50, 
									NULL	);
			}
		}
	}

    return CallNextHookEx(NULL, code, w, l);
}
Пример #29
0
	HICON GetWindowIcon(HWND hWnd)
	{
		HICON hIcon=NULL;
		if(SendMessageTimeout(hWnd,WM_GETICON,ICON_BIG,0,SMTO_ABORTIFHUNG|SMTO_BLOCK, 1000, (DWORD_PTR *)&hIcon))
		{
			if (hIcon==NULL)
				if(!SendMessageTimeout(hWnd,WM_GETICON,ICON_SMALL,0,SMTO_ABORTIFHUNG|SMTO_BLOCK, 1000,(DWORD_PTR *)&hIcon))
					hIcon=NULL;
		}
		else
			hIcon=NULL;
		if (hIcon==NULL)
			hIcon=(HICON)(LONG_PTR)GetClassLong(hWnd,GCL_HICONSM);
		if (hIcon==NULL)
			hIcon=(HICON)(LONG_PTR)GetClassLong(hWnd,GCL_HICON);
		return hIcon;
	}
Пример #30
0
void CvJoyMonitor::PollingStopped(Device * dev)
{
    if (dev->Exist && dev->EnPolling)
    {
        UCHAR iDevice = dev->vJoyID;
        SendMessageTimeout (m_ParentWnd, WMSPP_JMON_STP, iDevice , 0, SMTO_ABORTIFHUNG, 1000, 0);
    }
}