if(::GetForegroundWindow() != GetSafeHwnd()) {
 HWND hActiveWnd = ::GetForegroundWindow();
 if(hActiveWnd != NULL) {
  DWORD ThreadID = GetWindowThreadProcessId(hActiveWnd, NULL);
  DWORD CurrentThreadID = GetCurrentThreadId();
  if(CurrentThreadID != ThreadID) {
   if(AttachThreadInput(CurrentThreadID, ThreadID, TRUE)) {
    ::BringWindowToTop(GetSafeHwnd());
    AttachThreadInput(CurrentThreadID, ThreadID, FALSE);
   }
  }
 }
}
Posted by 모과이IT
,

int CheckEncodingType(CString strPage)
{
//////////////////////////////////////////////////////////////////////////
//
// Function : CheckEncodingType
// Param : LPCTSTR lpFilelocation 파일의 저장위치
// Return : integer;    0  = ANSI
//                      1  = UTF-8
//                      2  = Unicode LE
//                      3  = Unicdoe BE
//                      -1 = File Error
//
// description : 텍스트의 인코딩 형식을 찾아 리턴한다

    int nRet = 0;

    BYTE btBuf[8];
    memset(btBuf, 0, 8);

    //BOM 정의
    BYTE btBOM_UnicodeBE[] = {0xFE, 0xFF};
    BYTE btBOM_UnicodeLE[] = {0xFF, 0xFE};
    BYTE btBOM_UTF8[] = {0xEF, 0xBB, 0xBF};

    //3바이트이상
    if(strPage.GetLength() < 3)
        return -1;

    if(memcmp(btBuf, btBOM_UnicodeLE, 2) == 0) //Unicode Little Endian
    {
        nRet = 2;
        return nRet;
    }
    else if(memcmp(btBuf, btBOM_UnicodeBE, 2) == 0) //Unicode Big Endian
    {
        nRet = 3;
        return nRet;
    }
    else if(memcmp(btBuf, btBOM_UTF8, 3) == 0) //UTF-8
    {
        nRet = 1;
        return nRet;
    }

    // ANSI와 UTF-8을 노가다로 판단하는 루틴
    memset(btBuf, 0, 8);
    int nLookNum = 0; // 이후 출현할 바이트 개수값
    int nRead = 0;
    int nANSINum = 0;
    for (int i=0; i<strPage.GetLength(); i++)
    {
        btBuf[0] = strPage.GetAt(i);
        nRead++;
        //7F (=127)보다 작은 경우는 패스
        if(btBuf[0] <= 0x7F && nLookNum == 0)
        {
            nANSINum++;
            continue;
        }
        //FF, FE일 경우는 UTF-8이 될 수 없다.
        else if((btBuf[0] == 0xFF || btBuf[0] == 0xFE) && nLookNum == 0)
        {
            return 0;
        }
        //7F보다 큰경우 UTF-8 판단작업 들어감
        else
        {
            if(nLookNum > 0) //내부 검사
            {
                nLookNum--;            
                if(btBuf[0] >= 0x80 && btBuf[0] <= 0xBF)
                    continue;
                else
                    return 0; //ANSI 리턴
            }
            else  //최외각 검사
            {
                if(btBuf[0] >= 0xC0 && btBuf[0] <= 0xDF)  nLookNum = 1;
                else if(btBuf[0] >= 0xE0 && btBuf[0] <= 0xEF) nLookNum = 2;
                else if(btBuf[0] >= 0xF0 && btBuf[0] <= 0xF7) nLookNum = 3;
                else if(btBuf[0] >= 0xF8 && btBuf[0] <= 0xFB) nLookNum = 4;
                else if(btBuf[0] == 0xFC || btBuf[0] == 0xFD) nLookNum = 5;
                else           nANSINum++;

                continue;
            }
        }
    }  

    if(nRead != nANSINum) nRet = 1;
    else     nRet = 0;

    return nRet;
}

Posted by 모과이IT
,

[CString -> char * 변환]

CString str;
str = "Hello";
char* ss = LPSTR(LPCTSTR(str));

[char * --> CString 변환]

char ss[] = "Hello";
CString str;
str.Format("%s", ss);

Or

char *ss = "Hello";
CString str;
str = ss;

유용한 팁임
Posted by 모과이IT
,