コード例 #1
0
ファイル: ctrl_edit.cpp プロジェクト: kmdtukl/miranda-ng
BOOL CEditCtrl::OnInfoChanged(MCONTACT hContact, LPCSTR pszProto)
{
	if (!_Flags.B.hasChanged) {
		DBVARIANT dbv;
		TCHAR szText[64];

		_Flags.B.hasCustom = _Flags.B.hasProto = _Flags.B.hasMeta = 0;
		_Flags.W |= DB::Setting::GetTStringCtrl(hContact, _pszModule, _pszModule, pszProto, _pszSetting, &dbv);

		EnableWindow(_hwnd,
			!hContact || _Flags.B.hasCustom || !db_get_b(NULL, MODNAME, SET_PROPSHEET_PCBIREADONLY, 0));

		MIR_FREE(_pszValue);
		switch (dbv.type) {
		case DBVT_BYTE:
			_itot_s(dbv.bVal, szText, _countof(szText), 10);
			SetWindowText(_hwnd, szText);
			_pszValue = mir_tstrdup(szText);
			break;

		case DBVT_WORD:
			_itot_s(dbv.wVal, szText, _countof(szText), 10);
			SetWindowText(_hwnd, szText);
			_pszValue = mir_tstrdup(szText);
			break;

		case DBVT_DWORD:
			_itot_s(dbv.dVal, szText, _countof(szText), 10);
			SetWindowText(_hwnd, szText);
			_pszValue = mir_tstrdup(szText);
			break;

		case DBVT_TCHAR:
			if (dbv.ptszVal) {
				SetWindowText(_hwnd, dbv.ptszVal);
				_pszValue = dbv.ptszVal;
				break;
			}

		default:
			SetWindowText(_hwnd, _T(""));
			db_free(&dbv);
			break;
		}
		_Flags.B.hasChanged = 0;
	}
	return _Flags.B.hasChanged;
}
コード例 #2
0
ファイル: strutils.cpp プロジェクト: mosunovpa/Projects
/**
 * converts int to string
 */
