示例#1
0
void CDefaultTerminal::CheckRegisterOsStartup()
{
	LPCWSTR ValueName = StartupValueName;
	bool bCurState = false;
	bool bNeedState = gpSet->isSetDefaultTerminal && gpSet->isRegisterOnOsStartup;
	HKEY hk;
	DWORD nSize; //, nType = 0;
	wchar_t szCurValue[MAX_PATH*3] = {};
	wchar_t szNeedValue[MAX_PATH*2+80] = {};
	LONG lRc;
	bool bPrevTSA = false;

	LPCWSTR pszConfigName = gpSetCls->GetConfigName();
	if (pszConfigName && !*pszConfigName)
		pszConfigName = NULL;

	_wsprintf(szNeedValue, SKIPLEN(countof(szNeedValue)) L"\"%s\" %s%s%s/SetDefTerm /Detached /MinTSA%s",
		gpConEmu->ms_ConEmuExe,
		pszConfigName ? L"/Config \"" : L"", pszConfigName ? pszConfigName : L"", pszConfigName ? L"\" " : L"",
		gpSet->isRegisterOnOsStartupTSA ? L"" : L" /Exit");

	if (IsRegisteredOsStartup(szCurValue, countof(szCurValue)-1, &bPrevTSA) && *szCurValue)
	{
		bCurState = true;
	}

	if ((bCurState != bNeedState)
		|| (bNeedState && (lstrcmpi(szNeedValue, szCurValue) != 0)))
	{
		if (0 == (lRc = RegCreateKeyEx(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hk, NULL)))
		{
			if (bNeedState)
			{
				nSize = ((DWORD)_tcslen(szNeedValue)+1) * sizeof(szNeedValue[0]);
				if (0 != (lRc = RegSetValueEx(hk, ValueName, 0, REG_SZ, (LPBYTE)szNeedValue, nSize)))
				{
					DisplayLastError(L"Failed to set ConEmuDefaultTerminal value in HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", lRc);
				}
			}
			else
			{
				if (0 != (lRc = RegDeleteValue(hk, ValueName)))
				{
					DisplayLastError(L"Failed to remove ConEmuDefaultTerminal value from HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", lRc);
				}
			}
			RegCloseKey(hk);
		}
		else
		{
			DisplayLastError(L"Failed to open HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run for write", lRc);
		}
	}
}
示例#2
0
// static
void Library::HandleShellExecuteError(HINSTANCE h)
{
	/* 
	Returns a value greater than 32 if successful, or an error value that is less 
	than or equal to 32 otherwise. The following table lists the error values. 
	The return value is cast as an HINSTANCE for backward compatibility with 
	16-bit Windows applications. It is not a true HINSTANCE, however. The 
	only thing that can be done with the returned HINSTANCE is to cast it to 
	an int and compare it with the value 32 or one of the error codes below.
	0	The operating system is out of memory or resources.
	ERROR_FILE_NOT_FOUND	The specified file was not found.
	ERROR_PATH_NOT_FOUND	The specified path was not found.
	ERROR_BAD_FORMAT	The .exe file is invalid (non-Microsoft Win32 .exe or error in .exe image).
	SE_ERR_ACCESSDENIED	The operating system denied access to the specified file.
	SE_ERR_ASSOCINCOMPLETE	The file name association is incomplete or invalid.
	SE_ERR_DDEBUSY	The Dynamic Data Exchange (DDE) transaction could not be completed because other DDE transactions were being processed.
	SE_ERR_DDEFAIL	The DDE transaction failed.
	SE_ERR_DDETIMEOUT	The DDE transaction could not be completed because the request timed out.
	SE_ERR_DLLNOTFOUND	The specified dynamic-link library (DLL) was not found.
	SE_ERR_FNF	The specified file was not found.
	SE_ERR_NOASSOC	There is no application associated with the given file name extension. This error will also be returned if you attempt to print a file that is not printable.
	SE_ERR_OOM	There was not enough memory to complete the operation.
	SE_ERR_PNF	The specified path was not found.
	SE_ERR_SHARE	A sharing violation occurred.
	*/

	int nError = (int) h;
	if (nError > 32) // no error
		return;
	DisplayLastError("");

}
示例#3
0
void ConEmuAbout::OnInfo_WhatsNew(bool bLocal)
{
	wchar_t sFile[MAX_PATH+80];
	int iExec = -1;

	if (bLocal)
	{
		wcscpy_c(sFile, gpConEmu->ms_ConEmuBaseDir);
		wcscat_c(sFile, L"\\WhatsNew-ConEmu.txt");

		if (FileExists(sFile))
		{
			iExec = (int)ShellExecute(ghWnd, L"open", sFile, NULL, NULL, SW_SHOWNORMAL);
			if (iExec >= 32)
			{
				return;
			}
		}
	}

	wcscpy_c(sFile, gsWhatsNew);

	iExec = (int)ShellExecute(ghWnd, L"open", sFile, NULL, NULL, SW_SHOWNORMAL);
	if (iExec >= 32)
	{
		return;
	}

	DisplayLastError(L"File 'WhatsNew-ConEmu.txt' not found, go to web page failed", iExec);
}
示例#4
0
void ConEmuAbout::OnInfo_ReportCrash(LPCWSTR asDumpWasCreatedMsg)
{
	if (nLastCrashReported)
	{
		// if previous gsReportCrash was opened less than 60 sec ago
		DWORD nLast = GetTickCount() - nLastCrashReported;
		if (nLast < 60000)
		{
			// Skip this time
			return;
		}
	}

	if (asDumpWasCreatedMsg && !*asDumpWasCreatedMsg)
	{
		asDumpWasCreatedMsg = NULL;
	}

	DWORD shellRc = (DWORD)(INT_PTR)ShellExecute(ghWnd, L"open", gsReportCrash, NULL, NULL, SW_SHOWNORMAL);
	if (shellRc <= 32)
	{
		DisplayLastError(L"ShellExecute failed", shellRc);
	}
	else if (asDumpWasCreatedMsg)
	{
		MsgBox(asDumpWasCreatedMsg, MB_OK|MB_ICONEXCLAMATION|MB_SYSTEMMODAL);
	}

	nLastCrashReported = GetTickCount();
}
NS_IMETHODIMP
WinCEUConvAdapter::GetMaxLength(const char * aSrc, 
                                PRInt32 aSrcLength, 
                                PRInt32 * aDestLength)
{
  if (mCodepage == -1 || aSrc == nsnull )
    return NS_ERROR_FAILURE;
  
  int count = MultiByteToWideChar(mCodepage,
                                  MB_PRECOMPOSED,
                                  aSrc,
                                  aSrcLength,
                                  NULL,
                                  NULL);
  
  if (count == 0 && GetLastError() == ERROR_INVALID_PARAMETER)
  {
    // fall back on the current system Windows "ANSI" code page
    
    count = MultiByteToWideChar(CP_ACP,
                                MB_PRECOMPOSED,
                                aSrc,
                                aSrcLength,
                                NULL,
                                NULL);
  }
  
#ifdef ALERT_DBG  
  if (count == 0)
    DisplayLastError("MultiByteToWideChar (0)");
#endif
  
  *aDestLength = count;
  return NS_OK;
}
示例#6
0
bool CConEmuUpdate::CanUpdateInstallation()
{
	if (UpdateDownloadSetup() == 1)
	{
		// Если через Setupper - то msi сам разберется и ругнется когда надо
		return true;
	}

	// Раз дошли сюда - значит ConEmu был просто "распакован"

	if (IsUserAdmin())
	{
		// ConEmu запущен "Под администратором", проверки не нужны
		return true;
	}

	wchar_t szTestFile[MAX_PATH*2];
	wcscpy_c(szTestFile, gpConEmu->ms_ConEmuExeDir);
	wcscat_c(szTestFile, L"\\ConEmuUpdate.check");

	HANDLE hFile = CreateFile(szTestFile, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL|FILE_ATTRIBUTE_TEMPORARY, NULL);
	if (hFile == INVALID_HANDLE_VALUE)
	{
		DWORD nErr = GetLastError();
		wcscpy_c(szTestFile, L"Can't update installation folder!\r\n");
		wcscat_c(szTestFile, gpConEmu->ms_ConEmuExeDir);
		DisplayLastError(szTestFile, nErr);
		return false;
	}
	CloseHandle(hFile);
	DeleteFile(szTestFile);

	// OK
	return true;
}
示例#7
0
void CTabPanelWin::ShowToolbar(bool bShow)
{
	if (bShow)
	{
		if (!IsToolbarCreated() && (CreateToolbar() != NULL))
		{
			REBARBANDINFO rbBand = {80}; // не используем size, т.к. приходит "новый" размер из висты и в XP обламываемся

			rbBand.fMask  = RBBIM_SIZE | RBBIM_CHILD | RBBIM_CHILDSIZE | RBBIM_ID | RBBIM_STYLE | RBBIM_COLORS;
			rbBand.fStyle = RBBS_CHILDEDGE | RBBS_FIXEDSIZE | RBBS_VARIABLEHEIGHT;
			rbBand.clrBack = GetSysColor(COLOR_BTNFACE);
			rbBand.clrFore = GetSysColor(COLOR_BTNTEXT);

			SIZE sz = {0,0};
			SendMessage(mh_Toolbar, TB_GETMAXSIZE, 0, (LPARAM)&sz);

			// Set values unique to the band with the toolbar.
			rbBand.wID        = 2;
			rbBand.hwndChild  = mh_Toolbar;
			rbBand.cx = rbBand.cxMinChild = rbBand.cxIdeal = mn_LastToolbarWidth = sz.cx;
			rbBand.cyChild = rbBand.cyMinChild = rbBand.cyMaxChild = sz.cy + mn_ThemeHeightDiff;

			// Add the band that has the toolbar.
			if (!SendMessage(mh_Rebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand))
			{
				DisplayLastError(_T("Can't initialize rebar (toolbar)"));
			}
		}
	}
	else
	{
		_ASSERTEX(bShow);
	}
}
示例#8
0
文件: FindDlg.cpp 项目: G-VAR/ConEmu
void CEFindDlg::FindTextDialog()
{
	if (mh_FindDlg && IsWindow(mh_FindDlg))
	{
		SetForegroundWindow(mh_FindDlg);
		return;
	}

	CVConGuard VCon;
	CRealConsole* pRCon = (CVConGroup::GetActiveVCon(&VCon) >= 0) ? VCon->RCon() : NULL;

	// Создаем диалог поиска только для консольных приложений
	if (!pRCon || (pRCon->GuiWnd() && !pRCon->isBufferHeight()) || !pRCon->GetView())
	{
		//DisplayLastError(L"No RealConsole, nothing to find");
		return;
	}

	gpConEmu->SkipOneAppsRelease(true);
	
	mh_FindDlg = CreateDialogParam((HINSTANCE)GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_FIND), ghWnd, findTextProc, 0/*Param*/);
	if (!mh_FindDlg)
	{
		DisplayLastError(L"Can't create Find text dialog", GetLastError());
	}
}
NS_IMETHODIMP
WinCEUConvAdapter::Convert(const PRUnichar * aSrc, 
                           PRInt32 * aSrcLength, 
                           char * aDest, 
                           PRInt32 * aDestLength)
{
  if (mCodepage == -1)
    return NS_ERROR_FAILURE;
  
  char * defaultChar = "?";
  int count = WideCharToMultiByte(mCodepage,
                                  0,
                                  aSrc,
                                  *aSrcLength,
                                  aDest,
                                  *aDestLength,
                                  defaultChar,
                                  NULL);
  
#ifdef ALERT_DBG
  if (count == 0)
    DisplayLastError("WideCharToMultiByte");
#endif
  
  *aSrcLength = count;
  *aDestLength = count;
  
  return NS_OK;
}
示例#10
0
bool MyOpenClipboard(LPCWSTR asAction)
{
	_ASSERTE(gnMyClipboardOpened==0 || gnMyClipboardOpened==1);

	if (gnMyClipboardOpened > 0)
	{
		InterlockedIncrement(&gnMyClipboardOpened);
		return true;
	}

	BOOL lbRc;
	int iMaxTries = 100;

	// Open Windows' clipboard
	while (!(lbRc = OpenClipboard((ghWnd && IsWindow(ghWnd)) ? ghWnd : NULL)) && (iMaxTries-- > 0))
	{
		DWORD dwErr = GetLastError();

		wchar_t szCode[32]; _wsprintf(szCode, SKIPCOUNT(szCode) L", Code=%u", dwErr);
		wchar_t* pszMsg = lstrmerge(L"OpenClipboard failed (", asAction, L")", szCode);
		LogString(pszMsg);
		int iBtn = DisplayLastError(pszMsg, dwErr, MB_RETRYCANCEL|MB_ICONSTOP);
		SafeFree(pszMsg);

		if (iBtn != IDRETRY)
			return false;
	}

	InterlockedIncrement(&gnMyClipboardOpened);
	_ASSERTE(gnMyClipboardOpened==1);

	LogString(L"OpenClipboard succeeded");
	return true;
}
示例#11
0
bool CDlgItemHelper::ProcessHyperlinkCtrl(HWND hDlg, WORD nCtrlId)
{
	if (!isHyperlinkCtrl(nCtrlId))
	{
		return false;
	}

	CEStr lsUrl;

	switch (nCtrlId)
	{
	case stConEmuUrl:
		lsUrl = gsHomePage;
		break;
	case stHomePage:
		lsUrl = gsFirstStart;
		break;
	default:
		if (GetString(hDlg, nCtrlId, &lsUrl.ms_Val) <= 0)
			return false;
		if ((0 != wcsncmp(lsUrl, L"http://", 7))
			&& (0 != wcsncmp(lsUrl, L"https://", 8))
			) return false;
	}

	DWORD shellRc = (DWORD)(INT_PTR)ShellExecute(ghWnd, L"open", lsUrl, NULL, NULL, SW_SHOWNORMAL);
	if (shellRc <= 32)
	{
		DisplayLastError(L"ShellExecute failed", shellRc);
		return false;
	}

	return true;
}
示例#12
0
// Открыть диалог с подтверждением параметров создания/закрытия/пересоздания консоли
int CRecreateDlg::RecreateDlg(RConStartArgsEx* apArgs, bool abDontAutoSelCmd /*= false*/)
{
	if (!this)
	{
		_ASSERTE(this);
		return IDCANCEL;
	}

	mb_DontAutoSelCmd = abDontAutoSelCmd;

	if (mh_Dlg && IsWindow(mh_Dlg))
	{
		DisplayLastError(L"Close previous 'Create dialog' first, please!", -1);
		return IDCANCEL;
	}

	DontEnable de;

	gpConEmu->SkipOneAppsRelease(true);

	//if (!gpConEmu->mh_RecreatePasswFont)
	//{
	//	gpConEmu->mh_RecreatePasswFont = CreateFont(

	//}

	mn_DlgRc = IDCANCEL;
	mp_Args = apArgs;

	mh_Parent = (apArgs->aRecreate == cra_EditTab && ghOpWnd) ? ghOpWnd : ghWnd;

	#ifdef _DEBUG
	if ((mh_Parent == ghWnd) && gpConEmu->isIconic())
	{
		_ASSERTE(FALSE && "Window must be shown before dialog!");
	}
	#endif

	InitVars();

	bool bPrev = gpConEmu->SetSkipOnFocus(true);
	CDpiForDialog::Create(mp_DpiAware);
	// Modal dialog (CreateDialog)
	int nRc = CDynDialog::ExecuteDialog(IDD_RESTART, mh_Parent, RecreateDlgProc, (LPARAM)this);
	UNREFERENCED_PARAMETER(nRc);
	gpConEmu->SetSkipOnFocus(bPrev);

	FreeVars();

	//if (gpConEmu->mh_RecreatePasswFont)
	//{
	//	DeleteObject(gpConEmu->mh_RecreatePasswFont);
	//	gpConEmu->mh_RecreatePasswFont = NULL;
	//}

	gpConEmu->SkipOneAppsRelease(false);

	return mn_DlgRc;
}
示例#13
0
void ConEmuAbout::OnInfo_ReportBug()
{
	DWORD shellRc = (DWORD)(INT_PTR)ShellExecute(ghWnd, L"open", gsReportBug, NULL, NULL, SW_SHOWNORMAL);
	if (shellRc <= 32)
	{
		DisplayLastError(L"ShellExecute failed", shellRc);
	}
}
示例#14
0
void ConEmuAbout::DonateBtns_Add(HWND hDlg, int AlignLeftId, int AlignVCenterId)
{
	if (!m_Btns[0].pImg)
		LoadResources();

	RECT rcLeft = {}, rcTop = {};
	HWND hCtrl;

	hCtrl = GetDlgItem(hDlg, AlignLeftId);
	GetWindowRect(hCtrl, &rcLeft);
	MapWindowPoints(NULL, hDlg, (LPPOINT)&rcLeft, 2);
	hCtrl = GetDlgItem(hDlg, AlignVCenterId);
	GetWindowRect(hCtrl, &rcTop);
	int nPreferHeight = rcTop.bottom - rcTop.top;
	MapWindowPoints(NULL, hDlg, (LPPOINT)&rcTop, 2);

	#ifdef _DEBUG
	DpiValue dpi;
	CDpiAware::QueryDpiForWindow(hDlg, &dpi);
	#endif

	int X = rcLeft.left;

	for (size_t i = 0; i < countof(m_Btns); i++)
	{
		if (!m_Btns[i].pImg)
			continue; // Image was failed

		TODO("Вертикальное центрирование по объекту AlignVCenterId");

		int nDispW = 0, nDispH = 0;
		if (!m_Btns[i].pImg->GetSizeForHeight(nPreferHeight, nDispW, nDispH))
		{
			_ASSERTE(FALSE && "Image not available for dpi?");
			continue; // Image was failed?
		}
		_ASSERTE(nDispW>0 && nDispH>0);
		int nY = rcTop.top + ((rcTop.bottom - rcTop.top - nDispH + 1) / 2);

		hCtrl = CreateWindow(L"STATIC", m_Btns[i].ResId,
			WS_CHILD|WS_VISIBLE|SS_NOTIFY|SS_OWNERDRAW,
			X, nY, nDispW, nDispH,
			hDlg, (HMENU)m_Btns[i].nCtrlId, g_hInstance, NULL);

		#ifdef _DEBUG
		if (!hCtrl)
			DisplayLastError(L"Failed to create image button control");
		#endif

		//X += nDispW + (10 * dpi.Ydpi / 96);
		X += nDispW + (nDispH / 3);
	}

	RegisterTip(hDlg);

	UNREFERENCED_PARAMETER(hCtrl);
}
示例#15
0
void ConEmuAbout::OnInfo_OnlineWiki(LPCWSTR asPageName /*= NULL*/)
{
	CEStr szUrl(lstrmerge(CEWIKIBASE, asPageName ? asPageName : L"TableOfContents", L".html"));
	DWORD shellRc = (DWORD)(INT_PTR)ShellExecute(ghWnd, L"open", szUrl, NULL, NULL, SW_SHOWNORMAL);
	if (shellRc <= 32)
	{
		DisplayLastError(L"ShellExecute failed", shellRc);
	}
}
示例#16
0
HWND CConEmuChild::CreateView()
{
	if (!this)
	{
		_ASSERTE(this!=NULL);
		return NULL;
	}
	if (mh_WndDC || mh_WndBack)
	{
		_ASSERTE(mh_WndDC == NULL && mh_WndBack == NULL);
		return mh_WndDC;
	}

	if (!gpConEmu->isMainThread())
	{
		// Окно должно создаваться в главной нити!
		HWND hCreate = gpConEmu->PostCreateView(this); UNREFERENCED_PARAMETER(hCreate);
		_ASSERTE(hCreate && (hCreate == mh_WndDC));
		return mh_WndDC;
	}

	CVirtualConsole* pVCon = (CVirtualConsole*)this;
	_ASSERTE(pVCon!=NULL);
	//-- тут консоль только создается, guard не нужен
	//CVConGuard guard(pVCon);

	TODO("Заменить ghWnd на ghWndWork");
	HWND hParent = ghWnd;
	// Имя класса - то же самое, что и у главного окна
	DWORD style = /*WS_VISIBLE |*/ WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
	DWORD styleEx = 0;

	RECT rcBack = gpConEmu->CalcRect(CER_BACK, pVCon);
	RECT rc = gpConEmu->CalcRect(CER_DC, rcBack, CER_BACK, pVCon);

	mh_WndBack = CreateWindowEx(styleEx, gsClassNameBack, L"BackWND", style,
		rcBack.left, rcBack.top, rcBack.right - rcBack.left, rcBack.bottom - rcBack.top, hParent, NULL, (HINSTANCE)g_hInstance, pVCon);

	mn_WndDCStyle = style;
	mn_WndDCExStyle = styleEx;
	mh_WndDC = CreateWindowEx(styleEx, gsClassName, L"DrawWND", style,
		rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, hParent, NULL, (HINSTANCE)g_hInstance, pVCon);

	if (!mh_WndDC || !mh_WndBack)
	{
		DisplayLastError(L"Can't create DC window!");
		return NULL; //
	}

	SetWindowPos(mh_WndDC, HWND_TOP, 0,0,0,0, SWP_NOMOVE|SWP_NOSIZE);

	// Установить переменную среды с дескриптором окна
	SetConEmuEnvVar(mh_WndDC);

	return mh_WndDC;
}
示例#17
0
void ConEmuAbout::LoadResources()
{
	struct ImgLoadInfo
	{
		LPCWSTR ResId; UINT nCtrlId; int nWidth; int nHeight;
	} Images[] = {
		{L"DONATE", pLinkDonate, 74, 21},
		{L"FLATTR", pLinkFlattr, 89, 18},
	};
	_ASSERTE(countof(m_Btns) == countof(Images));

	for (size_t i = 0; i < countof(Images); i++)
	{
		if (m_Btns[i].hBmp)
			continue; // Already loaded

		m_Btns[i].ResId = Images[i].ResId;
		m_Btns[i].nCtrlId = Images[i].nCtrlId;
		m_Btns[i].pszUrl = (Images[i].nCtrlId == pLinkDonate) ? gsDonatePage : gsFlattrPage;
		m_Btns[i].hBmp = (HBITMAP)LoadImage(g_hInstance, Images[i].ResId, IMAGE_BITMAP, 0, 0, LR_LOADTRANSPARENT|LR_LOADMAP3DCOLORS);

		if (m_Btns[i].hBmp == NULL)
		{
			#ifdef _DEBUG
			DWORD nErr = GetLastError();
			DisplayLastError(L"Failed to load button image!", nErr);
			#endif
			m_Btns[i].bmp.bmWidth = Images[i].nWidth; m_Btns[i].bmp.bmHeight = Images[i].nHeight;
		}
		else
		{
			ZeroStruct(m_Btns[i].bmp);
			if (!GetObject(m_Btns[i].hBmp, sizeof(m_Btns[i].bmp), &m_Btns[i].bmp) || m_Btns[i].bmp.bmWidth <= 0 || m_Btns[i].bmp.bmHeight <= 0)
			{
				#ifdef _DEBUG
				DWORD nErr = GetLastError();
				DisplayLastError(L"GetObject() on button image failed!", nErr);
				#endif
				m_Btns[i].bmp.bmWidth = Images[i].nWidth; m_Btns[i].bmp.bmHeight = Images[i].nHeight;
			}
		}
	}
}
示例#18
0
void CPushInfo::OpenNotificationUrl()
{
	if (!mp_Active || !mp_Active->pszUrl)
		return;
	DWORD shellRc = (DWORD)(INT_PTR)ShellExecute(ghWnd, L"open", mp_Active->pszUrl, NULL, NULL, SW_SHOWNORMAL);
	if (shellRc <= 32)
	{
		DisplayLastError(L"ShellExecute failed", shellRc);
	}
}
示例#19
0
// Открыть диалог с подтверждением параметров создания/закрытия/пересоздания консоли
int CRecreateDlg::RecreateDlg(RConStartArgs* apArgs)
{
	if (!this)
	{
		_ASSERTE(this);
		return IDCANCEL;
	}

	if (mh_Dlg && IsWindow(mh_Dlg))
	{
		DisplayLastError(L"Close previous 'Create dialog' first, please!", -1);
		return IDCANCEL;
	}
	
	DontEnable de;

	gpConEmu->SkipOneAppsRelease(true);

	//if (!gpConEmu->mh_RecreatePasswFont)
	//{
	//	gpConEmu->mh_RecreatePasswFont = CreateFont(

	//}

	mn_DlgRc = IDCANCEL;
	mp_Args = apArgs;

	mh_Parent = (apArgs->aRecreate == cra_EditTab && ghOpWnd) ? ghOpWnd : ghWnd;

	#ifdef _DEBUG
	if ((mh_Parent == ghWnd) && gpConEmu->isIconic())
	{
		_ASSERTE(FALSE && "Window must be shown before dialog!");
	}
	#endif

	InitVars();

	bool bPrev = gpConEmu->SetSkipOnFocus(true);
	int nRc = DialogBoxParam(g_hInstance, MAKEINTRESOURCE(IDD_RESTART), mh_Parent, RecreateDlgProc, (LPARAM)this);
	UNREFERENCED_PARAMETER(nRc);
	gpConEmu->SetSkipOnFocus(bPrev);

	FreeVars();

	//if (gpConEmu->mh_RecreatePasswFont)
	//{
	//	DeleteObject(gpConEmu->mh_RecreatePasswFont);
	//	gpConEmu->mh_RecreatePasswFont = NULL;
	//}

	gpConEmu->SkipOneAppsRelease(false);

	return mn_DlgRc;
}
示例#20
0
bool CDlgItemHelper::OpenHyperlink(CEStr& url, HWND hParent)
{
	DWORD shellRc = (DWORD)(INT_PTR)ShellExecute(hParent, L"open", url, NULL, NULL, SW_SHOWNORMAL);
	if (shellRc <= 32)
	{
		DisplayLastError(L"ShellExecute failed", shellRc);
		return false;
	}

	return true;
}
示例#21
0
void ConEmuAbout::OnInfo_About(LPCWSTR asPageName /*= NULL*/)
{
	InitCommCtrls();

	bool bOk = false;

	if (!asPageName && sLastOpenTab[0])
	{
		// Reopen last active tab
		asPageName = sLastOpenTab;
	}

	ReloadSysInfo();

	{
		DontEnable de;
		if (!mp_DpiAware)
			mp_DpiAware = new CDpiForDialog();
		HWND hParent = (ghOpWnd && IsWindowVisible(ghOpWnd)) ? ghOpWnd : ghWnd;
		// Modal dialog (CreateDialog)
		INT_PTR iRc = CDynDialog::ExecuteDialog(IDD_ABOUT, hParent, aboutProc, (LPARAM)asPageName);
		bOk = (iRc != 0 && iRc != -1);

		mh_AboutDlg = NULL;
		if (mp_DpiAware)
			mp_DpiAware->Detach();

		#ifdef _DEBUG
		// Any problems with dialog resource?
		if (!bOk) DisplayLastError(L"DialogBoxParam(IDD_ABOUT) failed");
		#endif
	}

	if (!bOk)
	{
		wchar_t* pszTitle = lstrmerge(gpConEmu->GetDefaultTitle(), L" About");
		DontEnable de;
		MSGBOXPARAMS mb = {sizeof(MSGBOXPARAMS), ghWnd, g_hInstance,
			pAbout,
			pszTitle,
			MB_USERICON, MAKEINTRESOURCE(IMAGE_ICON), 0, NULL, LANG_NEUTRAL
		};
		SafeFree(pszTitle);
		// Use MessageBoxIndirect instead of MessageBox to show our icon instead of std ICONINFORMATION
		MessageBoxIndirect(&mb);
	}
}
示例#22
0
void ConEmuAbout::DonateBtns_Add(HWND hDlg, int AlignLeftId, int AlignVCenterId)
{
	if (!m_Btns[0].hBmp)
		LoadResources();

	RECT rcLeft = {}, rcTop = {};
	HWND hCtrl;

	hCtrl = GetDlgItem(hDlg, AlignLeftId);
	GetWindowRect(hCtrl, &rcLeft);
	MapWindowPoints(NULL, hDlg, (LPPOINT)&rcLeft, 2);
	hCtrl = GetDlgItem(hDlg, AlignVCenterId);
	GetWindowRect(hCtrl, &rcTop);
	MapWindowPoints(NULL, hDlg, (LPPOINT)&rcTop, 2);

	int nDisplayDpi = gpSetCls->QueryDpi();

	int X = rcLeft.left;

	for (size_t i = 0; i < countof(m_Btns); i++)
	{
		if (!m_Btns[i].hBmp)
			continue; // Image was failed

		TODO("Вертикальное центрирование по объекту AlignVCenterId");

		int nDispW = m_Btns[i].bmp.bmWidth * nDisplayDpi / 96;
		int nDispH = m_Btns[i].bmp.bmHeight * nDisplayDpi / 96;
		int nY = rcTop.top + ((rcTop.bottom - rcTop.top - nDispH + 1) / 2);

		hCtrl = CreateWindow(L"STATIC", m_Btns[i].ResId,
			WS_CHILD|WS_VISIBLE|SS_NOTIFY|SS_OWNERDRAW,
			X, nY, nDispW, nDispH,
			hDlg, (HMENU)m_Btns[i].nCtrlId, g_hInstance, NULL);

		#ifdef _DEBUG
		if (!hCtrl)
			DisplayLastError(L"Failed to create image button control");
		#endif

		X += nDispW + (10 * nDisplayDpi / 96);
	}

	RegisterTip(hDlg);

	UNREFERENCED_PARAMETER(hCtrl);
}
示例#23
0
void CTabPanelWin::ShowToolsPane(bool bShow)
{
	if (bShow)
	{
		_ASSERTE(isMainThread());
		if (!IsToolbarCreated() && (CreateToolbar() != NULL))
		{
			REBARBANDINFO rbBand = {REBARBANDINFO_SIZE}; // не используем size, т.к. приходит "новый" размер из висты и в XP обламываемся

			rbBand.fMask  = RBBIM_SIZE | RBBIM_CHILD | RBBIM_CHILDSIZE | RBBIM_ID | RBBIM_STYLE;
			rbBand.fStyle = RBBS_CHILDEDGE | RBBS_FIXEDSIZE | RBBS_VARIABLEHEIGHT;

			#if 0
			rbBand.fMask |= RBBIM_COLORS;
			rbBand.clrFore = RGB(255,255,255);
			rbBand.clrBack = RGB(0,0,255);
			#endif

			SIZE sz = {0,0};
			SendMessage(mh_Toolbar, TB_GETMAXSIZE, 0, (LPARAM)&sz);

			rbBand.wID        = rbi_ToolBar;
			rbBand.hwndChild  = mh_Toolbar;
			rbBand.cx = rbBand.cxMinChild = rbBand.cxIdeal = mn_LastToolbarWidth = sz.cx;
			rbBand.cyChild = rbBand.cyMinChild = rbBand.cyMaxChild = sz.cy + mn_ThemeHeightDiff;

			if (!SendMessage(mh_Rebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand))
			{
				DisplayLastError(_T("Can't initialize rebar (toolbar)"));
			}
		}
	}
	else
	{
		_ASSERTEX(!bShow);
		INT_PTR nPaneIndex = SendMessage(mh_Rebar, RB_IDTOINDEX, rbi_ToolBar, 0);
		if (nPaneIndex >= 0)
		{
			SendMessage(mh_Rebar, RB_DELETEBAND, nPaneIndex, 0);
			DestroyWindow(mh_Toolbar);
			mh_Toolbar = NULL;
		}
	}
}
示例#24
0
文件: logoff.c 项目: RareHare/reactos
//----------------------------------------------------------------------
//
//Main entry for program
//
//----------------------------------------------------------------------
int _tmain(int argc, TCHAR *argv[])
{
	LPTSTR lpLogoffRemote, lpLogoffLocal;

	//
	// Parse command line
	//
	if (!ParseCommandLine(argc, argv)) {
		PrintUsage();
		return 1;
	}

	//
	//Should we log off session on remote server?
	//
	if (szRemoteServerName) {
		if (bVerbose) {
			if (AllocAndLoadString(&lpLogoffRemote, GetModuleHandle(NULL), IDS_LOGOFF_REMOTE))
			_putts(lpLogoffRemote);
		}

		//FIXME: Add Remote Procedure Call to logoff user on a remote machine
		_ftprintf(stderr, "Remote Procedure Call in logoff.exe has not been implemented");
	}
	//
	//Perform logoff of current session on local machine instead
	//
	else {
		if (bVerbose) {
			//Get resource string, and print it.
			if (AllocAndLoadString(&lpLogoffLocal, GetModuleHandle(NULL), IDS_LOGOFF_LOCAL))
			_putts(lpLogoffLocal);
		}

		//Actual logoff
		if (!ExitWindows(NULL, NULL)) {
			DisplayLastError();
			return 1;
		}
	}

	return 0;
}
示例#25
0
文件: edit.c 项目: navoj/xlisp
/* xGetSelectedText - built-in function 'get-selected-text' */
static xlValue xGetSelectedText(void)
{
    DWORD start,end,length;
    xlValue obj,str;
    Widget *widget;
    HLOCAL hText;
    char *p;

    /* parse the arguments */
    obj = xlGetArgInstance(c_basicEditText);
    xlLastArg();

    /* get the widget structure */
    widget = GetWidget(obj);

    /* get the selection */
    SendMessage(widget->wnd,EM_GETSEL,(WPARAM)&start,(LPARAM)&end);

    /* compute the text length */
    if ((length = end - start) < 0)
        return xlNil;

    /* get a handle to the edit text */
    if ((hText = (HLOCAL)SendMessage(widget->wnd,EM_GETHANDLE,0,0)) == NULL)
        return xlNil;

    /* allocate a string and get the selection */
    xlCPush(obj);
    str = xlNewString((xlFIXTYPE)length);
    if ((p = (char *)LocalLock(hText)) == NULL) {
        DisplayLastError();
        str = xlNil;
    }
    else {
        memcpy(xlGetString(str),p,length);
        LocalUnlock(hText);
    }
    xlDrop(1);

    /* return the string */
    return str;
}
示例#26
0
void ConEmuAbout::OnInfo_About(LPCWSTR asPageName /*= NULL*/)
{
	InitCommCtrls();

	bool bOk = false;

	{
		DontEnable de;
		HWND hParent = (ghOpWnd && IsWindowVisible(ghOpWnd)) ? ghOpWnd : ghWnd;
		// Modal dialog
		INT_PTR iRc = DialogBoxParam(g_hInstance, MAKEINTRESOURCE(IDD_ABOUT), hParent, aboutProc, (LPARAM)asPageName);
		bOk = (iRc != 0 && iRc != -1);

		ZeroStruct(m_Btns);
		mh_AboutDlg = NULL;

		#ifdef _DEBUG
		// Any problems with dialog resource?
		if (!bOk) DisplayLastError(L"DialogBoxParam(IDD_ABOUT) failed");
		#endif
	}

	if (!bOk)
	{
		WCHAR szTitle[255];
		LPCWSTR pszBits = WIN3264TEST(L"x86",L"x64");
		LPCWSTR pszDebug = L"";
		#ifdef _DEBUG
		pszDebug = L"[DEBUG] ";
		#endif
		_wsprintf(szTitle, SKIPLEN(countof(szTitle)) L"About ConEmu (%02u%02u%02u%s %s%s)", 
			(MVV_1%100),MVV_2,MVV_3,_T(MVV_4a), pszDebug, pszBits);
		DontEnable de;
		MSGBOXPARAMS mb = {sizeof(MSGBOXPARAMS), ghWnd, g_hInstance,
			pAbout,
			szTitle,
			MB_USERICON, MAKEINTRESOURCE(IMAGE_ICON), 0, NULL, LANG_NEUTRAL
		};
		MessageBoxIndirectW(&mb);
		//MessageBoxW(ghWnd, pHelp, szTitle, MB_ICONQUESTION);
	}
}
示例#27
0
void CTabPanelWin::ShowTabsPane(bool bShow)
{
	if (bShow)
	{
		_ASSERTE(isMainThread());
		if (CreateTabbar())
		{
			RECT rcWnd = GetRect();

			REBARBANDINFO rbBand = {REBARBANDINFO_SIZE}; // не используем size, т.к. приходит "новый" размер из висты и в XP обламываемся

			rbBand.fMask  = RBBIM_SIZE | RBBIM_CHILD | RBBIM_CHILDSIZE | RBBIM_ID | RBBIM_STYLE;
			rbBand.fStyle = RBBS_CHILDEDGE | RBBS_FIXEDSIZE | RBBS_VARIABLEHEIGHT;

			#if 0
			rbBand.fMask |= RBBIM_COLORS;
			rbBand.clrFore = RGB(255,255,255);
			rbBand.clrBack = RGB(0,0,0);
			#endif

			rbBand.wID        = rbi_TabBar;
			rbBand.hwndChild  = mh_Tabbar;
			rbBand.cxMinChild = 100;
			rbBand.cx = /*rbBand.cxIdeal =*/ rcWnd.right - 20; // - sz.cx - 80 - iFindPanelWidth;
			rbBand.cyChild = rbBand.cyMinChild = rbBand.cyMaxChild = mn_TabHeight; // sz.cy;

			// Tabs are always on the first place
			if (!SendMessage(mh_Rebar, RB_INSERTBAND, (WPARAM)0, (LPARAM)&rbBand))
			{
				DisplayLastError(_T("Can't initialize rebar (tabbar)"));
			}
		}
	}
	else
	{
		_ASSERTE(FALSE && "Deletion is not supported yet");
	}
}
示例#28
0
void CEFindDlg::FindTextDialog()
{
	if (mh_FindDlg && IsWindow(mh_FindDlg))
	{
		SetForegroundWindow(mh_FindDlg);
		return;
	}

	CVConGuard VCon;
	CRealConsole* pRCon = (CVConGroup::GetActiveVCon(&VCon) >= 0) ? VCon->RCon() : NULL;

	// Создаем диалог поиска только для консольных приложений
	if (!pRCon || (pRCon->GuiWnd() && !pRCon->isBufferHeight()) || !pRCon->GetView())
	{
		//DisplayLastError(L"No RealConsole, nothing to find");
		return;
	}

	if (gpConEmu->mp_TabBar && gpConEmu->mp_TabBar->ActivateSearchPane(true))
	{
		// Контрол поиска встроен и показан в панели инструментов
		return;
	}

	gpConEmu->SkipOneAppsRelease(true);

	if (!mp_DpiAware)
		mp_DpiAware = new CDpiForDialog();

	// (CreateDialog)
	mp_Dlg = CDynDialog::ShowDialog(IDD_FIND, ghWnd, findTextProc, 0/*Param*/);
	mh_FindDlg = mp_Dlg ? mp_Dlg->mh_Dlg : NULL;
	if (!mh_FindDlg)
	{
		DisplayLastError(L"Can't create Find text dialog", GetLastError());
	}
}
NS_IMETHODIMP
WinCEUConvAdapter::GetMaxLength(const PRUnichar * aSrc, 
                                PRInt32 aSrcLength, 
                                PRInt32 * aDestLength)
{
  if (mCodepage == -1)
    return NS_ERROR_FAILURE;
  
  int count = WideCharToMultiByte(mCodepage,
                                  0,
                                  aSrc,
                                  aSrcLength,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL);
#ifdef ALERT_DBG
  if (count == 0)
    DisplayLastError("WideCharToMultiByte (0)");
#endif
  
  *aDestLength = count;
  return NS_OK;
}
NS_IMETHODIMP
WinCEUConvAdapter::Convert(const char * aSrc, 
                           PRInt32 * aSrcLength, 
                           PRUnichar * aDest, 
                           PRInt32 * aDestLength)
{
  if (mCodepage == -1)
    return NS_ERROR_FAILURE;
  
  int count = MultiByteToWideChar(mCodepage,
                                  0,
                                  aSrc,
                                  *aSrcLength,
                                  aDest,
                                  *aDestLength);
  
  if (count == 0 && GetLastError() == ERROR_INVALID_PARAMETER)
  {
    // fall back on the current system Windows "ANSI" code page
    count = MultiByteToWideChar(CP_ACP,
                                0,
                                aSrc,
                                *aSrcLength,
                                aDest,
                                *aDestLength);
  }
  
#ifdef ALERT_DBG
  if (count == 0)
    DisplayLastError("MultiByteToWideChar");
#endif
  
  *aDestLength = count;
  *aSrcLength  = count;
  return NS_OK;
}