« Previous : 1 : 2 : 3 : 4 : 5 : Next »

시간계산...

long startTime;
long endTime;
long tickDiff;

startTime = GetTickCount();
endTime = GetTickCount();

tickDiff = endTime - startTime;

잇힝 틱타임

Posted by rCan

2011/11/18 19:26 2011/11/18 19:26
Response
No Trackback , No Comment
RSS :
http://rcan.net/rss/response/610

하트

사용자 삽입 이미지
이미지 테스트용 하트

Posted by rCan

2011/08/01 22:55 2011/08/01 22:55
Response
No Trackback , a comment
RSS :
http://rcan.net/rss/response/608

VS6.0 한글토클방법


기술 자료: 600742 - 마지막 검토: 2005년 7월 11일 월요일 - 수정: 1.1
프로그래밍적으로 한/영 키 토글 방법
추가 정보
 
<imm.h>에 함수의 원형과 상수의 정의가, imm32.lib 각 함수의 주소정보가 있으므로 Source에는 <imm.h>를 include하고...<imm.h>에 함수의 원형과 상수의 정의가, imm32.lib 각 함수의 주소정보가 있으므로 Source에는 <imm.h>를 include하고 makefile에는 imm32.lib를 library에 추가한다.

다음의 함수는 ImmSetConversionStatus함수에서 한/영 토글 모드 관련 DWORD fdwConversion 을 fFlag로 넘겨주는 Sample 함수이다.
void Conv_HAN_ENG(HWND hWnd, DWORD fFlag ){
 HIMC            hIMC;           // Input context handle.
 if ( !( hIMC = ImmGetContext( hWnd ) ) )
  return;
 ImmSetConversionStatus( hIMC, fFlag, IME_SMODE_NONE );
 ImmReleaseContext( hWnd, hIMC );
}
    
그리고 다음은 Sample 함수를 부르는 부분이다.

프로그램 메뉴에서 한글 모드를 선택하면, ID_HANGEUL이 영문 모드를 선택하면 ID_ENGLISH가 실행되도록 한 경우이다.
case ID_HANGEUL:
Conv_HAN_ENG(hWnd,IME_CMODE_HANGEUL);
break;
case ID_ENGLISH:
Conv_HAN_ENG(hWnd,IME_CMODE_ALPHANUMERIC);
break;

