Example #1
0
BOOL systray_shutdown_notify(HWND hWnd, UINT uniqueID)
{
	// http://www.codeproject.com/kb/shell/stealthdialog.aspx?display=printall
	HICON hicon = LoadIcon(NULL,MAKEINTRESOURCE(IDI_INFORMATION));

	// Tray icon
	NOTIFYICONDATA tnid = {};
	tnid.cbSize = sizeof(NOTIFYICONDATA);
	memset( &tnid, 0, sizeof(tnid) );

	tnid.hWnd = hWnd;
	tnid.uID = uniqueID;

	tnid.uVersion = NOTIFYICON_VERSION;
	tnid.uFlags = NIF_ICON;
	tnid.uCallbackMessage = WM_USER_SYSTRAY;
	tnid.hIcon = hicon;
	Shell_NotifyIcon(NIM_DELETE, &tnid);
	Shell_NotifyIcon(NIM_SETVERSION, &tnid);
	Shell_NotifyIcon(NIM_ADD, &tnid);

	// Notification balloon
	// https://stackoverflow.com/questions/1414947/display-balloon-tooltip-in-systemtray
	tnid.hWnd = GetActiveWindow();
	tnid.cbSize =sizeof(NOTIFYICONDATA);
	tnid.uCallbackMessage = WM_USER_SYSTRAY;
	tnid.hIcon = hicon;
	tnid.uTimeout = 300000;
	tnid.uVersion = NOTIFYICON_VERSION;
	tnid.uFlags = NIF_INFO | NIF_MESSAGE | NIF_ICON | NIF_TIP;
	tnid.uID = uniqueID;
	tnid.dwInfoFlags = NIIF_INFO;
	StrCpyW(tnid.szInfoTitle,_T("MicroSIP: Shutting Down..."));
	char cInfo[256];
	sprintf(cInfo, "%s", "Unbinding uPnP");
	StrCpyW(tnid.szInfo, convertCharArrayToLPCWSTR(cInfo));
	StrCpyW(tnid.szTip, _T("MicroSIP: Shutting Down...\nUnbinding uPnP"));
	Shell_NotifyIcon(NIM_MODIFY,&tnid);

	if (hicon) 
        DestroyIcon(hicon); 

	// Play windows notification sound as we have put a notification on the box
	PlaySound(TEXT("SystemExit"), NULL, SND_ALIAS);
	return true;
}
static LPWSTR load_string(HINSTANCE hInstance, UINT uiResourceId)
{
    WCHAR string[256];
    LPWSTR ret;

    LoadStringW(hInstance, uiResourceId, string, sizeof(string)/sizeof(string[0]));
    ret = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, (wcslen(string) + 1) * sizeof(WCHAR));
    StrCpyW(ret, string);
    return ret;
}
Example #3
0
static void test_StrCpyW(void)
{
  WCHAR szSrc[256];
  WCHAR szBuff[256];
  const StrFormatSizeResult* result = StrFormatSize_results;


  while(result->value)
  {
    MultiByteToWideChar(0,0,result->byte_size_64,-1,szSrc,sizeof(szSrc)/sizeof(WCHAR));

    StrCpyW(szBuff, szSrc);
    ok(!StrCmpW(szSrc, szBuff), "Copied string %s wrong\n", result->byte_size_64);
    result++;
  }
}
Example #4
0
void change_to_directory_of_file(LPCWSTR fileName)
{
    WCHAR wcbuffer[MAX_PATH];
    StrCpyW(wcbuffer, fileName);

#if defined (WINDOWS_VERSION)
    LPWSTR backSlashAt = StrRChrW(wcbuffer, NULL, L'\\');
    if (backSlashAt != NULL) {
        wcbuffer[wcslen(wcbuffer) - wcslen(backSlashAt)] = L'\0';
        SetCurrentDirectoryW(wcbuffer);
    }
#else
    if (strrchr(wcbuffer, '/') != NULL) {
        strrchr(wcbuffer, '/')[0] = 0;
        chdir(wcbuffer);
    }
#endif
}
Example #5
0
HRESULT AppendString(LPWSTR *ppwzHead, LPCWSTR pwzTail, DWORD dwLen)
{
    HRESULT                                    hr = S_OK;
    LPWSTR                                     pwzBuf = NULL;
    DWORD                                      dwLenBuf;
    
    ASSERT(ppwzHead && pwzTail);

    if (!*ppwzHead) {
        *ppwzHead = NEW(WCHAR[dwLen + 1]);

        if (!*ppwzHead) {
            hr = E_OUTOFMEMORY;
            goto Exit;
        }
 
        // StrCpyN takes length in chars *including* NULL char

        StrCpyNW(*ppwzHead, pwzTail, dwLen + 1);
    }
    else {
        dwLenBuf = lstrlenW(*ppwzHead) + dwLen + 1;

        pwzBuf = NEW(WCHAR[dwLenBuf]);
        if (!pwzBuf) {
            hr = E_OUTOFMEMORY;
            goto Exit;
        }

        StrCpyW(pwzBuf, *ppwzHead);
        StrNCatW(pwzBuf, pwzTail, dwLen + 1);

        SAFEDELETEARRAY(*ppwzHead);

        *ppwzHead = pwzBuf;
    }

Exit:
    return hr;
}
Example #6
0
BOOL GetIntstancesAndCountersOfObject(CONST std::wstring wsObject, 
									 std::vector<std::wstring>& vecInstances, 
									 std::vector<std::wstring>& vecCounters)
{
	LPWSTR szDataSource = NULL, szMachineName = NULL,
		mszCounterList = NULL, mszInstanceList = NULL;
	DWORD dwCounterListLength = 0, dwInstanceListLength = 0;

	std::wstringstream wssInstanceName, wssCounterName;
	LPWSTR szObjectName = new WCHAR[wsObject.length() + 1];
	StrCpyW(szObjectName, wsObject.c_str());

	PDH_STATUS status =
		PdhEnumObjectItems(szDataSource, szMachineName, szObjectName,
		mszCounterList, &dwCounterListLength, mszInstanceList,
		&dwInstanceListLength, PERF_DETAIL_WIZARD, 0);

	if (status != PDH_MORE_DATA) {
		delete[]szObjectName;
		return FALSE;
	}

	mszCounterList = new WCHAR[dwCounterListLength + 1];
	mszInstanceList = new WCHAR[dwInstanceListLength + 1];

	status = PdhEnumObjectItems(szDataSource, szMachineName, szObjectName,
								mszCounterList, &dwCounterListLength, mszInstanceList,
								&dwInstanceListLength, PERF_DETAIL_WIZARD, 0);

	if (FAILED(status)) {
		delete[]mszCounterList;
		delete[]mszInstanceList;
		delete[]szObjectName;
		return FALSE;
	}

	if (dwInstanceListLength) {
		for (DWORD c = 0; c < dwInstanceListLength-1; ++c) {
			if (mszInstanceList[c])
				wssInstanceName << mszInstanceList[c];
			else {
				vecInstances.push_back(wssInstanceName.str());
				wssInstanceName.str(L"");
			}
		}
	}

	if (dwCounterListLength) {
		for (DWORD c = 0; c < dwCounterListLength-1; ++c) {
			if (mszCounterList[c]) {
				wssCounterName << mszCounterList[c];
			} else {
				vecCounters.push_back(wssCounterName.str());
				wssCounterName.str(L"");
			}
		}
	}

	delete[]mszCounterList;
	delete[]mszInstanceList;
	delete[]szObjectName;

	return TRUE;
}