_tstring strutils::to_string(int val, size_t size/* = 20*/, int radix/* = 10*/)
{
	_tstring res;
	res.resize(size);
	_itot_s(val, &res[0], size, radix);
	return _tstring(&res[0]); // need for adjusting of the result string size
}
コード例 #3
0
ファイル: EditFile.cpp プロジェクト: bruderstein/FileSwitcher
TCHAR *EditFile::getIndexString(BOOL includeView)
{
	if (_indexString == NULL)
	{
		TCHAR tmp[16];
		_itot_s(_index + 1, tmp, 16, 10);
		int length = _tcslen(tmp);

		if (_view == 1 && includeView)
			length += 4;
	
		_indexString = new TCHAR[length + 1];

		if (_view == 1 && includeView)
		{
			_tcscpy_s(_indexString, length + 1, _T("[2] "));
			_tcscat_s(_indexString, length + 1, tmp);
		}
		else
			_tcscpy_s(_indexString, length + 1, tmp);

	
	}
	return _indexString;
}
コード例 #4
0
ファイル: ado2.cpp プロジェクト: lidongqiang/wvpctool
wstring IntToStr(int nVal)
{
	wstring strRet;
	TCHAR buff[10];
	_itot_s(nVal,buff,sizeof(buff)/sizeof(buff[0]),10);
	strRet = buff;
	return strRet;
}
コード例 #5
0
ファイル: Compare.cpp プロジェクト: tititiou36/Compare-plugin
void saveSettings(void)
{
    TCHAR buffer[64];

    _itot_s(Settings.ColorSettings.added, buffer, 64, 10);
    ::WritePrivateProfileString(colorsSection, addedColorOption, buffer, iniFilePath);

    _itot_s(Settings.ColorSettings.deleted, buffer, 64, 10);
    ::WritePrivateProfileString(colorsSection, removedColorOption, buffer, iniFilePath);

    _itot_s(Settings.ColorSettings.changed, buffer, 64, 10);
    ::WritePrivateProfileString(colorsSection, changedColorOption, buffer, iniFilePath);

    _itot_s(Settings.ColorSettings.moved, buffer, 64, 10);
    ::WritePrivateProfileString(colorsSection, movedColorOption, buffer, iniFilePath);

    _itot_s(Settings.ColorSettings.blank, buffer, 64, 10);
    ::WritePrivateProfileString(colorsSection, blankColorOption, buffer, iniFilePath);

    _itot_s(Settings.ColorSettings.highlight, buffer, 64, 10);
    ::WritePrivateProfileString(colorsSection, highlightColorOption, buffer, iniFilePath);

    _itot_s(Settings.ColorSettings.alpha, buffer, 64, 10);
    ::WritePrivateProfileString(colorsSection, highlightAlphaOption, buffer, iniFilePath);

    ::WritePrivateProfileString(sectionName, addLinesOption, Settings.AddLine ? TEXT("1") : TEXT("0"), iniFilePath);
    ::WritePrivateProfileString(sectionName, ignoreSpacesOption, Settings.IncludeSpace ? TEXT("1") : TEXT("0"), iniFilePath);
    ::WritePrivateProfileString(sectionName, detectMovesOption, Settings.DetectMove ? TEXT("1") : TEXT("0"), iniFilePath);
    ::WritePrivateProfileString(sectionName, symbolsOption, Settings.OldSymbols ? TEXT("1") : TEXT("0"), iniFilePath);
    ::WritePrivateProfileString(sectionName, NavBarOption, Settings.UseNavBar ? TEXT("1") : TEXT("0"), iniFilePath);
}
コード例 #6
0
void UTBStr::itot(int value, TCHAR * dest, size_t size, int radix)
{
#if _MSC_VER >= 1400
	_itot_s(value, dest, size, radix);
#else
	UNREFERENCED_PARAMETER(size);
	_itot(value, dest, radix);
#endif
}
コード例 #7
0
ファイル: EditFile.cpp プロジェクト: bruderstein/FileSwitcher
TCHAR *EditFile::getViewString()
{
	if (_viewString == NULL)
	{
		_viewString = new TCHAR[2];
		_itot_s(_view + 1, _viewString, 2, 10);
	}

	return _viewString;
}
コード例 #8
0
//-----------------------------------------------------------------------------
// Name : GetFrameRate () 
// Desc : Returns the frame rate, sampled over the last second or so.
//-----------------------------------------------------------------------------
unsigned long CTimer::GetFrameRate( LPTSTR lpszString, size_t size ) const
{
	// Fill string buffer ?
	if ( lpszString )
	{
		// Copy frame rate value into string
		_itot_s( m_FrameRate, lpszString, size, 10 );

		// Append with FPS
		strcat_s( lpszString, size, _T(" FPS") );

	} // End if build FPS string

	return m_FrameRate;
}
コード例 #9
0
ファイル: AttachProcessDlg.cpp プロジェクト: avplayer/avdbg
BOOL CAttachProcessDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	RECT	rc;
	GetClientRect(&rc);
	
	int cx = rc.right-rc.left;
	int cy = rc.bottom-rc.top;
	m_ListProcess.MoveWindow(5,5,cx-10,cy-50,TRUE);
	m_BtnOK.MoveWindow(cx-200,cy-35,80,25,TRUE);
	m_BtnCancel.MoveWindow(cx-100,cy-35,80,25,TRUE);

	m_ListProcess.SetExtendedStyle(LVS_EX_GRIDLINES |LVS_EX_FULLROWSELECT); 

	m_ListProcess.InsertColumn(0, _T("PID"), LVCFMT_LEFT, 50);
	m_ListProcess.InsertColumn(1, _T("文件名"),LVCFMT_LEFT,50);
	m_ListProcess.InsertColumn(2, _T("文件路径"), LVCFMT_LEFT, 500);
	HANDLE hToolhelp = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
	if (hToolhelp == INVALID_HANDLE_VALUE)
	{
		this->MessageBox(_T("获取进程快照失败"));
		return	TRUE;
	}
	PROCESSENTRY32	stProcess = {0};
	stProcess.dwSize = sizeof(PROCESSENTRY32);
	Process32First(hToolhelp, &stProcess);
	for (int i=0;Process32Next(hToolhelp, &stProcess);i++)
	{
		TCHAR	pszPid[10];
		_itot_s(stProcess.th32ProcessID, pszPid,10);
		//m_ListProcess.SetItemText(i,0,pszPid);
		m_ListProcess.InsertItem(i, pszPid, NULL);
		m_ListProcess.SetItemText(i,1,stProcess.szExeFile);
		HANDLE	hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, stProcess.th32ProcessID);
		TCHAR	pszProcessPath[MAX_PATH+2];
		if (GetModuleFileNameEx(hProcess, NULL, pszProcessPath, MAX_PATH+2))
		{
			m_ListProcess.SetItemText(i, 2, pszProcessPath);
		}
		CloseHandle(hProcess);
	}
	CloseHandle(hToolhelp);


	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常: OCX 属性页应返回 FALSE
}
コード例 #10
0
void ApplicationListDlg::SetProgramParam(int item, DWORD param)
{
   LVITEM lvitem;

   //Store the value
   lvitem.mask = LVIF_PARAM;
   lvitem.iItem = item;
   lvitem.iSubItem = 0;
   lvitem.lParam = param;
   ListView_SetItem(m_hAppListWnd, &lvitem);

   //Setup sub-item in the list
   if (m_values)
   {
      ListView_SetItemText(m_hAppListWnd, item, 1, (LPTSTR)m_values[param]);
   }
   else if (m_valTitle) //else, this is not needed, as the data will not be shown/changed anyway
   {
      TCHAR buf[6];
	  _itot_s(param, buf, 6, 10);
      ListView_SetItemText(m_hAppListWnd, item, 1, buf);
   }
}
コード例 #11
0
void ApplicationListDlg::BeginEdit(int item)
{
   TCHAR buf[6];
   DWORD param = GetProgramParam(item);

   m_editedItemIndex = item;

   //Set the param value
   if (m_values) {
	   ComboBox_SetCurSel(m_hParamEditCtrl, param);
   } else {
	   _itot_s(param, buf, 6, 10);
	   SetWindowText(m_hParamEditCtrl, buf);
   }

   //Display the window at the correct location
   RECT rect;
   ListView_GetSubItemRect(m_hAppListWnd, item, 1, LVIR_BOUNDS, &rect);
   MoveWindow(m_hParamEditCtrl, rect.left, rect.top-1, rect.right-rect.left+1, rect.bottom-rect.top+1, TRUE);
   ShowWindow(m_hParamEditCtrl, SW_SHOW);

   //Give the focus to the edit control
   SetFocus(m_hParamEditCtrl);
}
コード例 #12
0
ファイル: pp.c プロジェクト: kcrazy/winekit
/*++

Routine Description: FillCommDlg

    Fill in baud rate, parity, etc in port dialog box

Arguments:

    hDlg: the window address

Return Value:

    BOOL: FALSE if function fails, TRUE if function passes

--*/
BOOL
FillCommDlg(
    HWND DialogHwnd
    )
{
    SHORT shIndex;
    TCHAR szTemp[81];

    //
    //  just list all of the baud rates
    //
    for(shIndex = 0; m_nBaudRates[shIndex]; shIndex++) {
        _itot_s(m_nBaudRates[shIndex], szTemp, ARRAYSIZE(szTemp), 10);

        SendDlgItemMessage(DialogHwnd,
                           PP_PORT_BAUDRATE,
                           CB_ADDSTRING,
                           0,
                           (LPARAM)szTemp);
    }

    //
    //  Set 9600 as default baud selection
    //
    shIndex = (USHORT) SendDlgItemMessage(DialogHwnd,
                                          PP_PORT_BAUDRATE,
                                          CB_FINDSTRING,
                                          (WPARAM)-1,
                                          (LPARAM)m_sz9600);

    shIndex = (shIndex == CB_ERR) ? 0 : shIndex;

    SendDlgItemMessage(DialogHwnd,
                       PP_PORT_BAUDRATE,
                       CB_SETCURSEL,
                       shIndex,
                       0L);

    for(shIndex = 0; m_nDataBits[shIndex]; shIndex++) {
        _itot_s(m_nDataBits[shIndex], szTemp, ARRAYSIZE(szTemp), 10);

        SendDlgItemMessage(DialogHwnd,
                           PP_PORT_DATABITS,
                           CB_ADDSTRING,
                           0,
                           (LPARAM)szTemp);
    }

    SendDlgItemMessage(DialogHwnd,
                       PP_PORT_DATABITS,
                       CB_SETCURSEL,
                       DEF_WORD,
                       0L);

    SetCBFromRes(GetDlgItem(DialogHwnd, PP_PORT_PARITY),
                 IDS_PARITY,
                 DEF_PARITY,
                 FALSE);

    SetCBFromRes(GetDlgItem(DialogHwnd, PP_PORT_STOPBITS),
                 IDS_BITS,
                 DEF_STOP,
                 TRUE);

    SetCBFromRes(GetDlgItem(DialogHwnd, PP_PORT_FLOWCTL),
                 IDS_FLOWCONTROL,
                 DEF_SHAKE,
                 FALSE);

    return 0;

} /* FillCommDlg */
コード例 #13
0
ファイル: registry.cpp プロジェクト: tantaishan/MyEcho
bool Registry::SetValue(const tstring& key, int value)
{
	TCHAR szValue[MAX_PATH] = { 0 };
	_itot_s(value, szValue, 10);
	return SetValue(key, szValue);
}
コード例 #14
0
ファイル: sproxy.cpp プロジェクト: Fluffiest/splayer
//////////////////////////////////////////////////////////////////////////
//Purpose: Searches for a resource dll in sub directories using a search order
//		   based on szPath - a directory to search res dll below.
//		   see example at .
//Input: szDllName - the string resource dll name to search. Ex: ToolUI.dll 
//Output: TCHAR *szPathOut - filled with absolute path to dll, if found.
//		  size_t sizeInCharacters - buffer size in characters
//Returns: Success (found dll) - S_OK , Failure - E_FAIL or E_UNEXPECTED
//////////////////////////////////////////////////////////////////////////
HRESULT LoadUILibrary(LPCTSTR szPath, LPCTSTR szDllName, DWORD dwExFlags, 
                      HINSTANCE *phinstOut, LPTSTR szFullPathOut,size_t sizeInCharacters,
                      LCID *plcidOut)
{
    TCHAR szPathTemp[_MAX_PATH + 1] = _T("");
    HRESULT hr = E_FAIL;
    LCID lcidFound = (LCID)-1;
    size_t nPathEnd = 0;

    // Gotta have this stuff!
	if (szPath==NULL || *szPath == '\0')	   
	{ 
		return E_POINTER; 
	}

    if (szDllName==NULL || *szDllName == '\0') 
	{ 
		return E_POINTER; 
	}

    if (!szPath || !*szPath || !szDllName || !*szDllName)
	{
        return E_INVALIDARG;
	}

    if (phinstOut != NULL)
    {
        *phinstOut = NULL;
    }

    szPathTemp[_MAX_PATH-1] = L'\0';

    // Add \ to the end if necessary
    _tcsncpy_s(szPathTemp,_countof(szPathTemp), szPath, _MAX_PATH-1);
    if (szPathTemp[_TCSNLEN(szPathTemp, _MAX_PATH-1) - 1] != L'\\')
    {
        _tcsncat_s(szPathTemp,_countof(szPathTemp), _T("\\"), PATHLEFT(szPathTemp));
    }

    // Check if given path even exists
    if (GetFileAttributes(szPathTemp) == 0xFFFFFFFF)
	{
        return E_FAIL;
	}

    nPathEnd = _TCSNLEN(szPathTemp, _MAX_PATH-1);
    
    {	        
		LANGID langid=0;
		if (FAILED(GetUserDefaultUILanguageLegacyCompat(&langid)))
		{
			return E_UNEXPECTED;
		}
        const LCID lcidUser = MAKELCID(langid, SORT_DEFAULT);
        
        LCID rglcid[3];
        rglcid[0] = lcidUser;
        rglcid[1] = MAKELCID(MAKELANGID(PRIMARYLANGID(lcidUser), SUBLANG_DEFAULT), SORTIDFROMLCID(lcidUser));
        rglcid[2] = 0x409;
        for (int i = 0; i < _countof(rglcid); i++)
        {
            TCHAR szNumBuf[10];
            
            // Check if it's the same as any LCID already checked,
            // which is very possible
			int n = 0;
            for (n = 0; n < i; n++)
            {
                if (rglcid[n] == rglcid[i])
                    break;
            }

            if (n < i)
			{
                continue;
			}
            
            szPathTemp[nPathEnd] = L'\0';
			_itot_s(rglcid[i], szNumBuf,_countof(szNumBuf), 10);
            _tcsncat_s(szPathTemp, _countof(szPathTemp),szNumBuf , PATHLEFT(szPathTemp));
            _tcsncat_s(szPathTemp,_countof(szPathTemp), _T("\\"), PATHLEFT(szPathTemp));
            _tcsncat_s(szPathTemp,_countof(szPathTemp), szDllName, PATHLEFT(szPathTemp));

            if (GetFileAttributes(szPathTemp) != 0xFFFFFFFF)
            {
                lcidFound = rglcid[i];

                hr = S_OK;
                goto Done;
            }
        }
    }

    // None of the default choices exists, so now look for the dll in a folder below
	//the given path (szPath)
    {        
        szPathTemp[nPathEnd] = L'\0';
        _tcsncat_s(szPathTemp,_countof(szPathTemp), _T("*.*"), PATHLEFT(szPathTemp));

		WIN32_FIND_DATA wfdw;
        HANDLE hDirs = FindFirstFile(szPathTemp, &wfdw);
        nPathEnd = _TCSNLEN(szPathTemp, _MAX_PATH-1)-3;
        if (hDirs != INVALID_HANDLE_VALUE)
        {
            while (FindNextFile(hDirs, &wfdw))
            {
                // We are only interested in directories, since at this level, that should
                // be the only thing in this directory, i.e, LCID sub dirs
                if (wfdw.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
                {
                    // Skip current and previous dirs, "." and ".."
                    if (!_tcscmp(wfdw.cFileName, _T(".")) || !_tcscmp(wfdw.cFileName, _T("..")))
                        continue;

                    // Does this dir have a copy of the dll?
                    szPathTemp[nPathEnd] = L'\0';
                    _tcsncat_s(szPathTemp,_countof(szPathTemp), wfdw.cFileName, PATHLEFT(szPathTemp));
                    _tcsncat_s(szPathTemp,_countof(szPathTemp), _T("\\"), PATHLEFT(szPathTemp));
                    _tcsncat_s(szPathTemp,_countof(szPathTemp), szDllName, PATHLEFT(szPathTemp));

                    if (GetFileAttributes(szPathTemp) != 0xFFFFFFFF)
                    {
                        // Got it!
                        lcidFound = (LCID)_tstol(wfdw.cFileName);

                        hr = S_OK;
                        break;
                    }
                }
            }

            FindClose(hDirs);
        }
    }

Done:
    if (SUCCEEDED(hr))
    {
        // Set the default LCID
        if (plcidOut)
        {
			if (lcidFound == (LCID)-1) 
			{ 
				return E_UNEXPECTED; 
			}
            *plcidOut = lcidFound;
        }

        // Finally, attempt to load the library
        // Beware!  A dll loaded with LOAD_LIBRARY_AS_DATAFILE won't
        // let you use LoadIcon and things like that (only general calls like
        // FindResource and LoadResource).
        if (phinstOut != NULL)
        {
            *phinstOut = LoadLibraryEx(szPathTemp, NULL, dwExFlags);
            hr = (*phinstOut) ? S_OK : E_FAIL;
        }
        if ( szFullPathOut )
		{
            _tcsncpy_s(szFullPathOut,sizeInCharacters, szPathTemp, _MAX_PATH-1);
		}
    }
 
    return hr;
}
コード例 #15
0
ファイル: PropDlg.cpp プロジェクト: Jinjiego/VCSamples
LRESULT CPropDlg::OnSelChanged(int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/)
{
	const int bufsize=128;
	ATLTRACE(_T("CPropDlg::OnSelChanged()\n"));
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pnmh;
	TCHAR buf[bufsize] = _T("");
	::EnableWindow(GetDlgItem(IDC_APPLY), FALSE);

	m_nCurSel = (int)(pNMTreeView->itemNew.lParam);

	switch(m_nCurSel)
	{
	case 0: // Fire
		SetDlgItemText(IDC_EDIT1,_T(""));
		::EnableWindow(m_hSetting,FALSE);
		::EnableWindow(m_hSettingCtl,FALSE);
		break;
	case 1: // Decay
		_itot_s(m_nDecay,buf,bufsize,10);
		SetDlgItemText(IDC_EDIT1,buf);
		::SendMessage(m_hSettingCtl,UDM_SETRANGE, 0, MAKELONG(1,100));
		::EnableWindow(m_hSettingCtl,TRUE);
		::EnableWindow(m_hSetting,TRUE);
		break;
	case 2: // Flammability
		_itot_s(m_nFlammability,buf,bufsize,10);
		SetDlgItemText(IDC_EDIT1,buf);
		::SendMessage(m_hSettingCtl,UDM_SETRANGE, 0, MAKELONG(1,399));
		::EnableWindow(m_hSettingCtl,TRUE);
		::EnableWindow(m_hSetting,TRUE);
		break;
	case 3: // Maximum Heat
		_itot_s(m_nMaxHeat,buf,bufsize,10);
		SetDlgItemText(IDC_EDIT1,buf);
		::SendMessage(m_hSettingCtl,UDM_SETRANGE, 0, MAKELONG(0,223));
		::EnableWindow(m_hSettingCtl,TRUE);
		::EnableWindow(m_hSetting,TRUE);
		break;
	case 4: // Spread Rate
		_itot_s(m_nSpreadRate,buf,bufsize,10);
		SetDlgItemText(IDC_EDIT1,buf);
		::SendMessage(m_hSettingCtl,UDM_SETRANGE, 0, MAKELONG(1,100));
		::EnableWindow(m_hSettingCtl,TRUE);
		::EnableWindow(m_hSetting,TRUE);
		break;
	case 5: // Size
		_itot_s(m_nSize,buf,bufsize,10);
		SetDlgItemText(IDC_EDIT1,buf);
		::SendMessage(m_hSettingCtl,UDM_SETRANGE, 0, MAKELONG(1,m_Display->bmSize.cx - 1));
		::EnableWindow(m_hSettingCtl,TRUE);
		::EnableWindow(m_hSetting,TRUE);
		break;
	case 6: // Smoothness
		_itot_s(m_nSmoothness,buf,bufsize,10);
		SetDlgItemText(IDC_EDIT1,buf);
		::SendMessage(m_hSettingCtl,UDM_SETRANGE, 0, MAKELONG(0,5));
		::EnableWindow(m_hSettingCtl,TRUE);
		::EnableWindow(m_hSetting,TRUE);
		break;
	case 7: // Distribution
		_itot_s(m_nDistribution,buf,bufsize,10);
		SetDlgItemText(IDC_EDIT1,buf);
		::SendMessage(m_hSettingCtl,UDM_SETRANGE, 0, MAKELONG(0,10));
		::EnableWindow(m_hSettingCtl,TRUE);
		::EnableWindow(m_hSetting,TRUE);
		break;
	case 8: // Chaos
		_itot_s(m_nChaos,buf,bufsize,10);
		SetDlgItemText(IDC_EDIT1,buf);
		::SendMessage(m_hSettingCtl,UDM_SETRANGE, 0, MAKELONG(1,100));
		::EnableWindow(m_hSettingCtl,TRUE);
		::EnableWindow(m_hSetting,TRUE);
		break;
	}

	return 0;
}
コード例 #16
0
ファイル: Registry.cpp プロジェクト: ldw9981/Rendering
BOOL Registry::WriteIntToINI( LPCTSTR lpFileName,LPCTSTR lpSectionName,LPCTSTR lpKeyName,INT nValue )
{
	TCHAR buffer[1024]={0,};
	_itot_s(nValue,&buffer[0],1024,10);
	return WriteStringToINI(lpFileName,lpSectionName,lpKeyName,buffer);
}
コード例 #17
0
ファイル: CdllInjectDoc.cpp プロジェクト: rheech/dll-injector
void CdllInjectDoc::updateProcList(CListCtrl* lv, LPCTSTR imgName, LPSTR dllName)
{
	// create Process Snapshot
	HANDLE hSnapshot;
	hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);

	PROCESSENTRY32 pe = {sizeof(PROCESSENTRY32)};

	// first snapshot
	Process32First(hSnapshot, &pe);
	
	// index, pid string
	int index = 0;
	
	TCHAR pid[20];
	TCHAR emptyPid[20] = {0};

	wsprintf(pid, _T("%d"), pe.th32ProcessID);

	// 1st, 2nd item text (exe file, pid)
	CString first, second;
	first = lv->GetItemText(0, 0);
	second = lv->GetItemText(0, 1);

	// update first process information
	if (pe.th32ProcessID != _ttoi(second.GetBuffer(0)) ||
			_tcsicmp(pe.szExeFile, first.GetBuffer(0)) != 0)
	{
		lv->DeleteItem(0);
		index = lv->InsertItem(0, pe.szExeFile);
		lv->SetItem(index, 1, LVIF_TEXT, pid, 0, 0, 0, NULL);
	}

	// check automatic inject option
	if (imgName != NULL &&
			_tcsicmp(imgName,pe.szExeFile) == 0)
	{
		InjectDll(pe.th32ProcessID, dllName);
	}

	// empty pid string
	//memcpy_s(pid, 20, emptyPid, 20);

	// insert next items
	int i = index + 1;

	// update next process informations
	while(Process32Next(hSnapshot, &pe) != FALSE)
	{
		first = lv->GetItemText(i, 0);
		second = lv->GetItemText(i, 1);

		// check automatic inject option
		if (imgName != NULL &&
			_tcsicmp(imgName, pe.szExeFile) == 0)
		{
			// empty pid string
			memcpy_s(pid, 20, emptyPid, 20);

			_itot_s(pe.th32ProcessID, pid, 20, 10);

			CString temp;
			temp.Append(pe.szExeFile);
			temp += _T("|");
			temp.Append(pid);
			temp += _T("|");

			if (pidInfo.Find(temp, 0) != -1)
			{
				i++;
				continue;
			}

			TCHAR line[260];
			_stprintf_s(line, 260, _T("Injecting %s(%d)... "),
						pe.szExeFile, pe.th32ProcessID);

			writeLog(CString(line));

			if (InjectDll(pe.th32ProcessID, dllName) == TRUE)
			{
				writeLog(CString("SUCCEED.\r\n"));
				pidInfo += temp;
			}
			else
				writeLog(CString("FAILED.\r\n"));
		}

		// if already in listview, skip
		if (pe.th32ProcessID == _ttoi(second.GetBuffer(0)) &&
				_tcsicmp(pe.szExeFile, first.GetBuffer(0)) == 0)
		{
			i++;
			continue;
		}

		// delete old process info, and inform that is exited & delete from injection list
		CString temp;
		temp = first + _T("|") + second + _T("|");

		if (pidInfo.Find(temp) != -1)
		{
			CString output;
			output = _T("Process Exited: ") + first 
				+ _T("(") + second + _T(").")
				+ _T("\r\n");

			writeLog(output);

			pidInfo.Replace(temp, _T(""));
		}


		lv->DeleteItem(i);
		index = lv->InsertItem(i, pe.szExeFile);
		wsprintf(pid, _T("%d"), pe.th32ProcessID);
		lv->SetItem(index, 1, LVIF_TEXT, pid, 0, 0, 0, NULL);

		i++;
	}

	CloseHandle(hSnapshot);

	// if listcount is more than process list, delete records
	while (i < lv->GetItemCount())
	{
		// delete old process info, and inform that is exited & delete from injection list
		first = lv->GetItemText(i, 0);
		second = lv->GetItemText(i, 1);

		CString temp;
		temp = first + _T("|") + second + _T("|");

		if (pidInfo.Find(temp) != -1)
		{
			CString output;
			output = _T("Process Exited: ") + first 
					+ _T("(") + second + _T(").")
					+ _T("\r\n");

			writeLog(output);

			pidInfo.Replace(temp, _T(""));
		}

		lv->DeleteItem(i);

		i++;
	}
}
コード例 #18
0
ファイル: cpuusage.cpp プロジェクト: biddyweb/miranda-ng
static void WinNT_PollThread(void *vparam)
{
	CpuUsageThreadParams *param = (CpuUsageThreadParams*)vparam;

	DWORD dwBufferSize=0,dwCount;
	BYTE *pBuffer=NULL;
	PERF_DATA_BLOCK *pPerfData=NULL; 
	LONG res,lCount;
	PERF_OBJECT_TYPE *pPerfObj;
	PERF_COUNTER_DEFINITION *pPerfCounter; 
	PERF_INSTANCE_DEFINITION *pPerfInstance; 
	PERF_COUNTER_BLOCK *pPerfCounterBlock;
	DWORD dwObjectId,dwCounterId; 
	WCHAR wszValueName[11],*pwszInstanceName;
	BYTE nCpuUsage;
	BOOL fSwitched,fFound,fIsFirst=FALSE;
	LARGE_INTEGER liPrevCounterValue={0},liCurrentCounterValue={0},liPrevPerfTime100nSec={0};

	/* init */
	dwObjectId=238;             /*'Processor' object */
	dwCounterId=6;              /* '% processor time' counter */
	pwszInstanceName=L"_Total"; /* '_Total' instance */
	_itot_s(dwObjectId, wszValueName, 10);
	fSwitched = WinNT_PerfStatsSwitch(_T("PerfOS"), FALSE);

	/* poll */
	for(;;) {
		/* retrieve data for given object */
		res=RegQueryValueExW(HKEY_PERFORMANCE_DATA,wszValueName,NULL,NULL,(BYTE*)pPerfData,&dwBufferSize);
		while(!pBuffer || res==ERROR_MORE_DATA) {
			pBuffer=(BYTE*)mir_realloc(pPerfData,dwBufferSize+=256);
			if (!pBuffer) break;
			pPerfData=(PERF_DATA_BLOCK*)pBuffer;
			res=RegQueryValueExW(HKEY_PERFORMANCE_DATA,wszValueName,NULL,NULL,pBuffer,&dwBufferSize);
		}
		if (res != ERROR_SUCCESS) break;

		/* find object in data */
		fFound=FALSE;
		/* first object */
		pPerfObj=(PERF_OBJECT_TYPE*)((BYTE*)pPerfData+pPerfData->HeaderLength);
		for(dwCount=0;dwCount<pPerfData->NumObjectTypes;++dwCount) {
			if (pPerfObj->ObjectNameTitleIndex==dwObjectId) {
				/* find counter in object data */
				/* first counter */
				pPerfCounter=(PERF_COUNTER_DEFINITION*)((BYTE*)pPerfObj+pPerfObj->HeaderLength);
				for(dwCount=0;dwCount<(pPerfObj->NumCounters);++dwCount) { 
					if (pPerfCounter->CounterNameTitleIndex==dwCounterId) {
						/* find instance in counter data */
						if (pPerfObj->NumInstances==PERF_NO_INSTANCES) { 
							pPerfCounterBlock=(PERF_COUNTER_BLOCK*)((BYTE*)pPerfObj+pPerfObj->DefinitionLength);
							liCurrentCounterValue=*(LARGE_INTEGER*)((BYTE*)pPerfCounterBlock+pPerfCounter->CounterOffset);
							fFound=TRUE;
						}
						else {
							/* first instance */
							pPerfInstance=(PERF_INSTANCE_DEFINITION*)((BYTE*)pPerfObj+pPerfObj->DefinitionLength);
							for(lCount=0;lCount<(pPerfObj->NumInstances);++lCount) {
								pPerfCounterBlock=(PERF_COUNTER_BLOCK*)((BYTE*)pPerfInstance+pPerfInstance->ByteLength);
								if (!mir_wstrcmpi(pwszInstanceName,(WCHAR*)((BYTE*)pPerfInstance+pPerfInstance->NameOffset))) {
									liCurrentCounterValue=*(LARGE_INTEGER*)((BYTE*)pPerfCounterBlock+pPerfCounter->CounterOffset);
									fFound=TRUE;
									break;
								}
								/* next instance */
								pPerfInstance=(PPERF_INSTANCE_DEFINITION)((BYTE*)pPerfCounterBlock+pPerfCounterBlock->ByteLength);
							} 
						} 
						break;
					}
					/* next counter */
					pPerfCounter=(PERF_COUNTER_DEFINITION*)((BYTE*)pPerfCounter+pPerfCounter->ByteLength);
				}
				break; 
			} 
			/* next object */
			pPerfObj=(PERF_OBJECT_TYPE*)((BYTE*)pPerfObj+pPerfObj->TotalByteLength);
		}
		if (!fFound) break;

		/* calc val from data, we need two samplings
		 * counter type: PERF_100NSEC_TIMER_INV
		 * calc: time base=100Ns, value=100*(1-(data_diff)/(100NsTime_diff)) */
		if (!fIsFirst) {
			nCpuUsage=(BYTE)((1.0-(Li2Double(liCurrentCounterValue)-Li2Double(liPrevCounterValue))/(Li2Double(pPerfData->PerfTime100nSec)-Li2Double(liPrevPerfTime100nSec)))*100.0+0.5);
			if (!CallBackAndWait(param,nCpuUsage)) break;
		}
		else fIsFirst=FALSE;
		/* store current sampling for next */
		memcpy(&liPrevCounterValue,&liCurrentCounterValue,sizeof(LARGE_INTEGER)); 
		memcpy(&liPrevPerfTime100nSec,&pPerfData->PerfTime100nSec,sizeof(LARGE_INTEGER)); 
	}

	/* uninit */
	if (pPerfData) mir_free(pPerfData);
	if (fSwitched) WinNT_PerfStatsSwitch(_T("PerfOS"),TRUE);

	/* return error for PollCpuUsage() if never succeeded */
	if (param->hFirstEvent != NULL) SetEvent(param->hFirstEvent);
	mir_free(param);
} 
コード例 #19
0
/**
 * @param strLogText - error log text.
 */