출처 : MS ( http://support.microsoft.com/kb/600742/ko )

Posted by rCan

2011/02/25 15:26 2011/02/25 15:26
Response
No Trackback , No Comment
RSS :
http://rcan.net/rss/response/606

TrimRight 관련

확장자를 제거하기 위해 TrimRight를 쓰는 경우가 있습니다.

CString Filter = ".txt";
CString szFileName = "MyText.txt";
szFileName.TrimRight(Filter);

작성자가 원하는 결과는 MyText
실제 결과는 MyTex

TrimRight는 Parameter로 받는 글자와 완벽히 일치하는 문자를 제거하는 것이 아니라
Parameter로 받은 글자가 전부 포함된 문자를 제거합니다.

MSDN에 있는 예제를 보면 이해가 빠릅니다.

CString strBefore;
CString strAfter;

   strBefore = "Hockey is Best!!!!";
   strAfter = strBefore;
   str.TrimRight('!');
   printf("Before: \"%s\"\n", (LPCTSTR) strBefore);
   printf("After : \"%s\"\n\n", (LPCTSTR) strAfter);

   strBefore = "Hockey is Best?!?!?!?!";
   strAfter = strBefore;
   str.TrimRight("?!");
   printf("Before: \"%s\"\n", (LPCTSTR) strBefore);
   printf("After : \"%s\"\n\n", (LPCTSTR) strAfter);

In the first example above, the string reading, "Hockey is Best!!!!" becomes "Hockey is Best".

In the second example above, the string reading, , "Hockey is Best?!?!?!?!" becomes "Hockey is Best".
<from MSDN : http://msdn.microsoft.com/en-us/library/aa300669(VS.60).aspx>

첫번째 예제의 느낌표는 모두 사라졌고 두 번째 예제에서는 ?! 가 모두 사라졌습니다. 그렇지만 TrimRight에 넘어가는 Parameter는 "!"와 "?!" 뿐입니다.

함수 이름만 보고는 오해를 불러 일으키기 쉬운 함수인 듯 합니다.

참고로 확장자를 제거하기 위해서는 아래 방법이 제일 무난합니다.

CString Filter = ".txt";
CString szFileName = "MyText.txt";
szFileName = szFileName.Left(szFileName.GetLength - Filter.GetLength());

- 출처 : http://doubleyh.tistory.com/194 -

Posted by rCan

2010/12/21 21:04 2010/12/21 21:04
Response
No Trackback , No Comment
RSS :
http://rcan.net/rss/response/605

[소니카메라]

SNC_ERROR sncErrorCode = (SNC_ERROR)LOWORD( wParam );

Posted by rCan

2010/10/04 22:41 2010/10/04 22:41
Response
No Trackback , No Comment
RSS :
http://rcan.net/rss/response/602

파일기록

CFile File(".\\scheduler_log.txt", CFile::modeCreate | CFile::modeNoTruncate | CFile::modeReadWrite);
File.SeekToEnd();
CString msg_log;
CTime time = CTime::GetCurrentTime();

msg_log.Format("\n\r%4d년%02d월%02d일 Error FileName : %s\n\r",time.GetYear(),time.GetMonth(),time.GetDay(),sFileName);
File.Write(msg_log.GetBuffer(0), msg_log.GetLength());
File.Close();

Posted by rCan

2010/06/21 15:34 2010/06/21 15:34
Response
No Trackback , No Comment
RSS :
http://rcan.net/rss/response/600

작업표시줄에서 숨기기

생성자
    m_bShowStatus=FALSE;

OnInitDialog()
    ModifyStyleEx(WS_EX_APPWINDOW,WS_EX_TOOLWINDOW,0);

OnWindowPosChanging(WINDOWPOS FAR* lpwndpos)
    // TODO: Add your message handler code here
    if(m_bShowStatus == TRUE)
    {
        lpwndpos->flags |= SWP_SHOWWINDOW;
    }
    else
    {
        lpwndpos->flags &= ~ SWP_SHOWWINDOW;
    }

Posted by rCan

2010/06/21 15:32 2010/06/21 15:32
Response
No Trackback , No Comment
RSS :
http://rcan.net/rss/response/599

시간연산


작성자 : CalmMass
작성일자 : 2010.05.28
제목 : 함수를 이용한 윈도우(windows) 시간 계산 방법
툴 : MS Visual C++ 6.0, STLPort 5.6, SDK
함 수 정리
GetLocalTime : IpSystemTime (현재 로컬 시간을 대입받을 SYSTEMTIME 구조체 사용합니다.) ( 바로가기 )
GetTickCount : 수행 시간을 측정 할때 많이 사용하는 함수( 바로가기 )
GetSystemTime : 현재 Windows System상의 날짜 및 시간을 반환 하는 함수( 바로가기 )
MFC
CTime : MFC에서 사용하는 시간 관련 클래스 단, Millisecond는 없다. ( 바로가기 )
CTime::CurrentTime() : 현재 시간을 구하기
CTimeSpan : MFC에서 사용하는 시간을 연산하는 방법이다. ( 바로가기 )

그외
---------------------------------------------------------------------------------------------
CompareFileTime
DosDateTimeToFileTime
FileTimeToDosDateTime
FileTimeToLocalFileTime
FileTimeToSystemTime
GetFileTime
GetLocalTime
GetSystemTime
GetSystemTimeAdjustment
GetSystemTimeAsFileTime
GetTickCount
GetTimeZoneInformation
LocalFileTimeToFileTime
SetFileTime
SetLocalTime
SetSystemTime
SetSystemTimeAdjustment
SetTimeZoneInformation
SystemTimeToFileTime
SystemTimeToTzSpecificLocalTime
---------------------------------------------------------------------------------------------

  • 시간을 연산하는 것이 말처럼 쉬운 것은 아니라고 생각 합니다. 밀리세컨드를 계산할때는 더욱 골치가 아프고 어떻게 연산을 해야 정확한 값을 가지고 오는지 여러번 테스트를 해야 합니다.
  • 가장 좋은 방법은 API를 활용하여 하나의 프로그램을 만드는 것도 좋지만 기존에 있는 좋은 라이브러리는 적절하게 사용하면 되겠습니다.
  • 그외 시간 관련 함수는 찾아

사용 방법 1. CTime

class CTime
{
public:

// Constructors
static CTime PASCAL GetCurrentTime();

CTime();
CTime(time_t time);
CTime(int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec,
int nDST = -1);
CTime(WORD wDosDate, WORD wDosTime, int nDST = -1);
CTime(const CTime& timeSrc);

CTime(const SYSTEMTIME& sysTime, int nDST = -1);
CTime(const FILETIME& fileTime, int nDST = -1);
const CTime& operator=(const CTime& timeSrc);
const CTime& operator=(time_t t);

// Attributes
struct tm* GetGmtTm(struct tm* ptm = NULL) const;
struct tm* GetLocalTm(struct tm* ptm = NULL) const;
BOOL GetAsSystemTime(SYSTEMTIME& timeDest) const;

time_t GetTime() const;
int GetYear() const;
int GetMonth() const; // month of year (1 = Jan)
int GetDay() const; // day of month
int GetHour() const;
int GetMinute() const;
int GetSecond() const;
int GetDayOfWeek() const; // 1=Sun, 2=Mon, ..., 7=Sat

// Operations
// time math
CTimeSpan operator-(CTime time) const;
CTime operator-(CTimeSpan timeSpan) const;
CTime operator+(CTimeSpan timeSpan) const;
const CTime& operator+=(CTimeSpan timeSpan);
const CTime& operator-=(CTimeSpan timeSpan);
BOOL operator==(CTime time) const;
BOOL operator!=(CTime time) const;
BOOL operator<(CTime time) const;
BOOL operator>(CTime time) const;
BOOL operator<=(CTime time) const;
BOOL operator>=(CTime time) const;

// formatting using "C" strftime
CString Format(LPCTSTR pFormat) const;
CString FormatGmt(LPCTSTR pFormat) const;
CString Format(UINT nFormatID) const;
CString FormatGmt(UINT nFormatID) const;

#ifdef _UNICODE
// for compatibility with MFC 3.x
CString Format(LPCSTR pFormat) const;
CString FormatGmt(LPCSTR pFormat) const;
#endif

// serialization
#ifdef _DEBUG
friend CDumpContext& AFXAPI operator<<(CDumpContext& dc, CTime time);
#endif
friend CArchive& AFXAPI operator<<(CArchive& ar, CTime time);
friend CArchive& AFXAPI operator>>(CArchive& ar, CTime& rtime);

private:
time_t m_time;
};




사용 방법 2. CTimeSpan

class CTimeSpan
{
public:

// Constructors
CTimeSpan();
CTimeSpan(time_t time);
CTimeSpan(LONG lDays, int nHours, int nMins, int nSecs);

CTimeSpan(const CTimeSpan& timeSpanSrc);
const CTimeSpan& operator=(const CTimeSpan& timeSpanSrc);

// Attributes
// extract parts
LONG GetDays() const; // total # of days
LONG GetTotalHours() const;
int GetHours() const;
LONG GetTotalMinutes() const;
int GetMinutes() const;
LONG GetTotalSeconds() const;
int GetSeconds() const;

// Operations
// time math
CTimeSpan operator-(CTimeSpan timeSpan) const;
CTimeSpan operator+(CTimeSpan timeSpan) const;
const CTimeSpan& operator+=(CTimeSpan timeSpan);
const CTimeSpan& operator-=(CTimeSpan timeSpan);
BOOL operator==(CTimeSpan timeSpan) const;
BOOL operator!=(CTimeSpan timeSpan) const;
BOOL operator<(CTimeSpan timeSpan) const;
BOOL operator>(CTimeSpan timeSpan) const;
BOOL operator<=(CTimeSpan timeSpan) const;
BOOL operator>=(CTimeSpan timeSpan) const;

#ifdef _UNICODE
// for compatibility with MFC 3.x
CString Format(LPCSTR pFormat) const;
#endif
CString Format(LPCTSTR pFormat) const;
CString Format(UINT nID) const;

// serialization
#ifdef _DEBUG
friend CDumpContext& AFXAPI operator<<(CDumpContext& dc,CTimeSpan timeSpan);
#endif
friend CArchive& AFXAPI operator<<(CArchive& ar, CTimeSpan timeSpan);
friend CArchive& AFXAPI operator>>(CArchive& ar, CTimeSpan& rtimeSpan);

private:
time_t m_timeSpan;
friend class CTime;
};




사용 방법 3. MFC CTime 클래스 사용


CString CurrentTimeText;
CTime CurTime;

CurTime = CTime::GetCurrentTime(); // 현재 시스템 시각을 구한다.

CurrentTimeText.Format( "현재 날짜 / 시각 : %04d-%02d-%02d / %02d:%02d:%02d",
, CurTime.GetYear()
, CurTime.GetMonth()
, CurTime.GetDay()
, CurTime.GetHour()
, CurTime.GetMinute()
, CurTime.GetSecond()
);



  • 출처 : http://kongmks.cafe24.com/239?TSSESSION=7329c8d8597d2af44015e2b666bb2e6f
  • CString 문자열 클래스에 현재 시간을 대입하여 Format로 각각의 년/월/요 시/분/초 로 정의 할 수 있습니다.

사용 방법 4. Millisecond(밀리세컨드) 현재 시간

SYSTEMTIME cur_time;
GetLocalTime(&cur_time);
CString strPCTime;


strPCTime.Format("%04d%02d%02d%02d%02d%02d%03ld",
cur_time.wYear,
cur_time.wMonth,
cur_time.wDay,
cur_time.wHour,
cur_time.wMinute,
cur_time.wSecond,
cur_time.wMilliseconds); );



  • 출처 : http://blog.naver.com/sanglyn/90047509460
  • CTime 클래스에 밀리세컨드가 없기 때문에 GetLocalTime() API 함수를 이용하여 밀리세컨드 값을 구합니다.


