2013년 12월 23일 월요일

[미완] IsIconic() 함수

[미완] IsIconic() 함수

윈도우가 최소화인지 아니지 판단하는 함수

리턴값
최소화=TRUE
활성화=FALSE

활용
1. 최소화되었을때 어떤 처리를 해야할때
2. 최소화일때 화면 출력 차단
   ex) WM_PAINT에서 최소화 되었을때 화면을 그릴 필요가 없다
   case WM_PAINT
      if( FASLE == IsIconic( hWnd ) ) // 활성화면
      {
         // 화면 출력 소스
      }
     break;

[미완] Internet Explorer 구글 인증서 오류로 인하여 접속 안될때

[미완] Internet Explorer 구글 인증서 오류로 인하여 접속 안될때

윈도우의 날짜가 안맞아서 그렇수 있을니
날짜를 오늘날짜로 셋팅

2013년 12월 18일 수요일

[Win32/MFC] "", L"", TEXT(""), _T("") 차이점

Visual C++에서 문자 처리는 2가지가 있다.
"멀티바이트"와 "유니코드"다.
(C#은 유니코드만 있는걸로 알고 있음)

멀티바이트(MBCS=Multi Byte Character Set): 영어는 1바이트, 그 외 문자는 2바이트로 처리.
유니코드(WBCS=Wide Byte Character Set): 모든 문자를 2바이트로 처리.(참고로 GCC는 4바이트로 처리)

그래서 Visual Studio에서 프로젝트 속성을
멀티바이트로 하면 "" 이렇게 문자를 입력하고
유니코드로 하면 L"" 이렇게 문자를 입력해야 한다.
ex)
멀티바이트일때 MessageBox( NULL, "a", "b", MB_OK );
유니코드일때    MessageBox( NULL, L"a", L"b", MB_OK );

근데 유니코드로 설정 후 개발 했다가
멀티바이트로 변경 해야될때(외부 라이브러리와의 호환성 등)
L"" 이렇게 입력한 부분을 모두 찾아서
"" 이렇게 변경을 해줘야 한다.(완전 노가다)

그래서 TEXT("")와 _T("")를 #define 했다.
ex)
MessageBox( NULL, TEXT("a"), TEXT("b"), MB_OK );
이렇게 입력을 하면
멀티바이트일때 MessageBox( NULL, "a", "b", MB_OK );
유니코드일때    MessageBox( NULL, L"a", L"b", MB_OK );
이렇게 변환이 되어서 컴파일 된다.

TEXT("")과 _T("")의 차이점은
TEXT("")는 WinNT.h에서 #define했고
_T("")는 tchar.h에서 TEXT가 4글자라서 _T이렇게 2글자로 #define했다.

즉 Win32에서는 TEXT("")를 쓰고 MFC에서는 _T("")를 사용한다.
Win32에서 _T("")를 사용하고 싶으면 tchar.h를 추가하면 되고
MFC에서는 당연히 TEXT("")도 사용 가능하다.

--- 결론
윈도우즈 프로그램 개발시
문자를 "" 또는 L"" 이렇게 입력하지 말고
TEXT("") 또는 _T("") 이렇게 입력하자.

[미완] 네트워크 정보 추출 함수

MSDN에 있는 내용임

#include <winsock2.h>
#include <iphlpapi.h>
#include <stdio.h>
#include <stdlib.h>
#pragma comment(lib, "IPHLPAPI.lib")

#define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
#define FREE(x) HeapFree(GetProcessHeap(), 0, (x))

/* Note: could also use malloc() and free() */