void CExpressModeDlg::GetErrorLog(CString& strLogText)
{
	strLogText.Empty();
	if (! m_pXMLElementDocument)
		return;
	HRESULT hRes;

	static const TCHAR szDividerMsg[] = _T("----------------------------------------\r\n");
	static const TCHAR szNewLine[] = _T("\r\n");

	CString strApplication;
	GetXMLNodeText(m_pXMLElementDocument, OLESTR("./application"), strApplication);
	if (! strApplication.IsEmpty())
	{
		static const TCHAR szAppMsg[] = _T("Application: ");

		strLogText += szAppMsg;
		strLogText += strApplication;
		strLogText += szNewLine;
	}

	CString strVersion;
	GetXMLNodeText(m_pXMLElementDocument, OLESTR("./version"), strVersion);
	if (! strVersion.IsEmpty())
	{
		static const TCHAR szVersionMsg[] = _T("Version: ");

		strLogText += szVersionMsg;
		strLogText += strVersion;
		strLogText += szNewLine;
	}

	CString strComputer;
	GetXMLNodeText(m_pXMLElementDocument, OLESTR("./computer"), strComputer);
	if (! strComputer.IsEmpty())
	{
		static const TCHAR szComputerNameMsg[] = _T("Computer: ");

		strLogText += szComputerNameMsg;
		strLogText += strComputer;
		strLogText += szNewLine;
	}

	CString strUser;
	GetXMLNodeText(m_pXMLElementDocument, OLESTR("./user"), strUser);
	if (! strUser.IsEmpty())
	{
		static const TCHAR szUserNameMsg[] = _T("User: "******"./timestamp"), strTimeStamp);
	if (! strTimeStamp.IsEmpty())
	{
		ULONGLONG uiTimeStamp = _tcstoui64(strTimeStamp, NULL, 0);
		if (uiTimeStamp != 0)
		{
			GetDateTimeString(uiTimeStamp, strTimeStamp);
			if (! strTimeStamp.IsEmpty())
			{
				static const TCHAR szDateTimeMsg[] = _T("Date: ");

				strLogText += szDateTimeMsg;
				strLogText += strTimeStamp;
				strLogText += szNewLine;
			}
		}
	}

	CString strErrorReason;
	GetErrorReason(strErrorReason);
	if (! strErrorReason.IsEmpty())
	{
		static const TCHAR szErrorMsg[] = _T("\r\nError Reason:\r\n");

		strLogText += szErrorMsg;
		strLogText += szDividerMsg;
		strLogText += strErrorReason;
	}

	CString strUserMessage;
	if (GetXMLNodeText(m_pXMLElementDocument, OLESTR("./usermsg"), strUserMessage) &&
		! strUserMessage.IsEmpty())
	{
		static const TCHAR szUserMsg[] = _T("\r\n\r\nUser Message:\r\n");

		strLogText += szUserMsg;
		strLogText += szDividerMsg;
		strLogText += strUserMessage;
	}

	CComPtr<IXMLDOMNode> pXMLNodeSysError;
	if (SelectXMLNode(m_pXMLElementDocument, OLESTR("./syserror"), pXMLNodeSysError))
	{
		CString strSysErrorCode;
		GetXMLNodeText(pXMLNodeSysError, OLESTR("./code"), strSysErrorCode);
		if (! strSysErrorCode.IsEmpty())
		{
			static const TCHAR szSysErrorMsg[] = _T("\r\n\r\nSystem Error:\r\n");

			strLogText += szSysErrorMsg;
			strLogText += szDividerMsg;
			strLogText += strSysErrorCode;

			CString strSysErrorDescription;
			GetXMLNodeText(pXMLNodeSysError, OLESTR("./description"), strSysErrorDescription);
			if (! strSysErrorDescription.IsEmpty())
			{
				strLogText += _T(" - ");
				strLogText += strSysErrorDescription;
			}
		}
	}

	CComPtr<IXMLDOMNode> pXMLNodeComError;
	if (SelectXMLNode(m_pXMLElementDocument, OLESTR("./comerror"), pXMLNodeComError))
	{
		CString strComErrorDescription;
		GetXMLNodeText(pXMLNodeComError, OLESTR("./description"), strComErrorDescription);
		CString strComErrorHelpFile;
		GetXMLNodeText(pXMLNodeComError, OLESTR("./helpfile"), strComErrorHelpFile);
		CString strComErrorSource;
		GetXMLNodeText(pXMLNodeComError, OLESTR("./source"), strComErrorSource);
		CString strComErrorGuid;
		GetXMLNodeText(pXMLNodeComError, OLESTR("./guid"), strComErrorGuid);

		if (! strComErrorDescription.IsEmpty() ||
			! strComErrorHelpFile.IsEmpty() ||
			! strComErrorSource.IsEmpty() ||
			! strComErrorGuid.IsEmpty())
		{
			static const TCHAR szCOMErrorMsg[] = _T("\r\n\r\nCOM Error:\r\n");
			static const TCHAR szDescriptionMsg[] = _T("Description: ");
			static const TCHAR szHelpFileMsg[] = _T("Help File:   ");
			static const TCHAR szSourceMsg[] = _T("Source:      ");
			static const TCHAR szGuidMsg[] = _T("GUID:        ");

			strLogText += szCOMErrorMsg;
			strLogText += szDividerMsg;

			BOOL bNotEmpty = FALSE;

			if (! strComErrorDescription.IsEmpty())
			{
				bNotEmpty = TRUE;
				strLogText += szDescriptionMsg;
				strLogText += strComErrorDescription;
			}

			if (! strComErrorHelpFile.IsEmpty())
			{
				if (bNotEmpty)
					strLogText += szNewLine;
				else
					bNotEmpty = TRUE;
				strLogText += szHelpFileMsg;
				strLogText += strComErrorHelpFile;
			}

			if (! strComErrorSource.IsEmpty())
			{
				if (bNotEmpty)
					strLogText += szNewLine;
				else
					bNotEmpty = TRUE;
				strLogText += szSourceMsg;
				strLogText += strComErrorSource;
			}

			if (! strComErrorGuid.IsEmpty())
			{
				if (bNotEmpty)
					strLogText += szNewLine;
				else
					bNotEmpty = TRUE;
				strLogText += szGuidMsg;
				strLogText += strComErrorGuid;
			}
		}
	}

	CComPtr<IXMLDOMNode> pXMLNodeRegisters;
	if (SelectXMLNode(m_pXMLElementDocument, OLESTR("./registers"), pXMLNodeRegisters))
	{
		static const TCHAR szRegistersMsg[] = _T("\r\n\r\nRegisters:\r\n");

		CString strRegValue;

		switch (GetPlatform())
		{
		case TPLAT_X86:
			{
				GetXMLNodeText(pXMLNodeRegisters, OLESTR("./eax"), strRegValue);
				DWORD dwEAX = _tcstoul(strRegValue, NULL, 0);
				GetXMLNodeText(pXMLNodeRegisters, OLESTR("./ebx"), strRegValue);
				DWORD dwEBX = _tcstoul(strRegValue, NULL, 0);
				GetXMLNodeText(pXMLNodeRegisters, OLESTR("./ecx"), strRegValue);
				DWORD dwECX = _tcstoul(strRegValue, NULL, 0);
				GetXMLNodeText(pXMLNodeRegisters, OLESTR("./edx"), strRegValue);
				DWORD dwEDX = _tcstoul(strRegValue, NULL, 0);

				GetXMLNodeText(pXMLNodeRegisters, OLESTR("./esi"), strRegValue);
				DWORD dwESI = _tcstoul(strRegValue, NULL, 0);
				GetXMLNodeText(pXMLNodeRegisters, OLESTR("./edi"), strRegValue);
				DWORD dwEDI = _tcstoul(strRegValue, NULL, 0);
				GetXMLNodeText(pXMLNodeRegisters, OLESTR("./esp"), strRegValue);
				DWORD dwESP = _tcstoul(strRegValue, NULL, 0);
				GetXMLNodeText(pXMLNodeRegisters, OLESTR("./ebp"), strRegValue);
				DWORD dwEBP = _tcstoul(strRegValue, NULL, 0);
				GetXMLNodeText(pXMLNodeRegisters, OLESTR("./eip"), strRegValue);
				DWORD dwEIP = _tcstoul(strRegValue, NULL, 0);

				GetXMLNodeText(pXMLNodeRegisters, OLESTR("./cs"), strRegValue);
				DWORD dwCS = _tcstoul(strRegValue, NULL, 0);
				GetXMLNodeText(pXMLNodeRegisters, OLESTR("./ds"), strRegValue);
				DWORD dwDS = _tcstoul(strRegValue, NULL, 0);
				GetXMLNodeText(pXMLNodeRegisters, OLESTR("./ss"), strRegValue);
				DWORD dwSS = _tcstoul(strRegValue, NULL, 0);
				GetXMLNodeText(pXMLNodeRegisters, OLESTR("./es"), strRegValue);
				DWORD dwES = _tcstoul(strRegValue, NULL, 0);
				GetXMLNodeText(pXMLNodeRegisters, OLESTR("./fs"), strRegValue);
				DWORD dwFS = _tcstoul(strRegValue, NULL, 0);
				GetXMLNodeText(pXMLNodeRegisters, OLESTR("./gs"), strRegValue);
				DWORD dwGS = _tcstoul(strRegValue, NULL, 0);

				GetXMLNodeText(pXMLNodeRegisters, OLESTR("./eflags"), strRegValue);
				DWORD dwEFLAGS = _tcstoul(strRegValue, NULL, 0);

				strRegValue.Format(
					_T("EAX=%08X  EBX=%08X  ECX=%08X  EDX=%08X\r\n")
					_T("ESI=%08X  EDI=%08X  FLG=%08X\r\n")
					_T("EBP=%08X  ESP=%08X  EIP=%08X\r\n")
					_T("CS=%04X  DS=%04X  SS=%04X  ES=%04X  FS=%04X  GS=%04X"),
					dwEAX, dwEBX, dwECX, dwEDX,
					dwESI, dwEDI, dwEFLAGS,
					dwEBP, dwESP, dwEIP,
					dwCS, dwDS, dwSS, dwES, dwFS, dwGS);
			}
			break;
		case TPLAT_X64:
			{
				GetXMLNodeText(pXMLNodeRegisters, OLESTR("./rax"), strRegValue);
				DWORD dwRAX = _tcstoul(strRegValue, NULL, 0);
				GetXMLNodeText(pXMLNodeRegisters, OLESTR("./rbx"), strRegValue);
				DWORD dwRBX = _tcstoul(strRegValue, NULL, 0);
				GetXMLNodeText(pXMLNodeRegisters, OLESTR("./rcx"), strRegValue);
				DWORD dwRCX = _tcstoul(strRegValue, NULL, 0);
				GetXMLNodeText(pXMLNodeRegisters, OLESTR("./rdx"), strRegValue);
				DWORD dwRDX = _tcstoul(strRegValue, NULL, 0);

				GetXMLNodeText(pXMLNodeRegisters, OLESTR("./rsi"), strRegValue);
				DWORD dwRSI = _tcstoul(strRegValue, NULL, 0);
				GetXMLNodeText(pXMLNodeRegisters, OLESTR("./rdi"), strRegValue);
				DWORD dwRDI = _tcstoul(strRegValue, NULL, 0);
				GetXMLNodeText(pXMLNodeRegisters, OLESTR("./rsp"), strRegValue);
				DWORD dwRSP = _tcstoul(strRegValue, NULL, 0);
				GetXMLNodeText(pXMLNodeRegisters, OLESTR("./rbp"), strRegValue);
				DWORD dwRBP = _tcstoul(strRegValue, NULL, 0);
				GetXMLNodeText(pXMLNodeRegisters, OLESTR("./rip"), strRegValue);
				DWORD dwRIP = _tcstoul(strRegValue, NULL, 0);

				GetXMLNodeText(pXMLNodeRegisters, OLESTR("./cs"), strRegValue);
				DWORD dwCS = _tcstoul(strRegValue, NULL, 0);
				GetXMLNodeText(pXMLNodeRegisters, OLESTR("./ds"), strRegValue);
				DWORD dwDS = _tcstoul(strRegValue, NULL, 0);
				GetXMLNodeText(pXMLNodeRegisters, OLESTR("./ss"), strRegValue);
				DWORD dwSS = _tcstoul(strRegValue, NULL, 0);
				GetXMLNodeText(pXMLNodeRegisters, OLESTR("./es"), strRegValue);
				DWORD dwES = _tcstoul(strRegValue, NULL, 0);
				GetXMLNodeText(pXMLNodeRegisters, OLESTR("./fs"), strRegValue);
				DWORD dwFS = _tcstoul(strRegValue, NULL, 0);
				GetXMLNodeText(pXMLNodeRegisters, OLESTR("./gs"), strRegValue);
				DWORD dwGS = _tcstoul(strRegValue, NULL, 0);

				GetXMLNodeText(pXMLNodeRegisters, OLESTR("./eflags"), strRegValue);
				DWORD dwEFLAGS = _tcstoul(strRegValue, NULL, 0);

				strRegValue.Format(
					_T("RAX=%016X  RBX=%016X\r\n")
					_T("RCX=%016X  RDX=%016X\r\n")
					_T("RSI=%016X  RDI=%016X\r\n")
					_T("FLG=%08X          RBP=%016X\r\n")
					_T("RSP=%016X  RIP=%016X\r\n")
					_T("CS=%04X  DS=%04X  SS=%04X  ES=%04X  FS=%04X  GS=%04X"),
					dwRAX, dwRBX, dwRCX, dwRDX,
					dwRSI, dwRDI, dwEFLAGS,
					dwRBP, dwRSP, dwRIP,
					dwCS, dwDS, dwSS, dwES, dwFS, dwGS);
			}
			break;
		default:
			_ASSERT(FALSE);
		}

		strLogText += szRegistersMsg;
		strLogText += szDividerMsg;
		strLogText += strRegValue;
	}

	CComPtr<IXMLDOMNode> pXMLNodeCpus;
	if (SelectXMLNode(m_pXMLElementDocument, OLESTR("./cpus"), pXMLNodeCpus))
	{
		CString strNumCpus;
		GetXMLNodeText(pXMLNodeCpus, OLESTR("./number"), strNumCpus);
		if (! strNumCpus.IsEmpty() && _tcstoul(strNumCpus, NULL, 0) != 0)
		{
			static const TCHAR szCpuMsg[] = _T("\r\n\r\nCPU:\r\n");
			static const TCHAR szArchitectureMsg[] = _T("Architecture: ");
			static const TCHAR szNumCpusMsg[] = _T("Number of Processors:  ");
			static const TCHAR szCpuDescriptionsMsg[] = _T("\r\nProcessors Descriptions:");

			strLogText += szCpuMsg;
			strLogText += szDividerMsg;

			CString strArchitecture;
			GetXMLNodeText(pXMLNodeCpus, OLESTR("./architecture"), strArchitecture);
			if (! strArchitecture.IsEmpty())
			{
				strLogText += szArchitectureMsg;
				strLogText += strArchitecture;
				strLogText += szNewLine;
			}

			strLogText += szNumCpusMsg;
			strLogText += strNumCpus;
			strLogText += szCpuDescriptionsMsg;

			CString strCpuDescription;
			CComPtr<IXMLDOMNodeList> pXMLNodeListCpus;
			if (SelectXMLNodes(pXMLNodeCpus, OLESTR("./cpu"), pXMLNodeListCpus))
			{
				for (int iItemPos = 1; ; ++iItemPos)
				{
					CComPtr<IXMLDOMNode> pXMLNodeCpu;
					hRes = pXMLNodeListCpus->nextNode(&pXMLNodeCpu);
					CHECK_HRESULT(hRes);
					if (hRes != S_OK)
						break;

					GetXMLNodeText(pXMLNodeCpu, OLESTR("./description"), strCpuDescription);
					TCHAR szItemPos[16];
					_itot_s(iItemPos, szItemPos, countof(szItemPos), 10);

					strLogText += szNewLine;
					strLogText += szItemPos;
					strLogText += _T(". ");
					strLogText += strCpuDescription;
				}
			}
		}
	}

	CComPtr<IXMLDOMNode> pXMLNodeOs;
	if (SelectXMLNode(m_pXMLElementDocument, OLESTR("./os"), pXMLNodeOs))
	{
		static const TCHAR szOSMsg[] = _T("\r\n\r\nOperating System:\r\n");
		static const TCHAR szOsVersionMsg[] = _T("OS Version:    ");
		static const TCHAR szBuildNumberMsg[] = _T("Build Number:  ");

		CString strOsVersion;
		GetXMLNodeText(pXMLNodeOs, OLESTR("./version"), strOsVersion);
		CString strServicePack;
		GetXMLNodeText(pXMLNodeOs, OLESTR("./spack"), strServicePack);
		CString strBuildNumber;
		GetXMLNodeText(pXMLNodeOs, OLESTR("./build"), strBuildNumber);

		strLogText += szOSMsg;
		strLogText += szDividerMsg;
		strLogText += szOsVersionMsg;
		strLogText += strOsVersion;
		if (! strServicePack.IsEmpty())
		{
			strLogText += _T(' ');
			strLogText += strServicePack;
		}
		strLogText += szNewLine;
		strLogText += szBuildNumberMsg;
		strLogText += strBuildNumber;
	}

	CComPtr<IXMLDOMNode> pXMLNodeMemory;
	if (SelectXMLNode(m_pXMLElementDocument, OLESTR("./memory"), pXMLNodeMemory))
	{
		static const TCHAR szMemMsg[] = _T("\r\n\r\nMemory Usage:\r\n");

		CString strMemValue;

		GetXMLNodeText(pXMLNodeMemory, OLESTR("./load"), strMemValue);
		DWORD dwCurMemLoad = _tcstoul(strMemValue, NULL, 0);
		GetXMLNodeText(pXMLNodeMemory, OLESTR("./totalphys"), strMemValue);
		DWORD dwTotalPhysMem = _tcstoul(strMemValue, NULL, 0);
		GetXMLNodeText(pXMLNodeMemory, OLESTR("./availphys"), strMemValue);
		DWORD dwAvailPhysMem = _tcstoul(strMemValue, NULL, 0);
		GetXMLNodeText(pXMLNodeMemory, OLESTR("./totalpage"), strMemValue);
		DWORD dwTotalPageMem = _tcstoul(strMemValue, NULL, 0);
		GetXMLNodeText(pXMLNodeMemory, OLESTR("./availpage"), strMemValue);
		DWORD dwAvailPageMem = _tcstoul(strMemValue, NULL, 0);

		strMemValue.Format(
			_T("Current Memory Load:         %lu%%\r\n")
			_T("Total Physical Memory:       %lu MB\r\n")
			_T("Available Physical Memory:   %lu MB\r\n")
			_T("Total Page File Memory:      %lu MB\r\n")
			_T("Available Page File Memory:  %lu MB"),
			dwCurMemLoad,
			dwTotalPhysMem / (1024 * 1024),
			dwAvailPhysMem / (1024 * 1024),
			dwTotalPageMem / (1024 * 1024),
			dwAvailPageMem / (1024 * 1024));

		strLogText += szMemMsg;
		strLogText += szDividerMsg;
		strLogText += strMemValue;
	}

	CStackEntry StackEntry;
	CComPtr<IXMLDOMNodeList> pXMLNodeListThreads;
	if (SelectXMLNodes(m_pXMLElementDocument, OLESTR("./threads/thread"), pXMLNodeListThreads))
	{
		static const TCHAR szTraceMsg[] = _T("\r\nStack Trace: ");
		static const TCHAR szThreadIDMsg[] = _T(", TID: ");
		static const TCHAR szThreadMsg[] = _T(" Thread");

		strLogText += szNewLine;

		CString strThreadID, strThreadStatus;
		for (;;)
		{
			CComPtr<IXMLDOMNode> pXMLNodeThread;
			hRes = pXMLNodeListThreads->nextNode(&pXMLNodeThread);
			CHECK_HRESULT(hRes);
			if (hRes != S_OK)
				break;

			GetXMLNodeText(pXMLNodeThread, OLESTR("./id"), strThreadID);
			GetXMLNodeText(pXMLNodeThread, OLESTR("./status"), strThreadStatus);
			if (! strThreadStatus.IsEmpty())
			{
				strThreadStatus.MakeLower();
				strThreadStatus.SetAt(0, (TCHAR)_totupper(strThreadStatus.GetAt(0)));
				strThreadStatus += szThreadMsg;
			}

			strLogText += szTraceMsg;
			strLogText += strThreadStatus;
			strLogText += szThreadIDMsg;
			strLogText += strThreadID;
			strLogText += szNewLine;
			strLogText += szDividerMsg;

			CComPtr<IXMLDOMNodeList> pXMLNodeListStackFrames;
			if (SelectXMLNodes(pXMLNodeThread, OLESTR("./stack/frame"), pXMLNodeListStackFrames))
			{
				for (;;)
				{
					CComPtr<IXMLDOMNode> pXMLNodeStackFrame;
					hRes = pXMLNodeListStackFrames->nextNode(&pXMLNodeStackFrame);
					CHECK_HRESULT(hRes);
					if (hRes != S_OK)
						break;
					GetStackEntry(pXMLNodeStackFrame, StackEntry);

					if (! StackEntry.m_strModule.IsEmpty())
					{
						strLogText += _T('\"');
						strLogText += StackEntry.m_strModule;
						strLogText += _T('\"');
					}
					if (! StackEntry.m_strAddress.IsEmpty())
					{
						strLogText += _T(" at ");
						strLogText += StackEntry.m_strAddress;
					}
					if (! StackEntry.m_strFunctionInfo.IsEmpty())
					{
						strLogText += _T(", ");
						strLogText += StackEntry.m_strFunctionInfo;
					}

					if (! StackEntry.m_strSourceFile.IsEmpty())
					{
						strLogText += _T(" in ");
						strLogText += StackEntry.m_strSourceFile;
					}

					if (! StackEntry.m_strLineInfo.IsEmpty())
					{
						strLogText += _T(", ");
						strLogText += StackEntry.m_strLineInfo;
					}

					strLogText += szNewLine;
				}
			}
		}
	}

	CString strCommandLine;
	GetXMLNodeText(m_pXMLElementDocument, OLESTR("./cmdline"), strCommandLine);
	if (! strCommandLine.IsEmpty())
	{
		static const TCHAR szCommandLineMsg[] = _T("\r\nCommand Line:\r\n");

		strLogText += szCommandLineMsg;
		strLogText += szDividerMsg;
		strLogText += strCommandLine;
	}

	CString strCurrentDirectory;
	GetXMLNodeText(m_pXMLElementDocument, OLESTR("./curdir"), strCurrentDirectory);
	if (! strCurrentDirectory.IsEmpty())
	{
		static const TCHAR szCurrentDirMsg[] = _T("\r\n\r\nCurrent Directory:\r\n");

		strLogText += szCurrentDirMsg;
		strLogText += szDividerMsg;
		strLogText += strCurrentDirectory;
	}

	CComPtr<IXMLDOMNodeList> pXMLNodeListEnvVars;
	if (SelectXMLNodes(m_pXMLElementDocument, OLESTR("./environment/variable"), pXMLNodeListEnvVars))
	{
		static const TCHAR szEnvironmentMsg[] = _T("\r\n\r\nEnvironment Variables:\r\n");

		strLogText += szEnvironmentMsg;
		strLogText += szDividerMsg;

		CString strVarName, strVarValue;
		for (;;)
		{
			CComPtr<IXMLDOMNode> pXMLNodeEnvVar;
			hRes = pXMLNodeListEnvVars->nextNode(&pXMLNodeEnvVar);
			CHECK_HRESULT(hRes);
			if (hRes != S_OK)
				break;

			GetXMLNodeText(pXMLNodeEnvVar, OLESTR("./name"), strVarName);
			GetXMLNodeText(pXMLNodeEnvVar, OLESTR("./value"), strVarValue);

			strLogText += strVarName;
			strLogText += _T('=');
			strLogText += strVarValue;
			strLogText += szNewLine;
		}
	}

	CComPtr<IXMLDOMNodeList> pXMLNodeListProcesses;
	if (SelectXMLNodes(m_pXMLElementDocument, OLESTR("./processes/process"), pXMLNodeListProcesses))
	{
		static const TCHAR szProcessMsg[] = _T("\r\nProcess: ");
		static const TCHAR szModulesMsg[] = _T(", Modules:\r\n");
		static const TCHAR szProcessIDMsg[] = _T(", PID: ");
		static const TCHAR szBaseMsg[] = _T(", Base: ");

		CString strProcessID, strProcessName, strModuleName, strModuleVersion, strModuleBase;
		for (;;)
		{
			CComPtr<IXMLDOMNode> pXMLNodeProcess;
			hRes = pXMLNodeListProcesses->nextNode(&pXMLNodeProcess);
			CHECK_HRESULT(hRes);
			if (hRes != S_OK)
				break;

			GetXMLNodeText(pXMLNodeProcess, OLESTR("./name"), strProcessName);
			GetXMLNodeText(pXMLNodeProcess, OLESTR("./id"), strProcessID);

			strLogText += szProcessMsg;
			strLogText += strProcessName;
			strLogText += szProcessIDMsg;
			strLogText += strProcessID;
			strLogText += szModulesMsg;
			strLogText += szDividerMsg;

			CComPtr<IXMLDOMNodeList> pXMLNodeListModules;
			if (SelectXMLNodes(pXMLNodeProcess, OLESTR("./modules/module"), pXMLNodeListModules))
			{
				for (;;)
				{
					CComPtr<IXMLDOMNode> pXMLNodeModule;
					hRes = pXMLNodeListModules->nextNode(&pXMLNodeModule);
					CHECK_HRESULT(hRes);
					if (hRes != S_OK)
						break;

					GetXMLNodeText(pXMLNodeModule, OLESTR("./name"), strModuleName);
					GetXMLNodeText(pXMLNodeModule, OLESTR("./version"), strModuleVersion);
					GetXMLNodeText(pXMLNodeModule, OLESTR("./base"), strModuleBase);

					strLogText += strModuleName;

					if (! strModuleVersion.IsEmpty())
					{
						strLogText += _T(" (");
						strLogText += strModuleVersion;
						strLogText += _T(')');
					}

					if (! strModuleBase.IsEmpty())
					{
						PVOID ptrBaseAddress = (PVOID)_tcstoui64(strModuleBase, NULL, 0);
						if (ptrBaseAddress != NULL)
						{
							strModuleBase.Format(_T("%08lX"), ptrBaseAddress);
							strLogText += szBaseMsg;
							strLogText += strModuleBase;
						}
					}

					strLogText += szNewLine;
				}
			}
		}
	}
}
コード例 #20
0
ファイル: ConfigDialog.cpp プロジェクト: olsonpm/FileSwitcher
void ConfigDialog::initializeOptions()
{
	tstring error;

	if (_options->searchFlags & SEARCHFLAG_CASESENSITIVE)
		::SendDlgItemMessage(_hSelf, IDC_CHECKCASE, BM_SETCHECK, BST_CHECKED, 0);
	else
		::SendDlgItemMessage(_hSelf, IDC_CHECKCASE, BM_SETCHECK, BST_UNCHECKED, 0);

	if ((_options->searchFlags & SEARCHFLAG_STARTONLY))
		::SendDlgItemMessage(_hSelf, IDC_CHECKANYPART, BM_SETCHECK, BST_CHECKED, 0);
	else
		::SendDlgItemMessage(_hSelf, IDC_CHECKANYPART, BM_SETCHECK, BST_UNCHECKED, 0);

	if (_options->searchFlags & SEARCHFLAG_INCLUDEPATH)
		::SendDlgItemMessage(_hSelf, IDC_CHECKINCLUDEPATH, BM_SETCHECK, BST_CHECKED, 0);
	else
		::SendDlgItemMessage(_hSelf, IDC_CHECKINCLUDEPATH, BM_SETCHECK, BST_UNCHECKED, 0);

	if (_options->searchFlags & SEARCHFLAG_INCLUDEFILENAME)
		::SendDlgItemMessage(_hSelf, IDC_CHECKINCLUDEFILENAME, BM_SETCHECK, BST_CHECKED, 0);
	else
		::SendDlgItemMessage(_hSelf, IDC_CHECKINCLUDEFILENAME, BM_SETCHECK, BST_UNCHECKED, 0);

	if (_options->searchFlags & SEARCHFLAG_INCLUDEINDEX)
		::SendDlgItemMessage(_hSelf, IDC_CHECKINCLUDEINDEX, BM_SETCHECK, BST_CHECKED, 0);
	else
		::SendDlgItemMessage(_hSelf, IDC_CHECKINCLUDEINDEX, BM_SETCHECK, BST_UNCHECKED, 0);

	if (_options->searchFlags & SEARCHFLAG_INCLUDEVIEW)
		::SendDlgItemMessage(_hSelf, IDC_CHECKINCLUDEVIEW, BM_SETCHECK, BST_CHECKED, 0);
	else
		::SendDlgItemMessage(_hSelf, IDC_CHECKINCLUDEVIEW, BM_SETCHECK, BST_UNCHECKED, 0);

	if (_options->useHomeForEdit)
		::SendDlgItemMessage(_hSelf, IDC_CHECKUSEHOMEFOREDIT, BM_SETCHECK, BST_CHECKED, 0);
	else
		::SendDlgItemMessage(_hSelf, IDC_CHECKUSEHOMEFOREDIT, BM_SETCHECK, BST_UNCHECKED, 0);

	if (_options->searchFlags & SEARCHFLAG_INCLUDEWILDCARD)
		::SendDlgItemMessage(_hSelf, IDC_CHECKWILDCARD, BM_SETCHECK, BST_CHECKED, 0);
	else
		::SendDlgItemMessage(_hSelf, IDC_CHECKWILDCARD, BM_SETCHECK, BST_UNCHECKED, 0);

	switch(_options->disabledSelectedSortOrder)
	{
	case ALWAYSREMEMBER :
		{
			::EnableWindow(GetDlgItem(_hSelf, IDC_RADIOSORTREMEMBER), FALSE);
			::SendDlgItemMessage(_hSelf, IDC_RADIOSORTREMEMBER, BM_SETCHECK, BST_CHECKED, 0);
			break;
		}
	case FILENAME :
		{
			::EnableWindow(GetDlgItem(_hSelf, IDC_RADIOSORTFILENAME), FALSE);
			::SendDlgItemMessage(_hSelf, IDC_RADIOSORTFILENAME, BM_SETCHECK, BST_CHECKED, 0);
			break;
		}
	case PATH :
		{
			::EnableWindow(GetDlgItem(_hSelf, IDC_RADIOSORTPATH), FALSE);
			::SendDlgItemMessage(_hSelf, IDC_RADIOSORTPATH, BM_SETCHECK, BST_CHECKED, 0);
			break;
		}
	case INDEX :
		{
			::EnableWindow(GetDlgItem(_hSelf, IDC_RADIOSORTINDEX), FALSE);
			::SendDlgItemMessage(_hSelf, IDC_RADIOSORTINDEX, BM_SETCHECK, BST_CHECKED, 0);
			break;
		}
	}

	if(_options->configuredContextPath.length() > 0)
	{
		::SetDlgItemText(_hSelf, IDC_SEARCHCONTEXTPATH, _options->configuredContextPath.c_str());
	}

	contextConfiguredOnInit = _options->hasConfiguredContext;
	if (_options->hasConfiguredContext)
	{
		::SendDlgItemMessage(_hSelf, IDC_CHECKCONFIGURESEARCHCONTEXT, BM_SETCHECK, BST_CHECKED, 0);
		::EnableWindow(GetDlgItem(_hSelf, IDC_SEARCHCONTEXTPATH), TRUE);
		::EnableWindow(GetDlgItem(_hSelf, IDC_MAXTRAVERSEFILES), TRUE);
		::EnableWindow(GetDlgItem(_hSelf, IDC_MAXDISPLAYFILES), TRUE);
		::EnableWindow(GetDlgItem(_hSelf, IDC_RADIOSORTINDEX), FALSE);
		::EnableWindow(GetDlgItem(_hSelf, IDC_CHECKINCLUDEVIEW), FALSE);
		::EnableWindow(GetDlgItem(_hSelf, IDC_CHECKINCLUDEINDEX), FALSE);
		::EnableWindow(GetDlgItem(_hSelf, IDC_CHECKONLYCURRENTVIEW), FALSE);
		::EnableWindow(GetDlgItem(_hSelf, IDC_CHECKSEPARATECOLUMNFORVIEW), FALSE);

		contextPathOnInit = _options->configuredContextPath;
		if(_options->configuredContextPath.length() > 0
			&& !(_options->ConfiguredContextPathIsValid()))
		{
			error = _T("Context path is invalid.  Please provide a valid context path.");
		}
	}
	else
	{
		::SendDlgItemMessage(_hSelf, IDC_CHECKCONFIGURESEARCHCONTEXT, BM_SETCHECK, BST_UNCHECKED, 0);
		::EnableWindow(GetDlgItem(_hSelf, IDC_SEARCHCONTEXTPATH), FALSE);
		::EnableWindow(GetDlgItem(_hSelf, IDC_MAXTRAVERSEFILES), FALSE);
		::EnableWindow(GetDlgItem(_hSelf, IDC_MAXDISPLAYFILES), FALSE);
		::EnableWindow(GetDlgItem(_hSelf, IDC_RADIOSORTINDEX), TRUE);
		if(_options->disabledSelectedSortOrder != NONE)
		{
			::SendDlgItemMessage(_hSelf, IDC_RADIOSORTINDEX, BM_SETCHECK, BST_CHECKED, 0);
			::SendDlgItemMessage(_hSelf, IDC_RADIOSORTFILENAME, BM_SETCHECK, BST_UNCHECKED, 0);
			::SendDlgItemMessage(_hSelf, IDC_RADIOSORTPATH, BM_SETCHECK, BST_UNCHECKED, 0);
			::SendDlgItemMessage(_hSelf, IDC_RADIOSORTREMEMBER, BM_SETCHECK, BST_UNCHECKED, 0);
			_options->disabledSelectedSortOrder = NONE;
		}
	}

	TCHAR bufMax[20];
	_itot_s(_options->maxTraverseFiles, bufMax, 20, 10);
	::SetDlgItemText(_hSelf, IDC_MAXTRAVERSEFILES, bufMax);
	_itot_s(_options->maxDisplayFiles, bufMax, 20, 10);
	::SetDlgItemText(_hSelf, IDC_MAXDISPLAYFILES, bufMax);

	switch(LOBYTE(_options->defaultSortOrder))
	{
	case FILENAME:
		{
			::SendDlgItemMessage(_hSelf, IDC_RADIOSORTFILENAME, BM_SETCHECK, BST_CHECKED, 0);
			break;
		}
	case PATH:
		{
			::SendDlgItemMessage(_hSelf, IDC_RADIOSORTPATH, BM_SETCHECK, BST_CHECKED, 0);
			break;
		}
	case INDEX:
		{
			::SendDlgItemMessage(_hSelf, IDC_RADIOSORTINDEX, BM_SETCHECK, BST_CHECKED, 0);
			break;
		}
	case ALWAYSREMEMBER:
	default:
		{
			::SendDlgItemMessage(_hSelf, IDC_RADIOSORTREMEMBER, BM_SETCHECK, BST_CHECKED, 0);
			EnableWindow(GetDlgItem(_hSelf, IDC_CHECKRESETSORTORDER), FALSE);
			EnableWindow(GetDlgItem(_hSelf, IDC_CHECKSORTDESCENDING), FALSE);
			break;
		}
	}

	::SendDlgItemMessage(_hSelf, IDC_CHECKSORTDESCENDING, BM_SETCHECK, _options->reversedSortOrder ? BST_CHECKED : BST_UNCHECKED, 0);
	::SendDlgItemMessage(_hSelf, IDC_CHECKRESETSORTORDER, BM_SETCHECK, _options->resetSortOrder ? BST_CHECKED : BST_UNCHECKED, 0);

	::SendDlgItemMessage(_hSelf, IDC_CHECKONLYCURRENTVIEW, BM_SETCHECK, _options->onlyUseCurrentView ? BST_CHECKED : BST_UNCHECKED, 0);

	::SendDlgItemMessage(_hSelf, IDC_CHECKAUTOSIZECOLUMNS, BM_SETCHECK, _options->autoSizeColumns ? BST_CHECKED : BST_UNCHECKED, 0);
	::EnableWindow(GetDlgItem(_hSelf, IDC_CHECKAUTOSIZEWINDOW), _options->autoSizeColumns);

	::SendDlgItemMessage(_hSelf, IDC_CHECKAUTOSIZEWINDOW, BM_SETCHECK, _options->autoSizeWindow ? BST_CHECKED : BST_UNCHECKED, 0);

	::SendDlgItemMessage(_hSelf, IDC_CHECKSEPARATECOLUMNFORVIEW, BM_SETCHECK, _options->columnForView ? BST_CHECKED : BST_UNCHECKED, 0);

	if (_options->emulateCtrlTab)
	{
		::SetDlgItemText(_hSelf, IDC_LABELCTRLTAB, _T("Ctrl-Tab functionality is enabled"));
		::ShowWindow(GetDlgItem(_hSelf, IDC_LABELCTRLTAB), SW_HIDE);

		::ShowWindow(GetDlgItem(_hSelf, IDC_CHECKOVERRIDESORTWHENTABBING), SW_SHOW);
		::ShowWindow(GetDlgItem(_hSelf, IDC_CHECKREVERTSORTORDERDURINGTABBING), SW_SHOW);
		::ShowWindow(GetDlgItem(_hSelf, IDC_CHECKDIALOGFORCTRLTAB), SW_SHOW);

		if (_options->overrideSortWhenTabbing)
		{
			::SendDlgItemMessage(_hSelf, IDC_CHECKOVERRIDESORTWHENTABBING, BM_SETCHECK, BST_CHECKED, 0);
			::EnableWindow(GetDlgItem(_hSelf, IDC_CHECKREVERTSORTORDERDURINGTABBING), TRUE);
		}
		else
		{
			::SendDlgItemMessage(_hSelf, IDC_CHECKOVERRIDESORTWHENTABBING, BM_SETCHECK, BST_UNCHECKED, 0);
			::EnableWindow(GetDlgItem(_hSelf, IDC_CHECKREVERTSORTORDERDURINGTABBING), FALSE);
		}

		if (_options->revertSortWhenTabbing)
			::SendDlgItemMessage(_hSelf, IDC_CHECKREVERTSORTORDERDURINGTABBING, BM_SETCHECK, BST_CHECKED, 0);
		else
			::SendDlgItemMessage(_hSelf, IDC_CHECKREVERTSORTORDERDURINGTABBING, BM_SETCHECK, BST_UNCHECKED, 0);

		::SendDlgItemMessage(_hSelf, IDC_CHECKDIALOGFORCTRLTAB, BM_SETCHECK, _options->showDialogForCtrlTab ?  BST_CHECKED : BST_UNCHECKED, 0);
	}
	else
	{
		::SetDlgItemText(_hSelf, IDC_LABELCTRLTAB, _T("Ctrl-Tab functionality is disabled. ")
			_T("To enable it, set the shortcuts for ")
			_T("\"Switch to next document\" and ")
			_T("\"Switch to previous document\" ")
			_T("to Ctrl-Tab and Ctrl-Shift-Tab respectively. ")
			_T("Remove the shortcuts from the Notepad++ defaults."));
		::ShowWindow(GetDlgItem(_hSelf, IDC_LABELCTRLTAB), SW_SHOW);

		::ShowWindow(GetDlgItem(_hSelf, IDC_CHECKOVERRIDESORTWHENTABBING), SW_HIDE);
		::ShowWindow(GetDlgItem(_hSelf, IDC_CHECKREVERTSORTORDERDURINGTABBING), SW_HIDE);
		::ShowWindow(GetDlgItem(_hSelf, IDC_CHECKDIALOGFORCTRLTAB), SW_HIDE);
	}

	if(error.length() > 0)
	{
		MessageBox(_hSelf, error.c_str(), _T("Error"), MB_OK);
	}
}
コード例 #21
0
ファイル: GameDlgcpp.cpp プロジェクト: ElenaSerbova/EKO-14-P2
BOOL GameDlg::Cls_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
{
	HP = GetDlgItem(hwnd, IDC_STATIC_HP);
	TCHAR tmpbuf[10];
	_itot_s(hp, tmpbuf, 10);
	SetWindowText(HP, tmpbuf);

	build_on = CreateWindow(L"STATIC", NULL, WS_CHILD | WS_VISIBLE | SS_BITMAP, 540, 120, 300, 220, hwnd, NULL, GetModuleHandle(NULL), NULL);
	GetClientRect(hwnd, &cd);
	phase = 0;
	ptr->trig = 0;

	ptr->catapult_b[0] = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP19));
	ptr->catapult_b[1] = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP20));
	ptr->catapult_b[2] = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP21));
	ptr->catapult_b[3] = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP22));

	ptr->build[0][0] = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP10));
	ptr->build[0][1] = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP11));
	ptr->build[0][2] = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP12));
	ptr->build[0][3] = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP13));
	ptr->build[0][4] = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP13));

	ptr->build[1][0] = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP14));
	ptr->build[1][1] = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP15));
	ptr->build[1][2] = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP16));
	ptr->build[1][3] = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP17));
	ptr->build[1][4] = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP18));
	
	ptr->build[2][0] = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP23));
	ptr->build[2][1] = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP24));
	ptr->build[2][2] = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP25));
	ptr->build[2][3] = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP26));
	ptr->build[2][4] = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP27));

	ptr->icons[0] = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP2));
	ptr->icons[1] = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP3));
	ptr->icons[2] = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP4));
	ptr->icons[3] = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP5));
	ptr->icons[4] = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP6));
	ptr->icons[5] = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP7));
	ptr->icons[6] = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP8));

	for (int i = 0; i < 11; i++)
	{
		for (int j = 0; j < 10; j++)
		{
			TCHAR nom[10];
			field[i][j] = new HANDLE;
			*field[i][j] = CreateWindowEx(NULL, L"BUTTON", nom, WS_CHILD | WS_VISIBLE | BS_FLAT, 20 + j * 50, 20 + i * 50, 50, 50, hwnd, NULL, GetModuleHandle(0), NULL);
			SetWindowLong((HWND)*field[i][j], GWL_STYLE, ::GetWindowLong((HWND)*field[i][j], GWL_STYLE) | BS_BITMAP | BS_FLAT);
			SendMessage((HWND)*field[i][j], BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)ptr->icons[game.Get(i, j)]);
		}
	}

	for (int j = 0; j < 10; j++)
	{
		TCHAR nom[10];
		catapult[j] = new HANDLE;
		*catapult[j] = CreateWindow(L"STATIC", nom, WS_CHILD | WS_VISIBLE | SS_BITMAP, 20 + j * 50, 570, 50, 50, hwnd, NULL, GetModuleHandle(NULL), NULL);
		SendMessage((HWND)*catapult[j], STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)ptr->catapult_b[0]);
	}

	SendMessage(build_on, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)ptr->build[level][anim]);

	//TOOLINFO ti;
	//HINSTANCE hinst = GetModuleHandle(NULL);
	//HWND hTooltip = CreateWindow(TOOLTIPS_CLASS, NULL, TTS_NOPREFIX | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,hwnd, (HMENU)NULL, hinst, NULL);
	//// Прикрепить подсказку к кнопке
	//memset(&ti, 0, sizeof TOOLINFO);
	//ti.cbSize = sizeof TOOLINFO;
	//ti.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
	//ti.uId = (UINT)GetDlgItem(hwnd, IDC_BUTTON1);;
	//ti.lpszText = L"Это подсказка Гагага!";
	//ti.hinst = hinst;
	//SendMessage(hTooltip, TTM_ADDTOOL, 0, (LPARAM)(LPTOOLINFO)&ti);

	return 0;
}
コード例 #22
0
ファイル: GameDlgcpp.cpp プロジェクト: ElenaSerbova/EKO-14-P2
void GameDlg::Cls_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{

	if (id == IDC_BUTTON1)
	{
		hp = hp - game.count_stone();
		
		if (hp > 0)
		{
			game.stone_on();

			for (int j = 0; j < 10; j++)
			{
				if (game.Get(10, j) == 0)
				{
					SendMessage((HWND)*ptr->catapult[j], STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)ptr->catapult_b[3]);
					Sleep(100);
					SendMessage((HWND)*ptr->catapult[j], STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)ptr->catapult_b[0]);
				}
				else
				{
					SendMessage((HWND)*ptr->catapult[j], STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)ptr->catapult_b[2]);
					Sleep(100);
					SendMessage((HWND)*ptr->catapult[j], STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)ptr->catapult_b[0]);
				}
			}

			game.generatefield();

			if (level == 0)
			{
				if (hp == 6) anim = 1;
				if (hp == 4) anim = 2;
				if (hp == 2) anim = 3;
			}
			if (level == 1)
			{
				if (hp == 12) anim = 1;
				if (hp == 9) anim = 2;
				if (hp == 6) anim = 3;
				if (hp == 3) anim = 4;
			}

			if (level == 2)
			{
				if (hp == 16) anim = 1;
				if (hp == 12) anim = 2;
				if (hp == 7) anim = 3;
				if (hp == 3) anim = 4;
			}

			if (hp < 0) hp = 0;
			TCHAR tmpbuf[10];
			_itot_s(hp, tmpbuf, 10);
			SetWindowText(HP, tmpbuf);
			
		}
		else
		{
			game.generatefield();

			for (int j = 0; j < 10; j++)
			{
				SendMessage((HWND)*ptr->catapult[j], STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)ptr->catapult_b[0]);
			}

			anim = 0;
			level++;

			if (level == 1) hp = 15;
			if (level == 2) hp = 20;
			if (level > 2)
			{
				level = 0;
				hp = 10;
			}

			TCHAR tmpbuf[10];
			_itot_s(hp, tmpbuf, 10);
			SetWindowText(HP, tmpbuf);
		}
	}

	if (phase == 0)
	{
		TCHAR nom[10];
		for (int i = 0; i < 11; i++)
			for (int j = 0; j < 10; j++)
			{
			if (hwndCtl == *field[i][j])
			{
				game.Click(i, j);

				if (game.getss())
				{
					if (game.isswap())
					{
						game.swap();
						phase++;
						SetTimer(hwnd, NULL, 100, NULL);
					}
					else
					{
						game.unselect();
						game.setbs(i, j);
					}
				}
			}
			}
	}

	for (int i = 0; i < 11; i++)
	{
		for (int j = 0; j < 10; j++)
		{
			SendMessage((HWND)*field[i][j], BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)ptr->icons[game.Get(i, j)]);
		}
	}

	SendMessage(build_on, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)ptr->build[level][anim]);
}
コード例 #23
0
ファイル: main.cpp プロジェクト: billycao/Wi-Mote
static INT_PTR CALLBACK dlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch (uMsg) {
		case WM_INITDIALOG:
		{
			hDlgMain = hDlg;
			char name[nameLen + 1];
			ZeroMemory(name, nameLen + 1);
			if (gethostname(name, nameLen) == 0) {
				struct addrinfo *result = NULL;
				char *szIpAddr = NULL;
				if (getaddrinfo(name, NULL, NULL, &result) == 0 && result) {
					for (struct addrinfo *ptr = result; ptr != NULL; ptr = ptr->ai_next) {
						if (ptr->ai_family == AF_INET) {
							struct sockaddr_in *sockaddr_ipv4 = (struct sockaddr_in *)ptr->ai_addr;
							if (sockaddr_ipv4) {
								szIpAddr = inet_ntoa(sockaddr_ipv4->sin_addr);
								break;
							}
						}
					}
					if (szIpAddr)
						SetDlgItemTextA(hDlg, IDC_IPADDR, szIpAddr);
					freeaddrinfo(result);
				}
			}

			srand((unsigned int)time(NULL));
			do {
				pin = rand();
			} while (!(pin >= 10000 && pin <= 65535));

			int i = 0;
			TCHAR tszBuffer[shortStringLen + 1];

			i = (int)GetPrivateProfileInt(lpszIniSection, lpszIniKeyPort, port, lpszIniFile);
			if (IS_SHORT(i))
				port = i;
			ZeroMemory(tszBuffer, shortStringLen + 1);
			if (_itot_s(port, tszBuffer, shortStringLen, 10) == 0)
				SetDlgItemText(hDlg, IDC_PORT, tszBuffer);

			i = (int)GetPrivateProfileInt(lpszIniSection, lpszIniKeyPin, pin, lpszIniFile);
			if (IS_SHORT(i))
				pin = i;
			ZeroMemory(tszBuffer, shortStringLen + 1);
			if (_itot_s(pin, tszBuffer, shortStringLen, 10) == 0)
				SetDlgItemText(hDlg, IDC_PIN, tszBuffer);

			SetDlgItemText(hDlg, IDC_STARTSTOP, lpszStart);

			return TRUE;
		}
		case WM_COMMAND:
			switch (LOWORD(wParam)) {
				case IDC_ABOUT:
					DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUT), hDlg, (DLGPROC)aboutDlgProc);
					break;
				case IDC_STARTSTOP:
					if (!bServerRunning) {
						int ret = getSaveSettings(hDlg);
						if (ret == 1) {
							bServerRunning = TRUE;
							hThread = CreateThread(NULL, 0, serverThread, NULL, 0, &dwThreadId);
							if (hThread) {
								SetDlgItemText(hDlg, IDC_STARTSTOP, lpszStop);
								SendDlgItemMessage(hDlg, IDC_BANNER, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)LoadImage(hInst, MAKEINTRESOURCE(IDB_WIMOTESTARTED), IMAGE_BITMAP, 0, 0, LR_SHARED));
								ShowWindow(GetDlgItem(hDlg, IDC_ABOUT), SW_HIDE);
								ShowWindow(GetDlgItem(hDlg, IDC_ABOUT), SW_SHOW);
								EnableWindow(GetDlgItem(hDlg, IDC_IPADDR), FALSE);
								EnableWindow(GetDlgItem(hDlg, IDC_PORT), FALSE);
								EnableWindow(GetDlgItem(hDlg, IDC_PIN), FALSE);
							}
							else
								bServerRunning = FALSE;
						}
						else if (ret == 0)
							MessageBox(hDlg, TEXT("Invalid inputs! Port/PIN must be in the range 0-65535."), TEXT("Wi-Mote Error"), MB_OK | MB_ICONSTOP);
						else
							MessageBox(hDlg, TEXT("An error has occurred while saving user settings."), TEXT("Wi-Mote Error"), MB_OK | MB_ICONSTOP);
					}
					else {
						bServerRunning = FALSE;
						CloseHandle(hThread);
						hThread = NULL;
						SetDlgItemText(hDlg, IDC_STARTSTOP, lpszStart);
						SendDlgItemMessage(hDlg, IDC_BANNER, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)LoadImage(hInst, MAKEINTRESOURCE(IDB_WIMOTE), IMAGE_BITMAP, 0, 0, LR_SHARED));
						ShowWindow(GetDlgItem(hDlg, IDC_ABOUT), SW_HIDE);
						ShowWindow(GetDlgItem(hDlg, IDC_ABOUT), SW_SHOW);
						EnableWindow(GetDlgItem(hDlg, IDC_IPADDR), TRUE);
						EnableWindow(GetDlgItem(hDlg, IDC_PORT), TRUE);
						EnableWindow(GetDlgItem(hDlg, IDC_PIN), TRUE);
					}
					break;
				case IDCANCEL:
				{
					bServerRunning = FALSE;
					CloseHandle(hThread);
					int ret = getSaveSettings(hDlg);
					if (ret == 1)
						EndDialog(hDlg, TRUE);
					else if (ret == 0)
						MessageBox(hDlg, TEXT("Invalid inputs! Port/PIN be in the range 0-65535."), TEXT("Wi-Mote Error"), MB_OK | MB_ICONSTOP);
					else {
						MessageBox(hDlg, TEXT("An error has occurred while saving user settings."), TEXT("Wi-Mote Error"), MB_OK | MB_ICONSTOP);
						EndDialog(hDlg, TRUE);
					}
					break;
				}
				default:
					break;
			}
			return 0;
		default:
			break;
	}
	return FALSE;
}
コード例 #24
0
ファイル: cLogLight.cpp プロジェクト: uvbs/SupportCenter
tstring i2tstring(const int i, const int radix)
{
	TCHAR buf[30];
	_itot_s(i,buf,radix);
	return buf;
}