BOOL CRegKey::DeleteKey(HKEY hKey,LPCWSTR szKey)
{
	if (!IsUnicodeSystem())
		return DeleteKey(hKey,W2A(szKey));

	HKEY hSubKey;
	FILETIME ft;
	DWORD cb;
	WCHAR szSubKey[200];
	if (RegOpenKeyExW(hKey,szKey,0,
		KEY_ENUMERATE_SUB_KEYS|KEY_SET_VALUE,&hSubKey)!=ERROR_SUCCESS)
		return TRUE;	
	DebugOpenHandle(dhtRegKey,hSubKey,szKey);
	
	for(;;)
	{
		cb=400;
		if (RegEnumKeyExW(hSubKey,0,szSubKey,&cb,NULL,
			NULL,NULL,&ft)==ERROR_NO_MORE_ITEMS)
			break;
		DeleteKey(hSubKey,szSubKey);
	}
	RegCloseKey(hSubKey);
	DebugCloseHandle(dhtRegKey,hSubKey,szKey);
	RegDeleteKeyW(hKey,szKey);
	return TRUE;
}
DWORD CRegKey::EnumKey(DWORD iSubkey,LPWSTR lpszName,DWORD cchName,LPWSTR lpszClass,LPDWORD lpcchClass,PFILETIME lpftLastWrite) const
{
	if (IsUnicodeSystem())
		return ::RegEnumKeyExW(m_hKey,iSubkey,lpszName,&cchName,0,lpszClass,lpcchClass,lpftLastWrite)==ERROR_SUCCESS?cchName+1:0;
	else
	{
		char* pClass=NULL;
		DWORD dwClass=0;
		if (lpszClass!=NULL)
		{
			pClass=new char[*lpcchClass+2];
			dwClass=*lpcchClass;
		}
		
		DWORD cb=cchName;
		char* pName=new char[cchName+2];
		
		BOOL bRet=::RegEnumKeyEx(m_hKey,iSubkey,pName,&cb,0,pClass,&dwClass,lpftLastWrite)==ERROR_SUCCESS;
		if (bRet)
		{
			MultiByteToWideChar(CP_ACP,0,pName,cb,lpszName,cchName);
					
			if (pClass!=NULL)
				MultiByteToWideChar(CP_ACP,0,pClass,dwClass,lpszClass,*lpcchClass);
		}
		delete[] pName;
		if (pClass!=NULL)
			delete[] pClass;			
			
		return bRet;
	}

}
int CTargetWnd::GetText(CStringW& str) const
{
	if (IsUnicodeSystem())
	{
		int len=(int)::SendMessageW(m_hWnd,WM_GETTEXTLENGTH,0,0)+2;
		LPWSTR text=new WCHAR[len];
		if (text==NULL)
		{
			SetHFCError(HFC_CANNOTALLOC);
			return FALSE;
		}
		len=(int)::SendMessageW(m_hWnd,WM_GETTEXT,(WPARAM)len,(LPARAM)text);
		str.Copy(text,len);
		delete[] text;
		return len;
	}
	
	int len=(int)::SendMessage(m_hWnd,WM_GETTEXTLENGTH,0,0)+2;
	LPSTR text=new CHAR[len];
	if (text==NULL)
	{
		SetHFCError(HFC_CANNOTALLOC);
		return FALSE;
	}
	len=(int)::SendMessageA(m_hWnd,WM_GETTEXT,(WPARAM)len,(LPARAM)text); 
	str.Copy(text,len);
	delete[] text;
	return len;
}
BOOL CRegKey::EnumKey(DWORD iSubkey,CStringW& strName,LPWSTR lpszClass,LPDWORD lpcchClass,PFILETIME lpftLastWrite) const
{
	if (IsUnicodeSystem())
	{
		DWORD cb=100,cb2=cb;
		LONG ret=::RegEnumKeyExW(m_hKey,iSubkey,strName.GetBuffer(cb/2),&cb2,0,lpszClass,lpcchClass,lpftLastWrite);
		while (ret==ERROR_MORE_DATA)
		{
			cb+=100;
			cb2=cb;
			ret=::RegEnumKeyExW(m_hKey,iSubkey,strName.GetBuffer(cb/2),&cb2,0,lpszClass,lpcchClass,lpftLastWrite);
		}

		if (ret==ERROR_SUCCESS)
		{
			strName.FreeExtra(cb2);
			return TRUE;
		}
		return FALSE;
	}
	else
	{
		DWORD cb=100,cb2=cb;
		char* pClass=NULL;
		DWORD dwClass=0;
		if (lpszClass!=NULL)
		{
			pClass=new char[*lpcchClass+2];
			dwClass=*lpcchClass;
		}
		
		char* pName=new char[cb];
		
		LONG ret=::RegEnumKeyEx(m_hKey,iSubkey,pName,&cb2,0,pClass,&dwClass,lpftLastWrite);
		while (ret==ERROR_MORE_DATA)
		{
			cb+=100;
			cb2=cb;
			delete[] pName;
			pName=new char[cb];
			ret=::RegEnumKeyEx(m_hKey,iSubkey,pName,&cb2,0,pClass,&dwClass,lpftLastWrite);
		}
		
		if (ret!=ERROR_SUCCESS)
		{
			delete[] pName;
			if (pClass!=NULL)
				delete[] pClass;			
			return FALSE;
		}

		strName=pName;
		if (pClass!=NULL)
		{
			MultiByteToWideChar(CP_ACP,0,pClass,dwClass,lpszClass,*lpcchClass);
			delete[] pClass;			
		}
		return TRUE;
	}
}
int CWnd::ShowErrorMessage(UINT nIDMsgStr,UINT nIDTitleStr,UINT uType) const
{
	if (IsUnicodeSystem())
	{
		WCHAR title[100];
		WCHAR msg[1000];
		LoadStringW(GetLanguageSpecificResourceHandle(),nIDMsgStr,msg,1000);
		if (nIDTitleStr)
			LoadStringW(GetLanguageSpecificResourceHandle(),nIDTitleStr,title,100);
		else
			StringCbCopyW(title,100*2,szwError);
		return ::MessageBoxW(m_hWnd,msg,title,uType);
	}
	else
	{
		char title[100];
		char msg[1000];
		LoadString(nIDMsgStr,msg,1000);
		if (nIDTitleStr)
			LoadString(nIDTitleStr,title,100);
		else
			StringCbCopy(title,100,szError);
		return ::MessageBox(m_hWnd,msg,title,uType);
	}
}
CStringW CComboBoxEx::GetItemTextW(int nItem) const
{
	if (IsUnicodeSystem())
	{
		COMBOBOXEXITEMW ce;
		WCHAR szBuffer[2000];
		ce.iItem=nItem;
		ce.cchTextMax=2000;
		ce.pszText=szBuffer;
		ce.mask=CBEIF_TEXT;
		if (::SendMessageW(CCommonCtrl::m_hWnd,CBEM_GETITEMW,0,(LPARAM)&ce))
			return CStringW(szBuffer);
	}
	else
	{
		COMBOBOXEXITEM ce;
		char szBuffer[2000];
		ce.iItem=nItem;
		ce.cchTextMax=2000;
		ce.pszText=szBuffer;
		ce.mask=CBEIF_TEXT;
		if (::SendMessageA(CCommonCtrl::m_hWnd,CBEM_GETITEMA,0,(LPARAM)&ce))
			return CStringW(szBuffer);
	}
	return CStringW();
}
void CToolTipCtrl::UpdateTipText(UINT nIDText,HWND hWnd,UINT nIDTool)
{
	if (IsUnicodeSystem())
	{
		TOOLINFOW ti;
		ti.cbSize=TTTOOLINFOW_V1_SIZE;
		ti.uFlags=TTF_SUBCLASS;
		ti.hwnd=hWnd;
		ti.uId=nIDTool;
		ti.hinst=GetLanguageSpecificResourceHandle();
		ti.lpszText=MAKEINTRESOURCEW(nIDText);
		::SendMessageW(m_hWnd,TTM_UPDATETIPTEXTW,0,(LPARAM)&ti);
	}
	else
	{
		TOOLINFO ti;
		ti.cbSize=TTTOOLINFOA_V1_SIZE;
		ti.uFlags=TTF_SUBCLASS;
		ti.hwnd=hWnd;
		ti.uId=nIDTool;
		ti.hinst=GetLanguageSpecificResourceHandle();
		ti.lpszText=MAKEINTRESOURCE(nIDText);
		::SendMessage(m_hWnd,TTM_UPDATETIPTEXT,0,(LPARAM)&ti);
	}
}
int CComboBoxEx::GetItemText(int nItem,LPWSTR lpszText,int nLen) const
{
	if (IsUnicodeSystem())
	{
		COMBOBOXEXITEMW ce;
		ce.iItem=nItem;
		ce.cchTextMax=nLen;
		ce.pszText=lpszText;
		ce.mask=CBEIF_TEXT;
		return (int)::SendMessageW(CCommonCtrl::m_hWnd,CBEM_GETITEMW,0,(LPARAM)&ce);
	}
	else
	{
		COMBOBOXEXITEM ce;
		ce.iItem=nItem;
		ce.cchTextMax=nLen;
		ce.pszText=new char[nLen+1];
		ce.mask=CBEIF_TEXT;
		int nRet=(int)::SendMessageA(CCommonCtrl::m_hWnd,CBEM_GETITEMA,0,(LPARAM)&ce);

		if (nRet)
			MultiByteToWideChar(CP_ACP,0,ce.pszText,-1,lpszText,nLen);
		delete[] ce.pszText;
		return nRet;
	}
}
BOOL CRegKey::SetValue(LPCWSTR lpValueName,CStringW& strData)
{
	if (IsUnicodeSystem())
		return ::RegSetValueExW(m_hKey,lpValueName,0,REG_SZ,(CONST BYTE*)(LPCWSTR)strData,(DWORD)(strData.GetLength()+1)*2)==ERROR_SUCCESS;
	else
		return ::RegSetValueExA(m_hKey,W2A(lpValueName),0,REG_SZ,(CONST BYTE*)(LPCSTR)W2A(strData),(DWORD)strData.GetLength()+1)==ERROR_SUCCESS;
}
Exemple #10
0
LPWSTR CSubAction::GetPathFromExplorer()
{
	if (!IsUnicodeSystem())
	{
		// Global shortcuts won't even work in non-unicode systems
		return NULL;
	}

	HWND hCurWindow=GetForegroundWindow();
	char szClass[100]="";
	GetClassName(hCurWindow,szClass,100);
	
	if (strcmp(szClass,"ExploreWClass")!=0  && // WinXP
		strcmp(szClass,"CabinetWClass")!=0)  // WinNT
		return NULL;
	
	WCHAR* pPath=new WCHAR[MAX_PATH];
	pPath[0]='\0';
	EnumChildWindows(hCurWindow,EnumExplorerChilds,(LPARAM)pPath);

	if (pPath[0]=='\0')
	{
		delete[] pPath;
		return NULL;
	}
	return pPath;
}
Exemple #11
0
HWND CWnd::HtmlHelp(UINT uCommand,DWORD_PTR dwData,LPCWSTR szHelpFile)
{
	if (szHelpFile==NULL)
		szHelpFile=GetApp()->m_szHelpFile;

	if (szHelpFile!=NULL)
	{	
		if (FirstCharIndex(szHelpFile,L'\\')!=-1)
		{
			if (IsUnicodeSystem())
				return HtmlHelpW(m_hWnd,szHelpFile,uCommand,dwData);
			else
				return HtmlHelpA(m_hWnd,W2A(szHelpFile),uCommand,dwData);
		}



		// Insert path
		if (IsUnicodeSystem())
		{
			CStringW sExeName=GetApp()->GetExeNameW();
			return HtmlHelpW(*this,sExeName.Left(sExeName.FindLast(L'\\')+1)+szHelpFile,
				uCommand,dwData);
		}
	
		CString sExeName=GetApp()->GetExeName();
		return HtmlHelpA(*this,sExeName.Left(sExeName.FindLast(L'\\')+1)+szHelpFile,
			uCommand,dwData);
	}



	if (IsUnicodeSystem())
	{
		CStringW sExeName=GetApp()->GetExeNameW();
		return HtmlHelpW(*this,sExeName.Left(sExeName.FindLast(L'.')+1)+L"chm",
			uCommand,dwData);
	}

	CString sExeName=GetApp()->GetExeName();
	return HtmlHelpA(*this,sExeName.Left(sExeName.FindLast(L'.')+1)+"chm",
		uCommand,dwData);
}
Exemple #12
0
LRESULT CTargetWnd::WindowProc(UINT msg,WPARAM wParam,LPARAM lParam)
{
#ifdef _DEBUG
	void DebugCommandsProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam);
	DebugCommandsProc(*this,msg,wParam,lParam);