사용 방법 5. GetTickCount 활용 방법

SYSTEMTIME cur_time;

어떤 명령어의 수행시간을 측정하고 싶을때가 있다.
이때 유용하게 사용할수 있는 함수가 GetTickCount()이다.

GetTickCount()함수는 시스템이 시작 된 후 얼마의 시간이 경과했는지를 반환한다. 단위는 밀리세컨드 단위이다. 참고로 경과시간은 DWORD(32비트 값)이므로 최대 49.7일이 지나면 다시 0으로 된다고 한다.

The GetTickCount function retrieves the number of milliseconds that have elapsed since the system was started. It is limited to the resolution of the system timer. To obtain the system timer resolution, use the GetSystemTimeAdjustment function.

DWORD GetTickCount(void);

Parameters : This function has no parameters.
Return values : The return value is the number of milliseconds that have elapsed since the system was started.


#include
#include //GetTickCount()함수 이용을 위해 추가한다.

using namespace std;

void main()
{
long startTime = GetTickCount(); //현재 시각을 저장한다.(시작지점)

for(int i=0; i<100000; i++) //시간 딜레이를 주기 위해 i값을 출력한다.
cout<<

long endTime = GetTickCount(); //현재 시각을 저장한다.(종료지점)
long tickDiff = endTime - startTime; //수행시간 = 종료시각 - 시작시각
long secDiff = tickDiff / 1000 ; //이건 초단위로도 나타내기 위한 것.

cout<<"Start Time : "<<<"ms"<
cout<<"End Time : "<<<"ms"<
cout<<"Tick difference : "<<<"ms"<
cout<<"Second difference : "<<<"s"<
}



  • 출처 : http://dolbbi.com/83
  • 수행시간을 측정하는 방법이며 이것은 49.7일 지나면 0으로 반환 됩니다.

