示例#1
0
文件: hook.cpp 项目: byplayer/yamy
/// get class name and title name
static void getClassNameTitleName(HWND i_hwnd, bool i_isInMenu,
                                  tstringi *o_className,
                                  tstring *o_titleName)
{
    tstringi &className = *o_className;
    tstring &titleName = *o_titleName;

    bool isTheFirstTime = true;

    if (i_isInMenu) {
        className = titleName = _T("MENU");
        isTheFirstTime = false;
    }

    while (true) {
        _TCHAR buf[MAX(GANA_MAX_PATH, GANA_MAX_ATOM_LENGTH)];

        // get class name
        if (i_hwnd)
            GetClassName(i_hwnd, buf, NUMBER_OF(buf));
        else
            GetModuleFileName(GetModuleHandle(NULL), buf, NUMBER_OF(buf));
        buf[NUMBER_OF(buf) - 1] = _T('\0');
        if (isTheFirstTime)
            className = buf;
        else
            className = tstringi(buf) + _T(":") + className;

        // get title name
        if (i_hwnd) {
            GetWindowText(i_hwnd, buf, NUMBER_OF(buf));
            buf[NUMBER_OF(buf) - 1] = _T('\0');
            for (_TCHAR *b = buf; *b; ++ b)
                if (_istlead(*b) && b[1])
                    b ++;
                else if (_istcntrl(*b))
                    *b = _T('?');
        }
        if (isTheFirstTime)
            titleName = buf;
        else
            titleName = tstring(buf) + _T(":") + titleName;

        // next loop or exit
        if (!i_hwnd)
            break;
        i_hwnd = GetParent(i_hwnd);
        isTheFirstTime = false;
    }
}
示例#2
0
int iscntrl( int c ) { return _istcntrl(c); }
示例#3
0
_bstr_t CXMLHttpRequest::GetErrorMsg(DWORD rc)
{
	_bstr_t msg(_T(""));
	TCHAR *lpBuffer = NULL;
	
	if (ERROR_INTERNET_EXTENDED_ERROR == rc) {
		DWORD dwError  = 0;
		DWORD dwLength = 0; 
		InternetGetLastResponseInfo (&dwError, NULL, &dwLength);
        if (dwLength > 0) {
			lpBuffer = (TCHAR *) LocalAlloc(LPTR,dwLength);
			if (!lpBuffer) {
				msg = _T("Unable to allocate memory to display Internet extended error: ");
                rc = GetLastError();
          	}
			else {
                if (!InternetGetLastResponseInfo(&dwError,lpBuffer,&dwLength)) {
				    msg = _T("Unable to get Internet extended error: ");
                    rc = GetLastError();
					LocalFree(lpBuffer);
                }
				else {
					int len = lstrlen(lpBuffer);
					for (int i=0; i < len; ++i) {
						if (_istcntrl(lpBuffer[i])) 
							lpBuffer[i] = _T(' ');
					}
					msg = lpBuffer;
					LocalFree(lpBuffer);
					return msg;
 				}
			}
		}
    }
	
	lpBuffer = NULL;
	HMODULE hModule = NULL; // default to system source
    
	if (rc >= INTERNET_ERROR_BASE) 
		 hModule = LoadLibraryEx(_T("wininet.dll"),NULL,LOAD_LIBRARY_AS_DATAFILE);
    
	::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER	|
					FORMAT_MESSAGE_IGNORE_INSERTS	|
					FORMAT_MESSAGE_FROM_SYSTEM		|
					((hModule != NULL) ? FORMAT_MESSAGE_FROM_HMODULE : 0),
					hModule, 
					rc,
					MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT),
					(LPTSTR)&lpBuffer, 0, NULL);
			
	if (lpBuffer) {
		int len = lstrlen(lpBuffer);
		for (int i=0; i < len; ++i) {
			if (_istcntrl(lpBuffer[i])) 
				lpBuffer[i] = _T(' ');
		}
	}

	msg += lpBuffer;
	LocalFree(lpBuffer);

	if (hModule != NULL)
	    FreeLibrary(hModule);

	return msg;
}