int __cdecl main()
{
char acMacAddr[100];
char acIpAddr[100];

bool b = GetNetworkInfo( acMacAddr, acIpAddr );
/* Declare and initialize variables */

// It is possible for an adapter to have multiple
// IPv4 addresses, gateways, and secondary WINS servers
// assigned to the adapter.
//
// Note that this sample code only prints out the
// first entry for the IP address/mask, and gateway, and
// the primary and secondary WINS server for each adapter.

PIP_ADAPTER_INFO pAdapterInfo;
PIP_ADAPTER_INFO pAdapter = NULL;
DWORD dwRetVal = 0;
UINT i;

/* variables used to print DHCP time info */
struct tm newtime;
char buffer[32];
errno_t error;

ULONG ulOutBufLen = sizeof (IP_ADAPTER_INFO);
pAdapterInfo = (IP_ADAPTER_INFO *) MALLOC(sizeof (IP_ADAPTER_INFO));
if (pAdapterInfo == NULL) {
printf("Error allocating memory needed to call GetAdaptersinfo\n");
return 1;
}
// Make an initial call to GetAdaptersInfo to get
// the necessary size into the ulOutBufLen variable
if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) {
FREE(pAdapterInfo);
pAdapterInfo = (IP_ADAPTER_INFO *) MALLOC(ulOutBufLen);
if (pAdapterInfo == NULL) {
printf("Error allocating memory needed to call GetAdaptersinfo\n");
return 1;
}
}

if ((dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen)) == NO_ERROR) {
pAdapter = pAdapterInfo;
while (pAdapter) {
printf("\tComboIndex: \t%d\n", pAdapter->ComboIndex);
printf("\tAdapter Name: \t%s\n", pAdapter->AdapterName);
printf("\tAdapter Desc: \t%s\n", pAdapter->Description);
printf("\tAdapter Addr: \t");
for (i = 0; i < pAdapter->AddressLength; i++) {
if (i == (pAdapter->AddressLength - 1))
printf("%.2X\n", (int) pAdapter->Address[i]);
else
printf("%.2X-", (int) pAdapter->Address[i]);
}
printf("\tIndex: \t%d\n", pAdapter->Index);
printf("\tType: \t");
switch (pAdapter->Type) {
case MIB_IF_TYPE_OTHER:
printf("Other\n");
break;
case MIB_IF_TYPE_ETHERNET:
printf("Ethernet\n");
break;
case MIB_IF_TYPE_TOKENRING:
printf("Token Ring\n");
break;
case MIB_IF_TYPE_FDDI:
printf("FDDI\n");
break;
case MIB_IF_TYPE_PPP:
printf("PPP\n");
break;
case MIB_IF_TYPE_LOOPBACK:
printf("Lookback\n");
break;
case MIB_IF_TYPE_SLIP:
printf("Slip\n");
break;
default:
printf("Unknown type %ld\n", pAdapter->Type);
break;
}

printf("\tIP Address: \t%s\n",
pAdapter->IpAddressList.IpAddress.String);
printf("\tIP Mask: \t%s\n", pAdapter->IpAddressList.IpMask.String);

printf("\tGateway: \t%s\n", pAdapter->GatewayList.IpAddress.String);
printf("\t***\n");

if (pAdapter->DhcpEnabled) {
printf("\tDHCP Enabled: Yes\n");
printf("\t  DHCP Server: \t%s\n",
pAdapter->DhcpServer.IpAddress.String);

printf("\t  Lease Obtained: ");
/* Display local time */
error = _localtime32_s(&newtime, (__time32_t*) &pAdapter->LeaseObtained);
if (error)
printf("Invalid Argument to _localtime32_s\n");
else {
// Convert to an ASCII representation
error = asctime_s(buffer, 32, &newtime);
if (error)
printf("Invalid Argument to asctime_s\n");
else
/* asctime_s returns the string terminated by \n\0 */
printf("%s", buffer);
}

printf("\t  Lease Expires:  ");
error = _localtime32_s(&newtime, (__time32_t*) &pAdapter->LeaseExpires);
if (error)
printf("Invalid Argument to _localtime32_s\n");
else {
// Convert to an ASCII representation
error = asctime_s(buffer, 32, &newtime);
if (error)
printf("Invalid Argument to asctime_s\n");
else
/* asctime_s returns the string terminated by \n\0 */
printf("%s", buffer);
}
} else
printf("\tDHCP Enabled: No\n");

if (pAdapter->HaveWins) {
printf("\tHave Wins: Yes\n");
printf("\t  Primary Wins Server:    %s\n",
pAdapter->PrimaryWinsServer.IpAddress.String);
printf("\t  Secondary Wins Server:  %s\n",
pAdapter->SecondaryWinsServer.IpAddress.String);
} else
printf("\tHave Wins: No\n");
pAdapter = pAdapter->Next;
printf("\n");
}
} else {
printf("GetAdaptersInfo failed with error: %d\n", dwRetVal);

}
if (pAdapterInfo)
FREE(pAdapterInfo);