출처 : http://calmmass.tistory.com/220

Posted by rCan

2010/06/21 14:30 2010/06/21 14:30
Response
No Trackback , No Comment
RSS :
http://rcan.net/rss/response/598

미니마이즈

::ShowWindow(m_hParent, SW_MINIMIZE);

Posted by rCan

2010/06/18 18:57 2010/06/18 18:57
Response
No Trackback , No Comment
RSS :
http://rcan.net/rss/response/597

문자열 관련

1. CString to char *
ANSI 표준 함수인 strcpy 함수를 사용하여 변환한다.
ex)
CString strTemp;
char buffer[MAX_PATH];
//strcpy(buffer, (LPSTR)(LPCSTR)strTemp);
strcpy(buffer, strTemp.GetBuffer(strTemp.GetLength());
strTemp.ReleaseBuffer();

2. char * to CString
Type casting 을 통해 간단하게 사용한다.
ex)
CString strTemp;
char buffer[MAX_PATH];
strTemp=(LPSTR)buffer;
// (LPSTR)은 char *을 CString 형태로 변환한다.

[출처] : www.coolx.net

Posted by rCan

2010/04/05 09:51 2010/04/05 09:51
Response
No Trackback , No Comment
RSS :
http://rcan.net/rss/response/595

« Previous : 1 : 2 : 3 : 4 : 5 : Next »

블로그 이미지

- rCan

Calendar

«   2012/02   »
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29      

Notices

  1. About Me

Site Stats

Total hits:
113493
Today:
13
Yesterday:
37