本文整理汇总了C++中StringCchCopy函数的典型用法代码示例。如果您正苦于以下问题:C++ StringCchCopy函数的具体用法?C++ StringCchCopy怎么用?C++ StringCchCopy使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了StringCchCopy函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GoProcessing
int GoProcessing(const tagCMDL & cmdl)
{
int mode = cmdl.mode;
CreateDirectory(cmdl.temppath, NULL);
wchar_t tempfile[MAX_PATH];
if( lstrlen(cmdl.temppath) == 0 )
{
// кодируем в файл по умолчанию
StringCchCopy(tempfile, MAX_PATH, cmdl.outputfilename);
}else
{
StringCchCopy(tempfile, MAX_PATH, cmdl.temppath);
if( tempfile[ lstrlen(tempfile) -1 ] != L'\\')
StringCchCat(tempfile, MAX_PATH, L"\\");
StringCchCat(tempfile, MAX_PATH, PathFindFileName(cmdl.outputfilename));
}
HWND fwwnd = FindWindow(wndclassnameW, NULL);
if(fwwnd == NULL) return 4;
int pos = -1;
while( pos < 0 )
{
if( !isProcessExist() ) // проверяем мьютекс
return 0; // преждевременный выход
pos = (int)SendMessage(fwwnd, MES_ONNEWTHREAD, 0, 0);
if( pos >= 0 ) break;
Sleep(200);
}
//////////////////////////////////////////////////////////////////////////
// название файла
if( !SendFileName(fwwnd, cmdl.outputfilename, pos) )
return 0; // выход, лажа.
//////////////////////////////////////////////////////////////////////////
// читаем файл из stdin и создаём временный wav-файл
if( !ReadAndCreateFile(tempfile) )
return 5;
DWORD len = CorrectHeader(tempfile);
//////////////////////////////////////////////////////////////////////////
// сообщаем длинну трэка: sec * 4 * 44100
if( !MySendMessage(fwwnd, MES_SENDLENGTH, pos, len) )
{
DeleteFile(tempfile);
return 0;
}
if( len )
{
UINT newpriority = (UINT)SendMessage(fwwnd, MES_GETPRIORITY, 0, 0);
SetPriorityClass(GetCurrentProcess(), newpriority );
if( !RunProcessing(tempfile, mode, fwwnd, pos) )
{
DeleteFile(tempfile);
return 0; // пытаемся безболезненно свалить :D
}
}
DeleteFile(tempfile);
if( !TrimFile(cmdl.outputfilename, pos) )
return 6;
return 0;
}
示例2: lock
void DirectoryListingService::updateEntries() {
ScopeLock lock(_mutex);
// stat directory for modification date
struct stat dirStat;
if (stat(_dir.c_str(), &dirStat) != 0) {
UM_LOG_ERR("Error with stat on directory '%s': %s", _dir.c_str(), strerror(errno));
return;
}
if ((unsigned)dirStat.st_mtime >= (unsigned)_lastChecked) {
// there are changes in the directory
set<string> currEntries;
#ifndef WIN32
DIR *dp;
dp = opendir(_dir.c_str());
if (dp == NULL) {
UM_LOG_ERR("Error opening directory '%s': %s", _dir.c_str(), strerror(errno));
return;
}
// iterate all entries and see what changed
struct dirent* entry;
while((entry = readdir(dp))) {
string dname = entry->d_name;
#else
WIN32_FIND_DATA ffd;
HANDLE hFind = INVALID_HANDLE_VALUE;
TCHAR szDir[MAX_PATH];
StringCchCopy(szDir, MAX_PATH, _dir.c_str());
StringCchCat(szDir, MAX_PATH, TEXT("\\*"));
hFind = FindFirstFile(szDir, &ffd);
do {
string dname = ffd.cFileName;
#endif
// see if the file was changed
char* filename;
asprintf(&filename, "%s/%s", _dir.c_str(), dname.c_str());
struct stat fileStat;
if (stat(filename, &fileStat) != 0) {
UM_LOG_ERR("Error with stat on directory entry '%s': %s", filename, strerror(errno));
free(filename);
continue;
}
if (fileStat.st_mode & S_IFDIR) {
// ignore directories
free(filename);
continue;
}
// are we interested in such a file?
if (!filter(dname)) {
free(filename);
continue;
}
currEntries.insert(dname);
if (_knownEntries.find(dname) != _knownEntries.end()) {
// we have seen this entry before
struct stat oldStat = _knownEntries[dname];
if (oldStat.st_mtime < fileStat.st_mtime) {
notifyModifiedFile(dname, fileStat);
}
} else {
// we have not yet seen this entry
notifyNewFile(dname, fileStat);
}
free(filename);
_knownEntries[dname] = fileStat; // gets copied on insertion
#ifndef WIN32
}
closedir(dp);
#else
}
while (FindNextFile(hFind, &ffd) != 0);
FindClose(hFind);
#endif
// are there any known entries we have not seen this time around?
map<string, struct stat>::iterator fileIter = _knownEntries.begin();
while(fileIter != _knownEntries.end()) {
if (currEntries.find(fileIter->first) == currEntries.end()) {
// we used to know this file
notifyRemovedFile(fileIter->first, fileIter->second);
_knownEntries.erase(fileIter->first);
}
fileIter++;
}
// remember when we last checked the directory for modifications
#ifndef WIN32
time(&_lastChecked);
#else
// TODO: this will fail with subsecond updates to the directory
_lastChecked = dirStat.st_mtime + 1;
#endif
}
示例3: ClipboardDataGet
/*!
クリップボードのデータをいただく・同じモノが、DocInsDelCtrl.cpp にある
@param[in] pVoid 特になし
@return 確保した文字列・mallocしてるので、函数呼んだ方でfree忘れないように
*/
LPTSTR ClipboardDataGet( LPVOID pVoid )
{
LPTSTR ptString = NULL, ptClipTxt;
LPSTR pcStr, pcClipTp; // 変換用臨時
DWORD cbSize;
UINT dEnumFmt;
INT ixCount, iC;
HANDLE hClipData;
// クリップボードの中身をチェキ・どっちにしてもユニコードテキストフラグはある
if( IsClipboardFormatAvailable( CF_UNICODETEXT ) )
{
OpenClipboard( NULL ); // クリップボードをオーポンする
// 開けっ放しだと他のアプリに迷惑なのですぐ閉めるように
dEnumFmt = 0; // 初期値は0
ixCount = CountClipboardFormats( );
for( iC = 0; ixCount > iC; iC++ )
{ // 順番に列挙して、先にヒットしたフォーマットで扱う
dEnumFmt = EnumClipboardFormats( dEnumFmt );
if( CF_UNICODETEXT == dEnumFmt || CF_TEXT == dEnumFmt ){ break; }
}
if( 0 == dEnumFmt ){ return NULL; }
// それ以上列挙が無いか、函数失敗なら0になる
// クリップボードのデータをゲッツ!
// ハンドルのオーナーはクリップボードなので、こちらからは操作しないように
// 中身の変更などもってのほかである
hClipData = GetClipboardData( dEnumFmt );
if( CF_UNICODETEXT == dEnumFmt )
{
// 取得データを処理。TEXTなら、ハンドルはグローバルメモリハンドル
// 新たにコピーされたらハンドルは無効になるので、中身をコピーせよ
ptClipTxt = (LPTSTR)GlobalLock( hClipData );
cbSize = GlobalSize( (HGLOBAL)hClipData );
// 確保出来るのはバイトサイズ・テキストだと末尾のNULLターミネータ含む
if( 0 < cbSize )
{
ptString = (LPTSTR)malloc( cbSize );
StringCchCopy( ptString, (cbSize / 2), ptClipTxt );
}
}
else // 非ユニコードが優先されている場合
{
pcClipTp = (LPSTR)GlobalLock( hClipData );
cbSize = GlobalSize( (HGLOBAL)hClipData );
if( 0 < cbSize )
{
pcStr = (LPSTR)malloc( cbSize );
StringCchCopyA( pcStr, cbSize, pcClipTp );
ptString = SjisDecodeAlloc( pcStr ); // SJISの内容をユニコードにする
free( pcStr );
}
}
// 使い終わったら閉じておく
GlobalUnlock( hClipData );
CloseClipboard( );
}
return ptString;
}
示例4: xnUSBOpenEndPoint
//.........这里部分代码省略.........
{
XN_ALIGNED_FREE_AND_NULL(pEPHandle);
return (XN_STATUS_USB_WRONG_ENDPOINT_TYPE);
}
}
else
{
XN_ALIGNED_FREE_AND_NULL(pEPHandle);
return (XN_STATUS_USB_UNKNOWN_ENDPOINT_TYPE);
}
// Verify that the EP direction matches the requested direction
if (nDirType == XN_USB_DIRECTION_IN)
{
if (USB_ENDPOINT_DIRECTION_IN(pUSBEndPointDesc->bEndpointAddress) == FALSE)
{
XN_ALIGNED_FREE_AND_NULL(pEPHandle);
return (XN_STATUS_USB_WRONG_ENDPOINT_DIRECTION);
}
}
else if (nDirType == XN_USB_DIRECTION_OUT)
{
if (USB_ENDPOINT_DIRECTION_OUT(pUSBEndPointDesc->bEndpointAddress) == FALSE)
{
XN_ALIGNED_FREE_AND_NULL(pEPHandle);
return (XN_STATUS_USB_WRONG_ENDPOINT_DIRECTION);
}
}
else
{
XN_ALIGNED_FREE_AND_NULL(pEPHandle);
return (XN_STATUS_USB_UNKNOWN_ENDPOINT_DIRECTION);
}
// Construct the pipe file name
pEPHandle->cpPipeName[0] = 0;
cpPipeID[0] = '0';
cpPipeID[1] = '0' + nEPIdx;
cpPipeID[2] = 0;
StringCchCopy(pEPHandle->cpPipeName, MAX_DEVICE_STR_LENGTH, pDevHandle->cpDeviceName);
StringCchCat(pEPHandle->cpPipeName, MAX_DEVICE_STR_LENGTH, PSDRV_PIPE_PREFIX);
StringCchCat(pEPHandle->cpPipeName, MAX_DEVICE_STR_LENGTH, cpPipeID);
// Open the regular pipe handle
pEPHandle->hEPHandle = CreateFile(pEPHandle->cpPipeName, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
if (pEPHandle->hEPHandle == INVALID_HANDLE_VALUE)
{
XN_ALIGNED_FREE_AND_NULL(pEPHandle);
return (XN_STATUS_USB_OPEN_ENDPOINT_FAILED);
}
// Init the overlapped I/O structs
nRetVal = xnUSBInitOvlp(pEPHandle);
if (nRetVal != XN_STATUS_OK)
{
XN_ALIGNED_FREE_AND_NULL(pEPHandle);
return (XN_STATUS_USB_OPEN_ENDPOINT_FAILED);
}
// Init the ThreadData variables
xnOSMemSet(&pEPHandle->ThreadData, 0, sizeof(xnUSBReadThreadData));
pEPHandle->ThreadData.bInUse = FALSE;
// Init the default endpoint properties
pEPHandle->nTimeOut = XN_USB_DEFAULT_EP_TIMEOUT;
pEPHandle->nEPType = nEPType;
pEPHandle->nEPDir = nDirType;
pEPHandle->nEndPointID = nEndPointID;
// Set the default endpoint timeout
nRetVal = xnUSBSetPipeProperty(pEPHandle, PSUSBDRV_PIPE_PROPERTY_TIMEOUT, XN_USB_DEFAULT_EP_TIMEOUT);
if (nRetVal != XN_STATUS_OK)
{
XN_ALIGNED_FREE_AND_NULL(pEPHandle);
return (nRetVal);
}
if (nUBBEPType == USB_ENDPOINT_TYPE_ISOCHRONOUS)
{
// bits 11 and 12 mark the number of additional transactions, bits 0-10 mark the size
XnUInt32 nAdditionalTransactions = pUSBEndPointDesc->wMaxPacketSize >> 11;
XnUInt32 nPacketSize = pUSBEndPointDesc->wMaxPacketSize & 0x7FF;
pEPHandle->nMaxPacketSize = (nAdditionalTransactions + 1) * (nPacketSize);
}
else
{
pEPHandle->nMaxPacketSize = pUSBEndPointDesc->wMaxPacketSize;
}
// Mark the endpoint as valid
pEPHandle->bValid = TRUE;
// The end... (Happy)
return (XN_STATUS_OK);
}
pBuf += pUSBEndPointDesc->bLength;
}
示例5: InvokeCustomAction
/// <summary>
/// Invokes a managed custom action from native code by
/// extracting the package to a temporary working directory
/// then hosting the CLR and locating and calling the entrypoint.
/// </summary>
/// <param name="hSession">Handle to the installation session.
/// Passed to custom action entrypoints by the installer engine.</param>
/// <param name="szWorkingDir">Directory containing the CA binaries
/// and the CustomAction.config file defining the entrypoints.
/// This may be NULL, in which case the current module must have
/// a concatenated cabinet containing those files, which will be
/// extracted to a temporary directory.</param>
/// <param name="szEntryPoint">Name of the CA entrypoint to be invoked.
/// This must be either an explicit "AssemblyName!Namespace.Class.Method"
/// string, or a simple name that maps to a full entrypoint definition
/// in CustomAction.config.</param>
/// <returns>The value returned by the managed custom action method,
/// or ERROR_INSTALL_FAILURE if the CA could not be invoked.</returns>
int InvokeCustomAction(MSIHANDLE hSession,
const wchar_t* szWorkingDir, const wchar_t* szEntryPoint)
{
#ifdef MANAGED_CAs_OUT_OF_PROC
if (!g_fRunningOutOfProc && szWorkingDir == NULL)
{
return InvokeOutOfProcManagedCustomAction(hSession, szEntryPoint);
}
#endif
wchar_t szTempDir[MAX_PATH];
bool fDeleteTemp = false;
if (szWorkingDir == NULL)
{
if (!ExtractToTempDirectory(hSession, g_hModule, szTempDir, MAX_PATH))
{
return ERROR_INSTALL_FAILURE;
}
szWorkingDir = szTempDir;
fDeleteTemp = true;
}
wchar_t szConfigFilePath[MAX_PATH + 20];
StringCchCopy(szConfigFilePath, MAX_PATH + 20, szWorkingDir);
StringCchCat(szConfigFilePath, MAX_PATH + 20, L"\\CustomAction.config");
const wchar_t* szConfigFile = szConfigFilePath;
if (!::PathFileExists(szConfigFilePath))
{
szConfigFile = NULL;
}
wchar_t szWIAssembly[MAX_PATH + 50];
StringCchCopy(szWIAssembly, MAX_PATH + 50, szWorkingDir);
StringCchCat(szWIAssembly, MAX_PATH + 50, L"\\Microsoft.Deployment.WindowsInstaller.dll");
int iResult = ERROR_INSTALL_FAILURE;
ICorRuntimeHost* pHost;
if (LoadCLR(hSession, NULL, szConfigFile, szWIAssembly, &pHost))
{
_AppDomain* pAppDomain;
if (CreateAppDomain(hSession, pHost, L"CustomAction", szWorkingDir,
szConfigFile, &pAppDomain))
{
if (!InvokeManagedCustomAction(hSession, pAppDomain, szEntryPoint, &iResult))
{
iResult = ERROR_INSTALL_FAILURE;
}
HRESULT hr = pHost->UnloadDomain(pAppDomain);
if (FAILED(hr))
{
Log(hSession, L"Failed to unload app domain. Error code 0x%X", hr);
}
pAppDomain->Release();
}
pHost->Stop();
pHost->Release();
}
if (fDeleteTemp)
{
DeleteDirectory(szTempDir);
}
return iResult;
}
示例6: InitializeEmbeddedUI
UINT __stdcall InitializeEmbeddedUI(MSIHANDLE hSession, LPCWSTR szResourcePath, LPDWORD pdwInternalUILevel)
{
// If the managed initialize method cannot be called, continue the installation in BASIC UI mode.
UINT uiResult = INSTALLUILEVEL_BASIC;
const wchar_t* szClassName = L"InitializeEmbeddedUI_FullClassName" NULLSPACE;
g_szWorkingDir = szResourcePath;
wchar_t szModule[MAX_PATH];
DWORD cchCopied = GetModuleFileName(g_hModule, szModule, MAX_PATH - 1);
if (cchCopied == 0)
{
Log(hSession, L"Failed to get module path. Error code %d.", GetLastError());
return uiResult;
}
else if (cchCopied == MAX_PATH - 1)
{
Log(hSession, L"Failed to get module path -- path is too long.");
return uiResult;
}
Log(hSession, L"Extracting embedded UI to temporary directory: %s", g_szWorkingDir);
int err = ExtractCabinet(szModule, g_szWorkingDir);
if (err != 0)
{
Log(hSession, L"Failed to extract to temporary directory. Cabinet error code %d.", err);
Log(hSession, L"Ensure that no MsiEmbeddedUI.FileName values are the same as "
L"any file contained in the embedded UI package.");
return uiResult;
}
wchar_t szConfigFilePath[MAX_PATH + 20];
StringCchCopy(szConfigFilePath, MAX_PATH + 20, g_szWorkingDir);
StringCchCat(szConfigFilePath, MAX_PATH + 20, L"\\EmbeddedUI.config");
const wchar_t* szConfigFile = szConfigFilePath;
if (!PathFileExists(szConfigFilePath))
{
szConfigFile = NULL;
}
wchar_t szWIAssembly[MAX_PATH + 50];
StringCchCopy(szWIAssembly, MAX_PATH + 50, g_szWorkingDir);
StringCchCat(szWIAssembly, MAX_PATH + 50, L"\\Microsoft.Deployment.WindowsInstaller.dll");
if (LoadCLR(hSession, NULL, szConfigFile, szWIAssembly, &g_pClrHost))
{
if (CreateAppDomain(hSession, g_pClrHost, L"EmbeddedUI", g_szWorkingDir,
szConfigFile, &g_pAppDomain))
{
const wchar_t* szMsiAssemblyName = L"Microsoft.Deployment.WindowsInstaller";
const wchar_t* szProxyClass = L"Microsoft.Deployment.WindowsInstaller.EmbeddedUIProxy";
const wchar_t* szInitMethod = L"Initialize";
const wchar_t* szProcessMessageMethod = L"ProcessMessage";
const wchar_t* szShutdownMethod = L"Shutdown";
if (GetMethod(hSession, g_pAppDomain, szMsiAssemblyName,
szProxyClass, szProcessMessageMethod, &g_pProcessMessageMethod) &&
GetMethod(hSession, g_pAppDomain, szMsiAssemblyName,
szProxyClass, szShutdownMethod, &g_pShutdownMethod))
{
_MethodInfo* pInitMethod;
if (GetMethod(hSession, g_pAppDomain, szMsiAssemblyName,
szProxyClass, szInitMethod, &pInitMethod))
{
bool invokeSuccess = InvokeInitializeMethod(pInitMethod, hSession, szClassName, pdwInternalUILevel, &uiResult);
pInitMethod->Release();
if (invokeSuccess)
{
if (uiResult == 0)
{
return ERROR_SUCCESS;
}
else if (uiResult == ERROR_INSTALL_USEREXIT)
{
// InitializeEmbeddedUI is not allowed to return ERROR_INSTALL_USEREXIT.
// So return success here and then IDCANCEL on the next progress message.
uiResult = 0;
*pdwInternalUILevel = INSTALLUILEVEL_NONE;
Log(hSession, L"Initialization canceled by user.");
}
}
}
}
g_pProcessMessageMethod->Release();
g_pProcessMessageMethod = NULL;
g_pShutdownMethod->Release();
g_pShutdownMethod = NULL;
g_pClrHost->UnloadDomain(g_pAppDomain);
g_pAppDomain->Release();
g_pAppDomain = NULL;
}
g_pClrHost->Stop();
g_pClrHost->Release();
g_pClrHost = NULL;
}
//.........这里部分代码省略.........
示例7: SHGetKnownFolderPath
BOOL Credential::SetMacDefaultBoot()
{
// get the filesystem location of %ProgramFiles%
// http://msdn.microsoft.com/en-us/library/bb762188.aspx
wchar_t* pathProgramFiles = 0;
SHGetKnownFolderPath(FOLDERID_ProgramFiles, 0, NULL, &pathProgramFiles);
// build the path to bootcamp.exe
// http://msdn.microsoft.com/en-us/library/ms647527.aspx
std::wstring pathBootCamp(pathProgramFiles);
pathBootCamp += L"\\Boot Camp\\BootCamp.exe";
// free the memory like the docs tell us
CoTaskMemFree(static_cast<void*>(pathProgramFiles));
// Make sure the executable exists
DWORD attr = GetFileAttributes(pathBootCamp.c_str());
if (attr == INVALID_FILE_ATTRIBUTES || (attr & FILE_ATTRIBUTE_DIRECTORY))
{
debug << "BootCamp.exe not found at " << pathBootCamp.c_str() << std::endl;
return FALSE;
}
// Finish building the complete command line to set the Mac startup volume
// http://support.apple.com/kb/HT3802
// "%ProgramFiles%\Boot Camp\BootCamp.exe" -StartupDisk
std::wstring fullCmd(L"\"" + pathBootCamp + L"\" -StartupDisk");
debug << fullCmd.c_str() << std::endl;
// CreateProcess
//http://msdn.microsoft.com/en-us/library/ms682425.aspx
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
wchar_t * pwszCmd = new wchar_t[fullCmd.length() + 1];
StringCchCopy(pwszCmd, fullCmd.length() + 1, fullCmd.c_str());
if (!CreateProcessW(NULL, // No module name (use command line)
pwszCmd, // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi ) // Pointer to PROCESS_INFORMATION structure
)
{
debug << L"CreateProcess failed with error " << GetLastError() << std::endl;
/* Free memory */
delete[]pwszCmd;
pwszCmd = 0;
return FALSE;
}
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, 5000 );
debug << L"BootCamp.exe finished or timeout elapsed" << std::endl;
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
/* Free memory */
delete[]pwszCmd;
pwszCmd = 0;
return TRUE;
}
示例8: ParseCommandLine
//.........这里部分代码省略.........
{
//
// If the switch value isn't optional, the next argument
// must be the value.
//
if (!Switches[switchIndex].SwitchValueOptional)
{
switchValue = argv[i+1];
i += 1; // Skip the argument.
}
//
// Otherwise the switch value is optional, so check the next parameter.
//
// If it's a switch, the user didn't specify a value, if it's not a switch
// the user DID specify a value.
//
else if (argv[i+1][0] != L'-' && argv[i+1][0] != L'/')
{
switchValue = argv[i+1];
i += 1; // Skip the argument.
}
}
else if (!Switches[switchIndex].SwitchValueOptional)
{
printf("Invalid command line argument parsing option %S\n", Switches[switchIndex].SwitchName);
return false;
}
}
switch (Switches[switchIndex].SwitchType)
{
//
// SwitchTypeNone switches take a boolean parameter indiating whether or not the parameter was present.
//
case CommandLineSwitch::SwitchTypeNone:
*reinterpret_cast<bool *>(Switches[switchIndex].SwitchValue) = true;
break;
//
// SwitchTypeInteger switches take an integer parameter.
//
case CommandLineSwitch::SwitchTypeInteger:
{
wchar_t *endValue;
long value = wcstoul(switchValue, &endValue, 0);
if (value == ULONG_MAX || value == 0 || (*endValue != L'\0' && !iswspace(*endValue)))
{
printf("Command line switch %S expected an integer value, received %S", Switches[switchIndex].SwitchName, switchValue);
return false;
}
*reinterpret_cast<long *>(Switches[switchIndex].SwitchValue) = value;
break;
}
//
// SwitchTypeString switches take a string parameter - allocate a buffer for the string using operator new[].
//
case CommandLineSwitch::SwitchTypeString:
{
wchar_t ** switchLocation = reinterpret_cast<wchar_t **>(Switches[switchIndex].SwitchValue);
//
// If the user didn't specify a value, set the location to NULL.
//
if (switchValue == NULL || *switchValue == '\0')
{
*switchLocation = NULL;
}
else
{
size_t switchLength = wcslen(switchValue)+1;
*switchLocation = new (std::nothrow) wchar_t[switchLength];
if (*switchLocation == NULL)
{
printf("Unable to allocate memory for switch %S", Switches[switchIndex].SwitchName);
return false;
}
HRESULT hr = StringCchCopy(*switchLocation, switchLength, switchValue);
if (FAILED(hr))
{
printf("Unable to copy command line string %S to buffer\n", switchValue);
return false;
}
}
break;
}
default:
break;
}
// We've processed this command line switch, we can move to the next argument.
//
break;
}
}
if (switchIndex == SwitchCount)
{
printf("unrecognized switch: %S", argv[i]);
return false;
}
}
}
return true;
}
示例9: cfgui_dlgproc
//.........这里部分代码省略.........
case WM_NOTIFY:
{
LPNMHDR lpnm;
LPNMTREEVIEW lptv;
LPNMTVGETINFOTIP lpgi;
khui_config_node node;
lpnm = (LPNMHDR) lParam;
switch (lpnm->code) {
case TVN_SELCHANGED:
lptv = (LPNMTREEVIEW) lParam;
cfgui_activate_node(hwnd,
(khui_config_node)
lptv->itemNew.lParam);
return TRUE;
case TVN_GETINFOTIP:
lpgi = (LPNMTVGETINFOTIP) lParam;
node = (khui_config_node) lpgi->lParam;
if (node) {
khm_int32 flags = 0;
flags = khui_cfg_get_flags(node);
if (flags & KHUI_CNFLAG_MODIFIED) {
LoadString(khm_hInstance, IDS_CFG_IT_MOD,
lpgi->pszText, lpgi->cchTextMax);
} else if (flags & KHUI_CNFLAG_APPLIED) {
LoadString(khm_hInstance, IDS_CFG_IT_APP,
lpgi->pszText, lpgi->cchTextMax);
} else {
LoadString(khm_hInstance, IDS_CFG_IT_NONE,
lpgi->pszText, lpgi->cchTextMax);
}
} else {
StringCchCopy(lpgi->pszText, lpgi->cchTextMax, L"");
}
return TRUE;
}
}
return TRUE;
case WM_CTLCOLORSTATIC:
{
d = cfgui_get_wnd_data(hwnd);
if (d == NULL)
break;
return (BOOL)(DWORD_PTR) d->hbr_white;
}
/* implicit break */
case WM_COMMAND:
switch(wParam) {
case MAKEWPARAM(IDCANCEL, BN_CLICKED):
khm_leave_modal();
EndDialog(hwnd, 0);
break;
case MAKEWPARAM(IDAPPLY, BN_CLICKED):
cfgui_apply_settings(NULL);
break;
case MAKEWPARAM(IDOK, BN_CLICKED):
cfgui_apply_settings(NULL);
khm_leave_modal();
EndDialog(hwnd, 0);
break;
}
return TRUE;
case KHUI_WM_CFG_NOTIFY:
switch(HIWORD(wParam)) {
case WMCFG_SHOW_NODE:
cfgui_activate_node(hwnd, (khui_config_node) lParam);
break;
case WMCFG_UPDATE_STATE:
cfgui_update_state(hwnd, LOWORD(wParam),
(khui_config_node) lParam);
break;
case WMCFG_SYNC_NODE_LIST:
d = cfgui_get_wnd_data(hwnd);
if (d == NULL)
break;
cfgui_sync_node_list(d, hwnd);
break;
}
return TRUE;
}
return FALSE;
}
示例10: switch
BOOL CALLBACK CQuickLaunch::QuickLaunchProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
static HWND hwndList;
static HKEY g_hKey = NULL;
static list<LaunchItem*> launchItems;
TEXTMETRIC tm;
static CDlgAnchor g_dlgAnchor;
switch (message)
{
case WM_SIZE :
{
g_dlgAnchor.OnSize();
}
break;
case WM_MEASUREITEM :
{
LPMEASUREITEMSTRUCT lpmis;
lpmis = (MEASUREITEMSTRUCT FAR*) lParam;
if (GetTextMetricsW(GetDC(hwndDlg), &tm))
{
lpmis->itemHeight = (UINT)(tm.tmHeight * 2.5);
}
else
{
lpmis->itemHeight = 50;
}
}
break;
case WM_DRAWITEM :
{
WCHAR tchBuffer[256] = {0};
int y = 0;
LPDRAWITEMSTRUCT lpdis = (DRAWITEMSTRUCT FAR*) lParam;
LaunchItem* pRecord = (LaunchItem*)lpdis->itemData;
GetTextMetrics(lpdis->hDC, &tm);
HBRUSH hBrush = NULL;
SetBkMode(lpdis->hDC, TRANSPARENT);
if ((lpdis->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)))
{
if ((lpdis->itemState & ODS_SELECTED))
{
hBrush = GetSysColorBrush(COLOR_HIGHLIGHT);
SetTextColor(lpdis->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
}
else
{
hBrush = GetSysColorBrush(COLOR_WINDOW);
SetTextColor(lpdis->hDC, GetSysColor(COLOR_WINDOWTEXT));
}
}
if (hBrush)
{
int desiredHeight = (lpdis->rcItem.bottom - lpdis->rcItem.top) - 2;
RECT rect;
memcpy(&rect, &(lpdis->rcItem), sizeof(RECT));
rect.top += 1;
rect.bottom -= 1;
rect.left += 1;
rect.right -= 1;
rect.left += desiredHeight;
FillRect(lpdis->hDC, &rect, hBrush);
rect.left += 5;
rect.right -= 5;
rect.bottom -= 5;
rect.top += 5;
WCHAR wzFullPath[MAX_PATH];
WCHAR wzName[MAX_PATH];
StringCchCopy(wzFullPath, ARRAYSIZE(wzFullPath), pRecord->wzPath);
StringCchCopy(wzName, ARRAYSIZE(wzName), pRecord->wzPath);
WCHAR* wzFile = wcsrchr(wzName, L'\\');
if (!wzFile)
{
wzFile = wzName;
}
else
{
wzFile++;
}
WCHAR* wzExt = wcsrchr(wzFile, L'.');
if (wzExt)
{
wzExt[0] = 0;
}
WCHAR* wzDir = wcsrchr(wzFullPath, L'\\');
if (wzDir)
{
wzDir[0] = 0;
}
//.........这里部分代码省略.........
示例11: PreviewVisibalise
//.........这里部分代码省略.........
InvalidateRect( ghPrevWnd, NULL, TRUE );
if( bForeg ) SetForegroundWindow( ghPrevWnd );
return S_FALSE;
}
// プレビュー開いてないときに、非フォアグランドなら何もしない
if( !(bForeg) ){ return E_ABORT; }
InitWindowPos( INIT_LOAD, WDP_PREVIEW, &rect );
if( 0 >= rect.right || 0 >= rect.bottom ) // 幅高さが0はデータ無し
{
hWnd = GetDesktopWindow( );
GetWindowRect( hWnd, &rect );
rect.left = ( rect.right - PVW_WIDTH ) / 2;
rect.top = ( rect.bottom - PVW_HEIGHT ) / 2;
rect.right = PVW_WIDTH;
rect.bottom = PVW_HEIGHT;
InitWindowPos( INIT_SAVE , WDP_PREVIEW, &rect ); // 起動時保存
}
ghPrevWnd = CreateWindowEx( WS_EX_TOOLWINDOW, DOC_PREVIEW_CLASS, TEXT("IEコンポーネントによるプレビュー"),
WS_POPUP | WS_THICKFRAME | WS_CAPTION | WS_VISIBLE | WS_SYSMENU,
rect.left, rect.top, rect.right, rect.bottom, NULL, NULL, ghInst, NULL );
//ツールバー作る
ghToolWnd = CreateWindowEx( 0, TOOLBARCLASSNAME, TEXT("toolbar"),
WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT | TBSTYLE_LIST | TBSTYLE_TOOLTIPS | CCS_NODIVIDER,
0, 0, 0, 0, ghPrevWnd, (HMENU)IDW_PVW_TOOL_BAR, ghInst, NULL );
// 自動ツールチップスタイルを追加
SendMessage( ghToolWnd, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_MIXEDBUTTONS );
SendMessage( ghToolWnd, TB_SETIMAGELIST, 0, (LPARAM)ghPrevwImgLst );
SendMessage( ghToolWnd, TB_SETBUTTONSIZE, 0, MAKELPARAM(16,16) );
SendMessage( ghToolWnd, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0 );
// ツールチップ文字列を設定・ボタンテキストがツールチップになる
StringCchCopy( atBuffer, MAX_STRING, TEXT("全プレビュースタイル") ); gstTBInfo[0].iString = SendMessage( ghToolWnd, TB_ADDSTRING, 0, (LPARAM)atBuffer );
SendMessage( ghToolWnd , TB_ADDBUTTONS, (WPARAM)TB_ITEMS, (LPARAM)&gstTBInfo ); // ツールバーにボタンを挿入
SendMessage( ghToolWnd , TB_AUTOSIZE, 0, 0 ); // ボタンのサイズに合わせてツールバーをリサイズ
InvalidateRect( ghToolWnd , NULL, TRUE ); // クライアント全体を再描画する命令
// ツールバーサブクラス化が必要
GetWindowRect( ghToolWnd, &tbRect );
tbRect.right -= tbRect.left;
tbRect.bottom -= tbRect.top;
tbRect.left = 0;
tbRect.top = 0;
GetClientRect( ghPrevWnd, &rect );
rect.top = tbRect.bottom;
rect.bottom -= tbRect.bottom;
AtlAxWinInit( );
ghIEwnd = CreateWindowEx( 0, ATL_AX_WIN, TEXT("Shell.Explorer.2"),
WS_CHILD | WS_VISIBLE, rect.left, rect.top, rect.right, rect.bottom,
ghPrevWnd, (HMENU)IDW_PVW_VIEW_WNDW, ghInst, NULL );
// ActiveXコントロールのインターフェースを要求
if( SUCCEEDED( AtlAxGetControl( ghIEwnd, &comPunkIE ) ) )
{
gpWebBrowser2 = comPunkIE; // ポインタに格納
if( gpWebBrowser2 )
{
gpWebBrowser2->Navigate2( &vUrl, &vEmpty, &vEmpty, &vEmpty, &vEmpty );
while( 1 )
{
hRslt = gpWebBrowser2->get_Document( &pDispatch );
if( SUCCEEDED(hRslt) && pDispatch )
{
gpDocument2 = pDispatch;
if( gpDocument2 ){ hRslt = S_OK; break; }
}
Sleep(100);
}
}
else
{
NotifyBalloonExist( TEXT("IEコンポーネントを初期化出来なかったよ・・・"), TEXT("お燐からのお知らせ"), NIIF_ERROR );
hRslt = E_ACCESSDENIED;
}
}
if( SUCCEEDED(hRslt) ){ PreviewPageWrite( iNowPage ); }
UpdateWindow( ghPrevWnd );
return hRslt;
}
示例12: DestroyPhoneNodes
node* CQuickLaunch::BuildLaunchList(int* piNodeLen, int thumbWidth, int thumbHeight)
{
if (g_iThumbHeight != thumbHeight || g_iThumbWidth != thumbWidth)
{
DestroyPhoneNodes(NULL);
}
if (!g_pHeadNode)
{
node* pHead = NULL;
node* pPrev = NULL;
list<LaunchItem*> pPhoneList = g_launchList;
list<LaunchItem*>::iterator iter = pPhoneList.begin();
int iPhoneNodeListCount = 0;
while (iter != pPhoneList.end())
{
LaunchItem* pRecord = *iter;
node* pCurr = new node();
if (!pHead)
{
pHead = pCurr;
pCurr = pHead;
}
else
{
pPrev->next = pCurr;
}
pRecord->hIcon = GetApplicationIcon(pRecord->wzPath, false, NULL, NULL, NULL);
pCurr->prev = pPrev;
pCurr->hIcon = pRecord->hIcon;
pCurr->iIndex = iPhoneNodeListCount;
pCurr->bCenter = true;
pCurr->hBmp = NULL;
Sleep(5);
WCHAR* wzName = wcsrchr(pRecord->wzPath, L'\\');
if (!wzName)
{
wzName = pRecord->wzPath;
}
else
{
wzName++;
}
StringCchCopy(pCurr->wzText, ARRAYSIZE(pCurr->wzText), wzName);
WCHAR* wzExt = wcsrchr(pCurr->wzText, '.');
if (wzExt)
{
wzExt[0] = 0;
}
StringCchCopy(pCurr->wzDetails, ARRAYSIZE(pCurr->wzDetails), L"Select to Launch");
/*
StringCchCopy(pCurr->wzDetails, ARRAYSIZE(pCurr->wzDetails), pRecord->wzPath);
wzName = wcsrchr(pCurr->wzDetails, L'\\');
if (wzName)
{
wzName[0] = 0;
}
*/
pCurr->pData = pRecord;
pPrev = pCurr;
iter++;
iPhoneNodeListCount++;
}
g_iNodeLen = iPhoneNodeListCount;
g_pHeadNode = pHead;
}
g_iThumbHeight = thumbHeight;
g_iThumbWidth = thumbWidth;
*piNodeLen = g_iNodeLen;
return g_pHeadNode;
}
示例13: install
bool install(const std::wstring& inf, const std::wstring& hardware_id, bool& reboot_required)
{
TCHAR inf_path[MAX_PATH];
if (GetFullPathName(inf.c_str(), MAX_PATH, inf_path, NULL) >= MAX_PATH)
{
return false;
}
std::wcerr << "INF file full path: " << inf_path << std::endl;
bool result = false;
TCHAR hardware_id_list[LINE_LEN + 4];
ZeroMemory(hardware_id_list, sizeof(hardware_id_list));
if (SUCCEEDED(StringCchCopy(hardware_id_list, LINE_LEN, hardware_id.c_str())))
{
std::wcerr << "Hardware identifier list: " << hardware_id_list << std::endl;
GUID class_guid;
TCHAR class_name[MAX_CLASS_NAME_LEN];
if (SetupDiGetINFClass(inf_path, &class_guid, class_name, sizeof(class_name) / sizeof(class_name[0]), 0))
{
std::wcerr << "Class name: " << class_name << std::endl;
HDEVINFO device_info_set = INVALID_HANDLE_VALUE;
device_info_set = SetupDiCreateDeviceInfoList(&class_guid, 0);
if (device_info_set != INVALID_HANDLE_VALUE)
{
std::wcerr << "Device information set created." << std::endl;
SP_DEVINFO_DATA device_info_data;
device_info_data.cbSize = sizeof(SP_DEVINFO_DATA);
if (SetupDiCreateDeviceInfo(device_info_set,
class_name,
&class_guid,
NULL,
0,
DICD_GENERATE_ID,
&device_info_data))
{
std::wcerr << "Device information element created." << std::endl;
if (SetupDiSetDeviceRegistryProperty(device_info_set,
&device_info_data,
SPDRP_HARDWAREID,
(LPBYTE)hardware_id_list,
(lstrlen(hardware_id_list) + 1 + 1) * sizeof(TCHAR)))
{
std::wcerr << "Hardware id set." << std::endl;
if (SetupDiCallClassInstaller(DIF_REGISTERDEVICE, device_info_set, &device_info_data))
{
std::wcerr << "Device registered." << std::endl;
result = update(inf, hardware_id, reboot_required);
}
}
}
SetupDiDestroyDeviceInfoList(device_info_set);
}
}
}
return result;
}
示例14: MainWndProc
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static PCSpotify spotify(nullptr);
if (spotify == nullptr)
{
if ((spotify = new CSpotify) == nullptr)
{
return -1;
}
spotify->initalize();
}
switch (message)
{
case WMAPP_NOTIFYCALLBACK:
switch (lParam)
{
case WM_LBUTTONDBLCLK:
if (spotify != nullptr)
spotify->pasteSong();
break;
case WM_RBUTTONDOWN:
case WM_CONTEXTMENU:
{
POINT pt{};
GetCursorPos(&pt);
HMENU hMenu = CreatePopupMenu();
if (hMenu)
{
InsertMenu(hMenu, static_cast<UINT>(-1), MF_BYPOSITION, WMAPP_PASTESONG, _T("Paste song."));
InsertMenu(hMenu, static_cast<UINT>(-1), MF_BYPOSITION, WMAPP_SETTINGS, _T("Settings"));
InsertMenu(hMenu, static_cast<UINT>(-1), MF_BYPOSITION, WMAPP_EXIT, _T("Exit"));
SetForegroundWindow(hWnd);
TrackPopupMenu(hMenu, TPM_BOTTOMALIGN, pt.x, pt.y, 0, hWnd, NULL);
DestroyMenu(hMenu);
}
}
default:
break;
}
case WM_CREATE:
{
NOTIFYICONDATA nid = { sizeof(nid) };
nid.hWnd = hWnd;
nid.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE | NIF_SHOWTIP;
nid.uCallbackMessage = WMAPP_NOTIFYCALLBACK;
nid.hIcon = g_hIcon;
StringCchCopy(nid.szTip, ARRAYSIZE(nid.szTip), _T("Spotify2PuTTY"));
Shell_NotifyIcon(NIM_ADD, &nid);
nid.uVersion = NOTIFYICON_VERSION_4;
Shell_NotifyIcon(NIM_SETVERSION, &nid);
RegisterHotKey(hWnd, 0x337, SR_MODIFIERS, SR_KEYS);
break;
}
case WM_HOTKEY:
if (LOWORD(lParam) == (SR_MODIFIERS) && HIWORD(lParam) == SR_KEYS && spotify != nullptr)
{
spotify->pasteSong();
}
break;
case WM_COMMAND:
{
int wmId = LOWORD(wParam);
switch (wmId)
{
case WMAPP_PASTESONG:
{
if (spotify != nullptr)
spotify->pasteSong();
break;
}
case WMAPP_SETTINGS:
// show settings dialog
DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_SETTINGS), hWnd, SettingsWndProc, reinterpret_cast<LPARAM>(spotify));
break;
case WMAPP_EXIT:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
break;
case WM_CLOSE:
case WM_DESTROY:
{
if (spotify != nullptr)
spotify->finalize();
EndDialog(hWnd, 0);
break;
}
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
示例15: FreeImage
// process image
void Viewer::Update(Png *png1)
{
struct p2d_globals_struct *p2dg = NULL;
P2D *p2d = NULL;
int rv;
int dens_x, dens_y, dens_units;
unsigned char tmpr,tmpg,tmpb;
HCURSOR hcur=NULL;
int cursor_flag=0;
struct viewer_read_ctx read_ctx;
m_errorflag=0;
FreeImage();
if(!png1) goto abort;
if(png1->m_imgtype==IMG_MNG) {
m_errorflag=1;
StringCchCopy(m_errormsg,200,_T("Viewer doesn") SYM_RSQUO _T("t support MNG files."));
goto abort;
}
else if(png1->m_imgtype==IMG_JNG) {
m_errorflag=1;
StringCchCopy(m_errormsg,200,_T("Viewer doesn") SYM_RSQUO _T("t support JNG files."));
goto abort;
}
hcur=SetCursor(LoadCursor(NULL,IDC_WAIT));
cursor_flag=1;
if(!globals.viewer_p2d_globals) {
globals.viewer_p2d_globals = (void*)p2d_create_globals();
}
p2d = p2d_init((p2d_globals_struct*)globals.viewer_p2d_globals);
png1->stream_file_start();
p2d_set_png_read_fn(p2d,my_read_fn);
read_ctx.png = png1;
p2d_set_userdata(p2d,(void*)&read_ctx);
p2d_enable_color_correction(p2d, globals.use_gamma?1:0);
p2d_set_use_file_bg(p2d,globals.use_imagebg?1:0);
if(globals.use_custombg) {
p2d_set_custom_bg(p2d,GetRValue(globals.custombgcolor),
GetGValue(globals.custombgcolor),GetBValue(globals.custombgcolor));
}
rv=p2d_run(p2d);
if(rv!=PNGD_E_SUCCESS) {
lstrcpyn(m_errormsg,p2d_get_error_msg(p2d),200);
m_errorflag=1;
goto abort;
}
rv=p2d_get_dib(p2d,&m_dib);
m_dib_size = p2d_get_dib_size(p2d);
rv=p2d_get_dibbits(p2d, &m_bits);
m_adjwidth = m_dib->biWidth;
m_adjheight = m_dib->biHeight;
if(globals.viewer_correct_nonsquare)
rv=p2d_get_density(p2d, &dens_x, &dens_y, &dens_units);
else
rv=0;
if(rv) {
if(dens_x!=dens_y && dens_x>0 && dens_y>0 &&
10*dens_x>dens_y && 10*dens_y>dens_x)
{
if(dens_x>dens_y) {
m_adjheight = (int) (0.5+ (double)m_adjheight * ((double)dens_x/(double)dens_y) );
}
else {
m_adjwidth = (int) (0.5+ (double)m_adjwidth * ((double)dens_y/(double)dens_x) );
}
}
}
CalcStretchedSize();
m_imghasbgcolor=0;
if(p2d_get_bgcolor(p2d,&tmpr,&tmpg,&tmpb)) {
m_imghasbgcolor=1;
m_imgbgcolor = RGB(tmpr,tmpg,tmpb);
}
abort:
if(p2d) p2d_done(p2d);
if(m_hwndViewer) {
InvalidateRect(m_hwndViewer,NULL,TRUE);
}
if(cursor_flag) SetCursor(hcur);
}