return 0;
}

2013년 12월 12일 목요일

[미완] 인터넷 사이트 연결 확인

인터넷 사이트 연결 확인

BOOL InternetCheckConnection( "사이트이름", FLAG_ICC_FORCE_CONNECTION, 0 );

접속성공하면 TRUE
접속안되면 FALSE
-> 외부인터넷 연결 확인시 사용 할 수 있을듯
주의: 사이트이름입력시 앞에 "http://"를 꼭 붙여야 함.

// 사용 예
#include <Windows.h>
#include <WinInet.h>
#pragma comment (lib, "wininet.lib")

BOOL CheckInternetSite( TCHAR* pstrSiteName )
{
return InternetCheckConnection( pstrSiteName, FLAG_ICC_FORCE_CONNECTION, 0 );
}

int main( void )
{
BOOL BRet = CheckInternetSite( TEXT("http://www.google.com") );

        if ( FALSE == BRet )
       {
            // 사이트 연결 실패
        }

return 0;
}

[미완] IPHlpApi.h 추가 했는데도 PMIB_ICMP_EX 에러 발생

[미완] IPHlpApi.h 추가 했는데도 PMIB_ICMP_EX 에러 발생

네트워크 정보를 추출하기 위해서 소스에

#include <IPHlpApi.h>
#pragma comment( lib, "iphlpapi.lib" )

추가해도
PMIB_ICMP_EX 에러가 발생한다.

해결
C:\Program Files\Microsoft SDK\include 에 있는 Iprtrmib.h 파일을
C:\Program Files\Microsoft Visual Studio\VC98\Include 에 덮어쓴다.

2013년 12월 7일 토요일

[미완] 디버그 모드에서만 실행

#if _DEBUG
   // 이곳에 디버그때만 처리하고 싶은 로직 추가
#endif

보통 설정에 보면 _DEBUG가 Debug에 등록이 되어 있고
Release에는 등록이 안되어 있다.

실제 사용 예는
프로그램 시작시 로그인해서 들어가는 프로그램 같은 경우
매번 테스트 할때마다 ID/PW를 입력해야 하는데

위에 코드에다가 로그인하는 루틴을 넣으면
디버그때 일일이 입력할 필요가 없고

릴리즈때는 입력을 해야한다

2013년 12월 5일 목요일

[미완] 다이어로그에서 Static 클릭 이벤트 발생할려면

[미완] 다이어로그에서 Static 클릭 이벤트 발생할려면

Static 클릭시 WM_COMMAND 발생하려면
Static의 Styles에서 Notify 체크

[미완] Visual Studio F5, Ctrl+F5 차이점

[미완] Visual Studio F5 Vs. Ctrl+F5 차이점

F5는 VS가 붙어서 실행되고
Ctrl+F5는 독립적으로 실행된다고 한다.

간단히 얘기해서
브레이크 포인트(F9)는
F5에서는 걸리고
Ctrl+F5에서는 안걸린다.

2013년 12월 4일 수요일

[미완] CEdit 멀티라인 출력

[미완] CEdit 멀티라인 출력

Multiline 체크하면 되는데도 안되면
\n 말고 \r\n 입력해주세요

2013년 12월 3일 화요일

[미완] CString -> int 변환

[미완] CString -> int 변환

CString str = "1";
int n = _ttoi(str);

[미완] SendMessage() Vs. PostMessage()

[미완] SendMessage() Vs. PostMessage()

둘다 윈도우에 메시지를 보네는데
차이점은 SendMessage는 즉시 처리이고
PostMessage는 메시지큐에 대입해서
먼저 들어온 메시지들을 처리하고나서 PostMessage를 처리한다

2013년 12월 2일 월요일

[미완] CString -> char*로 변환

CString CStringTemp;
CStringTemp = "Test";

char* pchTemp = LPSTR(LPCTSTR(CStringTemp));