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

일이 손에 잡히지 않는다.. 어떻게 하지...

일이 손에 잡히지 않는다.. 어떻게 하지...

아니..... 정확한것은 내가 무엇을 해야 할지를 모르겠다..
내가 여기서 뭘 하고 싶은건지 .. 무엇을 찾고 있는건지...
아무것도 모르겠다.
그냥 시간이 흐름에 따라 흘러가고 있다.

이대로 간다면 그냥 그저 그런 인생이 될 것 같다..

아니 ..... 그저 그런 인생도 못될 것 같다..
그저 그런 인생 남들이 생각하는 그저 그런 인생
평범한 인생
나에겐 그런것조차도 힘들것같다..

이대로 간다면 그냥 그저 그런 사람이 될 것 같다..

아니 ..... 그저 그런 사람도 못 될 것같다.
그저 그런 사람 남들이 생각하는 그저 그런 사람
평범한 사람
나에겐 그런것조차도 힘들것같다..

Posted by rCan

2010/10/11 11:39 2010/10/11 11:39
Response
No Trackback , a comment
RSS :
http://rcan.net/rss/response/603

[소니카메라]

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

깊은 밤 끄적끄적

The sound of silence
깊은 밤에 이 노래 듣고 있으니 참....
지금 티비에서 콘서트7080 보고있는데 옛날생각도 나면서
한편으로는 침울 해지는데 -_-..

아참 오늘은 오랜만에... 고딩동창을 우연히 보게 되었는데.
10년이면 강산이 변하지만.
아직 변한게 없는 친구와 짧은 만남과 다시 만날 날을 기약하며 해어졌다.

위에 쓰고 나니 조금 슬픈듯한 뤼앙스를 풍기고 있는데..
핸드폰 번호 서로 적고 해어졌다..

왠지.. 뒤에 문장에 핸드폰 번호 적고 해어졌다라고 쓸려고 하니 좀 이상해서..

아날로그 시대가 참 좋았던거 같다..
뭐랄까.. 지금은 거의 대부분의 사람들이 핸드폰을 가지고 있다.
예전에는 핸드폰이 나오기전에는.. 삐삐라는게 있었지만.
지금처럼 1:1로 대화 할 수 있는거라곤 전화선이 달려있는 전화였는데...

10년후에 만난 친구를 봤다면 서로 이야기 하면서 전화번호 교환?을.. 하며
진정으로 아쉬운 마음으로 해어졌을 것 같다.
지금은 핸드폰이라는 것 때문에 조금 사람들의 관계가 차가워 진거 같다.
아니 관계는 예전보다 가까워 졌다고 할 수 있을 것 같다.
하지만 서로간의 마음이 차가워 졌다고 해야 하나...

오랜만에 만난 친구들과 함께 이야기하다가 해어질때 서로 핸드폰 번호 교환하고
헤어지는게 대부분의 사람들이 패턴일 것 같다. 물론 아닐수도..


그건 그렇고 자기가 하고 싶은 것을 하고 싶어서 공부하고 있다는 말에 조금은 부러웠다.
나는 지금 뭘 하고 있는지... 뭐 .. 나름 열심히 나대로 노력은 하고 있는데..
내가 하고 싶어 하는 일을 하고 있긴 하지만

어딘가 모르게 마음속에는 뻥뚤려있는 마음이 있었는데..
오늘 친구와 대화를 하면서 조금더 조금더 그 구멍이 커져 가는것 같았다..

이 글을 보는 사람들이 모두 한번씩 생각해보면 좋겠습니다.
지금 자신은 행복한가요? 자신의 일에 만족한가요?
만족하지 못하다면 행복하지 못하다면 무엇때문에 그런가요.
그것을 찾으셧다면 그것을 채우기 위해서 계획을 만들어 보는건 어떨지요.

Posted by rCan

2010/08/22 01:58 2010/08/22 01:58
Response
No Trackback , No Comment
RSS :
http://rcan.net/rss/response/601

파일기록

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

무서운 꿈

저녁 10시쯤 자리에 누웠다.
잠이 오지 않아서 티비를 켜서 티비를 보다가 갑자기 졸음이 몰려와 티비를 끄고
잠을 청했다.

그러고 몇 분후 누군가 내 팔을 잡아 당겼다.
아프게 당긴것도 살살 당긴것도 잠을 살짝 깨울정도로 팔을 당겼다.
눈을뜨자 마자. 아 가위구나 하는 생각에 가위를 풀려고 노력을 해보았다.
누군가 당기는 손의 반대편 손은 자유롭게 움직일 수가 있었다.
그렇다면 가위는 풀린것같은데 아직도 한쪽팔을 누군가가 당기고 있다.

너무 무서워서 당겨지는 반대손으로 당기는 손을 내 몸쪽으로 끌어 당기려고 하자
몸전체를 누르는 듯한 힘을 느꼇다.
아.. 이번엔 이중 가위인건가 하면서 내 가위를 풀려고 노력했다.

노력이라고 해봤자 손을 움직여서 가위를 풀려고 했지만 노력은 허사가 되었다.
누군가가 내 옆에 누워있는 느낌을 받았다.

심각한 가위라 생각하고 어떻게든 풀려고 노력했다.
10분 15분 시간이 지났을 무렵 가위는 풀렸다.
그리고 그 공포심에 아악! 하고 소리를 지르며 몸을 움직였다.

집전체는 고요했다. 아무도 내 소리를 못들은 것 처럼.
전에는 이런 일이 없었기에 너무나도 무서워서
어머니가 주무시는 마루로 나가서 옆에 누웠다.
어머니는 살짝 깨셔서 왜 그러냐고 물으셧다.
나는 그냥 무서워서 나왔다고 했다.

그리고 잠시후 또 눈을 감았다.

그러자 이번에는 이불속에서 누군가가 있다... 이불속에서 나를 노려보고 있다.
이불속을 차마 볼 수 없었다.
하체를 덮고 있던 이불은 점점 부풀어 났다.
마치 짐승이라도 들어온 것처럼 점점 더 커져 갔다.
잠시후 그것은 나의 하체를 밀기 시작했다.

점점 점점..

점점 더 거칠게

밀기 시작했다.

나의 하체는 그 통증을 느끼기 시작했다.
그가 누르면 누를수록 밀면 밀수록 더욱더 통증은 고통은 더욱 커져만 갔다.

결국 내 몸은 그 힘을 이기지 못하고 벽쪽으로 쭈욱 밀려갔다.
벽과 만나는 동시에 아악 하고 소리질러보았지만 목소리는 나오지 않았다.
분명 벽과 부디쳤을꺼라고 생각은 했지만 내 몸은 벽과 만나지 않고
그대로 그벽을 통과하여 아무것도 보이지 않은 어두운 곳으로 밀려갔다.

그리고 몇분후 나는 소리를 지르며 내가 자던 방에서 깨어났다.

Posted by rCan

2010/05/06 09:58 2010/05/06 09:58
Response
No Trackback , a comment
RSS :
http://rcan.net/rss/response/596

문자열 관련

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


블로그 이미지

- rCan

Calendar

«   2010/01   »
    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 30 31    

Notices

  1. About Me

Site Stats

Total hits:
113493
Today:
13
Yesterday:
37