#endif
	if (IsUnicodeSystem())
		return DefWindowProcW(m_hWnd,msg,wParam,lParam);
	else
		return DefWindowProcA(m_hWnd,msg,wParam,lParam);
}
int CStatusBarCtrl::GetTipText(int n,LPWSTR szText,int nBufLen) const
{
	if (IsUnicodeSystem())
		return (int)::SendMessageW(m_hWnd,SB_GETTIPTEXTW,MAKEWPARAM(n,nBufLen),(LPARAM)szText);
	
	char* pText=new char[nBufLen+2];
	int ret=(int)::SendMessageW(m_hWnd,SB_GETTIPTEXTW,MAKEWPARAM(n,nBufLen),(LPARAM)pText);
	if (ret)
		MultiByteToWideChar(CP_ACP,0,pText,-1,szText,(int)nBufLen);
	delete[] pText;
	return ret;
}
Exemple #14
0
BOOL ShellFunctions::RunRegistryCommand(HKEY hKey,LPCWSTR szFile)
{
	if (!IsUnicodeSystem())
		return RunRegistryCommand(hKey,W2A(szFile));


	PROCESS_INFORMATION pi;
	STARTUPINFOW si;
	CRegKey CommandKey;
	CStringW ExecuteStr;
	CStringW CommandLine;
	int i;

	if (CommandKey.OpenKey(hKey,"command",CRegKey::openExist|CRegKey::samAll)!=ERROR_SUCCESS)
		return FALSE;
	if (CommandKey.QueryValue(L"",ExecuteStr)<2)
		return FALSE;
	i=ExecuteStr.FindFirst(L'%');
	while (i!=-1)
	{
		if (ExecuteStr[i+1]==L'1')
		{
			CommandLine.Copy(ExecuteStr,i);
			CommandLine<<szFile;
			CommandLine<<((LPCWSTR)ExecuteStr+i+2);
			break;
		}
		i=ExecuteStr.FindNext(L'%',i);
	}
	if (i==-1)
		CommandLine=ExecuteStr;
	if (!ExpandEnvironmentStringsW(CommandLine,ExecuteStr.GetBuffer(1000),1000))
		ExecuteStr.Swap(CommandLine);
	si.cb=sizeof(STARTUPINFOW);
	si.lpReserved=NULL;
	si.cbReserved2=0;
	si.lpReserved2=NULL;
	si.lpDesktop=NULL;
	si.lpTitle=NULL;
	si.dwFlags=STARTF_USESHOWWINDOW;
	si.wShowWindow=SW_SHOWDEFAULT;
	if (!CreateProcessW(NULL,ExecuteStr.GetBuffer(),NULL,
		NULL,FALSE,CREATE_DEFAULT_ERROR_MODE|NORMAL_PRIORITY_CLASS,
		NULL,NULL,&si,&pi))
	{
		CommandKey.CloseKey();
		return FALSE;
	}
	CloseHandle(pi.hThread);
	CloseHandle(pi.hProcess);
	CommandKey.CloseKey();
	return TRUE;
}
int LoadString(UINT uID,LPWSTR lpBuffer,int nBufferMax,TypeOfResourceHandle bType)
{
	if (!IsUnicodeSystem())
	{
		char* pStr=new char[nBufferMax+1];
		int nRet=::LoadStringA(GetResourceHandle(bType),uID,pStr,nBufferMax);
		MultiByteToWideChar(CP_ACP,0,pStr,nRet+1,lpBuffer,nBufferMax);
		delete[] pStr;
		return nRet;
	}
	return (int)::LoadStringW(GetResourceHandle(bType),uID,lpBuffer,nBufferMax);
}
int LoadString(UINT uID,LPWSTR lpBuffer,int nBufferMax,HINSTANCE hInstance)
{
	if (!IsUnicodeSystem())
	{
		char* pStr=new char[nBufferMax+1];
		int nRet=::LoadStringA(hInstance,uID,pStr,nBufferMax);
		MultiByteToWideChar(CP_ACP,0,pStr,nRet+1,lpBuffer,nBufferMax);
		delete[] pStr;
		return nRet;
	}
	return (int)::LoadStringW(hInstance,uID,lpBuffer,nBufferMax);
}
LONG CRegKey::SetValue(LPCWSTR lpValueName,LPCWSTR strData)
{
	if (IsUnicodeSystem())
		return ::RegSetValueExW(m_hKey,lpValueName,0,REG_SZ,(CONST BYTE*)strData,(DWORD)((wcslen(strData)+1)*2));
	else
	{
		int nLen=istrlenw(strData);
		LPSTR aData=new char[nLen+2];
		WideCharToMultiByte(CP_ACP,0,strData,nLen+1,aData,nLen+1,NULL,NULL);
		LONG lRet=::RegSetValueExA(m_hKey,W2A(lpValueName),0,REG_SZ,(CONST BYTE*)aData,nLen+1);
		delete[] aData;
		return lRet;
	}
}
LONG CRegKey::OpenKey(HKEY hKey,LPCWSTR lpszSubKey,DWORD fStatus,LPSECURITY_ATTRIBUTES lpSecurityAttributes)
{
	if (!IsUnicodeSystem())
		return OpenKey(hKey,W2A(lpszSubKey),fStatus,lpSecurityAttributes);

	REGSAM  samDesired=0;
	DWORD  fdwOptions;
	LONG ret;
	if (m_hKey!=NULL)
	{
		RegCloseKey(m_hKey);
		DebugCloseHandle(dhtRegKey,&m_hKey,lpszSubKey);
	}
	if (fStatus==samAll)
		samDesired=KEY_ALL_ACCESS;
	else
	{
		if (fStatus&samCreateLink)
			samDesired|=KEY_CREATE_LINK;
		if (fStatus&samCreateSubkey)
			samDesired|=KEY_CREATE_SUB_KEY;
		if (fStatus&samEnumerateSubkeys)
			samDesired|=KEY_ENUMERATE_SUB_KEYS;
		if (fStatus&samExecute)
			samDesired|=KEY_EXECUTE;
		if (fStatus&samNotify)
			samDesired|=KEY_NOTIFY;
		if (fStatus&samQueryValue)
			samDesired|=KEY_QUERY_VALUE;
		if (fStatus&samSetValue)
			samDesired|=KEY_SET_VALUE;
	}
	if (fStatus&optionVolatile)
		fdwOptions=REG_OPTION_VOLATILE;
	else
		fdwOptions=REG_OPTION_NON_VOLATILE;
	if (fStatus&openExist)
		ret=RegOpenKeyExW(hKey,lpszSubKey,0,samDesired,&m_hKey);
	else
	{
		DWORD type;
		ret=RegCreateKeyExW(hKey,lpszSubKey,0,NULL,fdwOptions,samDesired,lpSecurityAttributes,&m_hKey,&type); 
	}
	if (ret!=ERROR_SUCCESS)
		m_hKey=NULL;
	else
		DebugOpenHandle(dhtRegKey,m_hKey,lpszSubKey);
	return ret;
}
BOOL CToolTipCtrl::AddTool(HWND hWnd,UINT nIDText,LPCRECT lpRectTool,UINT nIDTool,LPARAM lParam)
{
	if (IsUnicodeSystem())
	{
		TOOLINFOW ti;
		ti.cbSize=TTTOOLINFOW_V2_SIZE;
		ti.uFlags=TTF_SUBCLASS;
		ti.hwnd=hWnd;
		ti.uId=nIDTool;
		ti.hinst=GetLanguageSpecificResourceHandle();
		ti.lpszText=MAKEINTRESOURCEW(nIDText);
		ti.lParam=lParam;	
		if (lpRectTool!=NULL)
			ti.rect=*lpRectTool;
		else if (hWnd!=NULL)
			::GetClientRect(hWnd,&ti.rect);
		else
		{
			ti.rect.left=0;
			ti.rect.right=0;
			ti.rect.top=0;
			ti.rect.bottom=0;
		}
		return (BOOL)::SendMessageW(m_hWnd,TTM_ADDTOOLW,0,(LPARAM)&ti);
	}
	else
	{
		TOOLINFO ti;
		ti.cbSize=TTTOOLINFOA_V2_SIZE;
		ti.uFlags=TTF_SUBCLASS;
		ti.hwnd=hWnd;
		ti.uId=nIDTool;
		ti.hinst=GetLanguageSpecificResourceHandle();
		ti.lpszText=MAKEINTRESOURCE(nIDText);
		ti.lParam=lParam;	
		if (lpRectTool!=NULL)
			ti.rect=*lpRectTool;
		else if (hWnd!=NULL)
			::GetClientRect(hWnd,&ti.rect);
		else
		{
			ti.rect.left=0;
			ti.rect.right=0;
			ti.rect.top=0;
			ti.rect.bottom=0;
		}
		return (BOOL)::SendMessage(m_hWnd,TTM_ADDTOOL,0,(LPARAM)&ti);
	}
}
Exemple #20
0
UINT CWnd::GetDlgItemText(int nIDDlgItem,CStringW& str)
{
	HWND hCtrl=::GetDlgItem(m_hWnd,nIDDlgItem);
	UINT len=(UINT)::SendMessage(hCtrl,WM_GETTEXTLENGTH,0,0);
	
	if (IsUnicodeSystem())
		return ::GetWindowTextW(hCtrl,str.GetBuffer(len),len+1);


	char* pText=new char[len+2];
	::GetWindowTextA(hCtrl,pText,len+1);
	str.Copy(pText,len);
	delete[] pText;
	return len;
}
Exemple #21
0
int CWnd::GetClassName(LPWSTR lpString,int nMaxCount) const
{
	if (IsUnicodeSystem())
		return ::GetClassNameW(m_hWnd,lpString,(int)nMaxCount); 

	char* pText=new char[nMaxCount+2];
	int ret=::GetClassNameA(m_hWnd,pText,(INT)nMaxCount);
	if (ret!=0)
	{
		MultiByteToWideChar(CP_ACP,0,pText,(int)ret,lpString,(int)nMaxCount);
		lpString[ret]=L'\0';
	}
	delete pText;
	return ret;
}
Exemple #22
0
HRESULT ShellFunctions::GetShortcutTarget(LPCWSTR pszShortcutFile,LPWSTR pszTarget,DWORD nBufSize)
{
	HRESULT hres;
	if (IsUnicodeSystem())
	{
		IShellLinkW* psl;
		WIN32_FIND_DATAW wfd;

		hres=CoCreateInstance(CLSID_ShellLink,NULL,CLSCTX_INPROC_SERVER,IID_IShellLinkW,(void**)&psl);
		if (SUCCEEDED(hres))
		{
			IPersistFile* ppf;
			hres=psl->QueryInterface(IID_IPersistFile,(void**)&ppf);
			if (SUCCEEDED(hres))
			{
				hres=ppf->Load(pszShortcutFile,STGM_READ);
				if (SUCCEEDED(hres))
					hres=psl->GetPath(pszTarget,nBufSize,(WIN32_FIND_DATAW*)&wfd,0);
				ppf->Release();
			}
			psl->Release();  
		}
	}
	else
	{
		IShellLinkA* psl;
		WIN32_FIND_DATA wfd;

		hres=CoCreateInstance(CLSID_ShellLink,NULL,CLSCTX_INPROC_SERVER,IID_IShellLinkA,(void**)&psl);
		if (SUCCEEDED(hres))
		{
			IPersistFile* ppf;
			hres=psl->QueryInterface(IID_IPersistFile,(void**)&ppf);
			if (SUCCEEDED(hres))
			{
				char* pTargetTmp=new char[nBufSize+2];
				hres=ppf->Load(pszShortcutFile,STGM_READ);
				if (SUCCEEDED(hres))
					hres=psl->GetPath(pTargetTmp,nBufSize,(WIN32_FIND_DATA*)&wfd,0);
				MultiByteToWideChar(CP_ACP,0,pTargetTmp,-1,pszTarget,nBufSize);
				delete[] pTargetTmp;
				ppf->Release();
			}
			psl->Release();  
		}
	}
	return hres;
}
Exemple #23
0
int CWnd::GetWindowText(CStringW& str) const
{
	if (IsUnicodeSystem())
	{
		int len=::GetWindowTextLengthW(m_hWnd);
		len=::GetWindowTextW(m_hWnd,str.GetBuffer(len),len+1);
		return len;
	}

	int len=::GetWindowTextLength(m_hWnd);
	char* pText=new char[len+2];
	::GetWindowTextA(m_hWnd,pText,len+1);
	str.Copy(pText,len);
	delete[] pText;
	return len;	
}
BOOL CTabCtrl::InsertItem(int nItem,TC_ITEMW* pTabCtrlItem)
{
	if (IsUnicodeSystem())
		return (BOOL)::SendMessageW(m_hWnd,TCM_INSERTITEMW,(WPARAM)nItem,(LPARAM)pTabCtrlItem);
	else if (pTabCtrlItem->mask&TCIF_TEXT && pTabCtrlItem->pszText!=NULL)
	{
		WCHAR* pText=pTabCtrlItem->pszText;
		pTabCtrlItem->pszText=(WCHAR*)alloccopyWtoA(pText);
		BOOL bRet=(BOOL)::SendMessageA(m_hWnd,TCM_INSERTITEMA,(WPARAM)nItem,(LPARAM)pTabCtrlItem);
		delete[] pTabCtrlItem->pszText;
		pTabCtrlItem->pszText=pText;
		return bRet;
	}
	else
		return (BOOL)::SendMessageA(m_hWnd,TCM_INSERTITEMA,(WPARAM)nItem,(LPARAM)pTabCtrlItem);
}
inline DWORD CRegKey::EnumValue(DWORD iValue,LPWSTR lpszValue,DWORD cchValue,LPDWORD lpdwType,LPBYTE lpbData,LPDWORD lpcbData) const
{
	if (IsUnicodeSystem())
		return ::RegEnumValueW(m_hKey,iValue,lpszValue,&cchValue,0,lpdwType,lpbData,lpcbData)==ERROR_SUCCESS?cchValue+1:0;
	else
	{
		char* pValue=new char[cchValue+2];
		DWORD cb=cchValue;
		BOOL bRet=::RegEnumValueW(m_hKey,iValue,lpszValue,&cb,0,lpdwType,lpbData,lpcbData)==ERROR_SUCCESS;
		if (bRet)
			MultiByteToWideChar(CP_ACP,0,pValue,cb,lpszValue,cchValue);
		
		delete[] pValue;
		return bRet;		
	}
}
Exemple #26
0
int CTargetWnd::GetText(LPWSTR lpszText,int cchTextMax) const
{
	if (IsUnicodeSystem())
		return (int)::SendMessageW(m_hWnd,WM_GETTEXT,cchTextMax*2,(LPARAM)lpszText); 

	int nLen=(int)::SendMessageA(m_hWnd,WM_GETTEXTLENGTH,0,0);
	char* pText=new char[nLen+2];
	int ret=(int)::SendMessageA(m_hWnd,WM_GETTEXT,(nLen+2)*2,(LPARAM)pText);
	if (ret!=0)
	{
		MultiByteToWideChar(CP_ACP,0,pText,(int)ret,lpszText,(int)cchTextMax);
		lpszText[ret]=L'\0';
	}
	delete pText;
	return ret;
}
Exemple #27
0
int ShellFunctions::ShellExecute(HWND hwnd,LPCWSTR lpOperation,LPCWSTR lpFile,LPCWSTR lpParameters,LPCWSTR lpDirectory,INT nShowCmd)
{
	if (lpOperation!=NULL)
	{
		if (lpOperation[0]=='\0')
			lpOperation=NULL;
	}

	if (IsUnicodeSystem())
		return (int)::ShellExecuteW(hwnd,lpOperation,lpFile,lpParameters,lpDirectory,nShowCmd);
	else
	{
		return (int)::ShellExecuteA(hwnd,(LPCSTR)W2A(lpOperation),(LPCSTR)W2A(lpFile),
			(LPCSTR)W2A(lpParameters),(LPCSTR)W2A(lpDirectory),
			nShowCmd);
	}
}
Exemple #28
0
void CShortcut::SendEventBackToControl()
{
#ifndef KEYHOOK_EXPORTS
	CWinThread* pThread=GetTrayIconWnd()->GetLocateDlgThread();
	if (pThread!=NULL)
	{
		const MSG* pMsg=pThread->GetCurrentMessage();
		ASSERT(pMsg!=NULL);

		TranslateMessage(pMsg);
		if (IsUnicodeSystem())
			DispatchMessageW(pMsg);
		else
			DispatchMessageA(pMsg);
	}
#endif
}
Exemple #29
0
UINT CWnd::GetDlgItemText(int nIDDlgItem,LPWSTR lpString,int nMaxCount) const
{
	if (IsUnicodeSystem())
		return ::GetDlgItemTextW(m_hWnd,nIDDlgItem,lpString,nMaxCount); 

	char* pText=new char[nMaxCount+2];
	int ret=::GetDlgItemTextA(m_hWnd,nIDDlgItem,pText,nMaxCount);
	if (ret!=0)
	{
		MultiByteToWideChar(CP_ACP,0,pText,ret,lpString,nMaxCount);
		lpString[ret]=L'\0';
	}
	else
		lpString[0]=L'\0';
	delete pText;
	return ret;
}
Exemple #30
0
int ShellFunctions::FileOperation(LPSHFILEOPSTRUCTW lpFileOp)
{
	if (IsUnicodeSystem())
		return ::SHFileOperationW(lpFileOp);

	LPCWSTR pFrom=lpFileOp->pFrom;
	LPCWSTR pTo=lpFileOp->pTo;
	LPCWSTR pProgressTitle=lpFileOp->fFlags&FOF_SIMPLEPROGRESS?lpFileOp->lpszProgressTitle:NULL;

	if (pFrom!=NULL)
		lpFileOp->pFrom=(LPCWSTR)alloccopymultiWtoA(pFrom);

	if (pTo!=NULL)
	{
		if (lpFileOp->fFlags&FOF_MULTIDESTFILES)
			lpFileOp->pTo=(LPCWSTR)alloccopymultiWtoA(pTo);
		else
			lpFileOp->pTo=(LPCWSTR)alloccopyWtoA(pTo,istrlenw(pTo)+1);
	}

	if (pProgressTitle!=NULL)
		lpFileOp->lpszProgressTitle=(LPCWSTR)alloccopyWtoA(pProgressTitle);

	int nRet=::SHFileOperationA((LPSHFILEOPSTRUCTA)lpFileOp);
	
	if (pFrom!=NULL)
	{
		delete[] (LPSTR)lpFileOp->pFrom;
		lpFileOp->pFrom=pFrom;
	}

	if (pTo!=NULL)
	{
		delete[] (LPSTR)lpFileOp->pTo;
		lpFileOp->pTo=pTo;
	}

	if (pProgressTitle!=NULL)
	{
		delete[] (LPSTR)lpFileOp->lpszProgressTitle;
		lpFileOp->lpszProgressTitle=pProgressTitle;
	}

	return nRet;
}