336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

MFC Grid control 2.27 DragAndDrop Error








가끔씩 Grid 컨트롤 내의 셀을 컨트롤 밖으로 드래그앤드랍을 하게 되면 에러가 발생한다.






EnableDragRowMode(FALSE);



으로 설정해주니





해당 에러가 발생하지 않는다.






MFC Modal and Modeless Dialog Boxes

Programming/MFC 2016. 9. 6. 10:56 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Modal and Modeless Dialog Boxes




You can use class CDialog to manage two kinds of dialog boxes:

  • Modal dialog boxes, which require the user to respond before continuing the program

  • Modeless dialog boxes, which stay on the screen and are available for use at any time but permit other user activities

The resource editing and procedures for creating a dialog template are the same for modal and modeless dialog boxes.

Creating a dialog box for your program requires the following steps:

  1. Use the dialog editor to design the dialog box and create its dialog-template resource.

  2. Create a dialog class.

  3. Connect the dialog resource's controls to message handlers in the dialog class.

  4. Add data members associated with the dialog box's controls and to specify dialog data exchange and dialog data validations for the controls.




생성되는 윈도우는 두가지 형태가 있다.
대화가 필요한 모달형과, 대화가 필요없는 모달리스

대화가 필요한 모달형은 대화를 마치지 않으면 다음으로 넘어갈 수 없는 윈도우다.
즉, 파일열기를 해서 파일목록이 나오고 파일을 선택하는 윈도우가 팝업되었을 때, 
그 윈도우창을 무시하고 그 전의 윈도우를 컨트롤 할 수 없도록 되어있다. (취소를 하시든가)
무조건 적으로 대화가 필요한 모달형에 비해,
대화가 필요없는 모달리스형이 있다.
모달리스형은 익스플로러를 하면서 Ctrl F키를 눌러서 찾기 기능을 사용할 때, 개념을 찾을 수 있는데, 
찾기 윈도우가 팝업되었지만, 기존의 익스플로러 윈도우에도 편하게 접근이 가능하다.
대화따위... 존재하지 않은지가 오랜지...


Modal Dialog

써먹을려면 CDialog 클래스의 일부함수를 재정의 해야 하는데, 
이렇게 가상함수들을 재정의할 때, 함수의 호출 시점을 꿰고있는게 좋을 것이다.

대화상자 객체를 주로 스택에 생성한다.

virtual BOOL CDialog::OnInitDialog();
호출 : CDialog::DoModal() 함수에 의해서 대화상자가 생성되고 WM_CREATE메시지가 발생하게 된다.
        OS는 이 메시지를 받고, Dialog 템플릿에 선언된 컨트롤을 모두 생성한 후 대화상자가 화면에 보이기전에
        WM_INITDIALOG 메시지를 발생시키는데, 이 때 OnInitDialog()함수가 호출된다.
        즉, OnInitDialog()함수는 WM_INITDIALOG메시지 핸들러라고 할 수 있다.
사용 : 컨트롤 초기화 및, 키보드 포커스 변경시 사용

virtual void CDialog::OnOk();
호출 : 사용자가 OK버튼을 누르면 호출된다. (id값이 IDOK인 버튼)
        즉, OnOk()함수는 OK버튼클릭 메시지 핸들러라고 할 수 있다.
사용 : 컨트롤 값을 읽거나 값의 타당성을 검사한 후 Dialog 닫기

virtual void CDialog::OnCancel();
호출 : 사용자가 Cancel버튼을 누르면 호출된다. (id값이 IDCANCEL인 버튼)
        즉, OnCancel()함수는 Cancel버튼클릭 메시지 핸들러라고 할 수 있다.
사용 : 대화상자 닫기.

위의 3가지 함수는 메시지핸들러의 기능을 하지만, 가상함수로 정의되어 있으므로 
굳이 메시지 맵이 필요없이 자동 호출된다.

생성은 CDialog::DoModal(), 닫을때는 CDialog::EndDialog()
OnOk()나 OnCancel()함수는 자동으로 EndDialog() 호출하므로,
만약 다른 방법으로 대화상자를 닫기 원할 때, CDialog::EndDialog() 호출하면 된다.



Modeless Dialog

주의사항. 모달형과 생성 및 닫는 함수가 다르다.
DoModal()대신 CDialog::Create()
EndDialog()대신 CWnd::DestroyWindow() 함수를 사용한다.
대화상자 객체를 힙에 생성한다.
(스택에 객체를 생성해버리면 변수선언영역을 벗어났을때 소멸자가 호출되어 대화상자가 소멸되므로
대화상자를 계속 유지할 수 없기 때문이다.)





'Programming > MFC' 카테고리의 다른 글

공유 DLL에서 MFC 사용 VS 정적 라이브러리에서 MFC 사용  (0) 2016.10.06
MFC Dialog Modal  (0) 2016.09.22
MFC Alert MessageBox2  (0) 2016.09.06
MFC Alert MessageBox  (0) 2016.09.06
MFC Drag And Drop FileName 만 추출  (0) 2016.08.30

MFC Alert MessageBox2

Programming/MFC 2016. 9. 6. 10:47 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

      int MessageBox(
   LPCTSTR lpszText,
   LPCTSTR lpszCaption = NULL,
   UINT nType = MB_OK 
);

lpszText

가리키는 있는 CString 개체 또는 표시 되는 메시지에 포함 된 null로 끝나는 문자열입니다.

lpszCaption

가리키는 있는 CString 개체 또는 null로 끝나는 문자열에 대 한 캡션을 메시지 상자를 사용할 수 있습니다. 경우 lpszCaption  NULL, 기본 캡션을 "오류"를 사용 합니다.

nType

콘텐츠 및 메시지 상자의 동작을 지정합니다.


전역 함수 사용 AfxMessageBox 응용 프로그램에서 메시지 상자를 구현 하려면이 멤버 함수를 대신 합니다.

다음은 메시지 상자에 사용할 수 있는 다양 한 시스템 아이콘입니다.

중지(x) 아이콘

MB_ICONHANDMB_ICONSTOP, 및 MB_ICONERROR

도움말(?) 아이콘

MB_ICONQUESTION

중요(!) 아이콘

MB_ICONEXCLAMATION 및 MB_ICONWARNING

정보(i) 아이콘

MB_ICONASTERISK 및 MB_ICONINFORMATION









void CMainFrame::OnDisplayErrorMessage()
{
   // This displays a message box with the title "Error"
   // and the message "Help, Something went wrong."
   // The error icon is displayed in the message box, along with
   // an OK button.
   MessageBox(_T("Help, Something went wrong."), _T("Error"), 
      MB_ICONERROR | MB_OK);
}




'Programming > MFC' 카테고리의 다른 글

MFC Dialog Modal  (0) 2016.09.22
MFC Modal and Modeless Dialog Boxes  (0) 2016.09.06
MFC Alert MessageBox  (0) 2016.09.06
MFC Drag And Drop FileName 만 추출  (0) 2016.08.30
MFC File Icon Drag and Drop  (0) 2016.08.30

MFC Alert MessageBox

Programming/MFC 2016. 9. 6. 10:40 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

MFC Alert MessageBox


MessageBox 클래스

.NET Framework (current version)
 

사용자에게 메시지를 보여 주는 메시지 창을 표시합니다. 이 창을 대화 상자라고도 합니다. 이 창은 사용자가 닫을 때까지 응용 프로그램의 다른 동작을 차단하는 모달 창입니다. MessageBox에는 사용자에게 필요한 정보와 명령을 제공하는 텍스트, 단추 및 기호가 포함될 수 있습니다.

네임스페이스:   System.Windows.Forms
어셈블리:  System.Windows.Forms.dll의 System.Windows.Forms




private:
   void validateUserEntry()
   {
      // Checks the value of the text.
      if ( serverName->Text->Length == 0 )
      {
         // Initializes the variables to pass to the MessageBox::Show method.
         String^ message = "You did not enter a server name. Cancel this operation?";
         String^ caption = "No Server Name Specified";
         MessageBoxButtons buttons = MessageBoxButtons::YesNo;
         System::Windows::Forms::DialogResult result;

         // Displays the MessageBox.
         result = MessageBox::Show( this, message, caption, buttons );
         if ( result == ::DialogResult::Yes )
         {
            // Closes the parent form.
            this->Close();
         }
      }
   }



private:
   void Form1_FormClosing(Object^ sender, FormClosingEventArgs^ e)
   {
	  // If the no button was pressed ...
      if ((MessageBox::Show(
         "Are you sure that you would like to close the form?", 
         "Form Closing", MessageBoxButtons::YesNo, 
         MessageBoxIcon::Question) == DialogResult::No))
      {
		 // cancel the closure of the form.
         e->Cancel = true;
      }
   }



'Programming > MFC' 카테고리의 다른 글

MFC Modal and Modeless Dialog Boxes  (0) 2016.09.06
MFC Alert MessageBox2  (0) 2016.09.06
MFC Drag And Drop FileName 만 추출  (0) 2016.08.30
MFC File Icon Drag and Drop  (0) 2016.08.30
MFC Dialog 가 이상한 위치에 배치, (0,0)에 배치  (0) 2016.08.24
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

CPP aes128 cbc mode Encryption Decryption



AES


Encryption Block  : 

128 비트

192 비트 

256 비트


Mode :    

1. ECB ( Electric Code Book )

http://jo.centis1504.net/wp-content/uploads/2010/11/Encryption-ECB_MODE.swf




2. CBC ( Cipher Block Chaining )

http://jo.centis1504.net/wp-content/uploads/2010/11/Encryption-CBC_MODE.swf





3. OFB ( Output Feed Back )

http://jo.centis1504.net/wp-content/uploads/2010/11/Encryption-OFB_MODE.swf



4. CFB ( Cipher Feed Back )



5. CTR ( CounTeR )



모드별 설명은


관련 자료 참고 : http://www.parkjonghyuk.net/lecture/modernCrypto/lecturenote/chap04.pdf




구현에서는 CTR 모드로 구현하였다.






개발 환경 : Windows 7 64bit, VS 2013



최신버전으로 직접 빌드하시려면 아래의 링크를 참조하시기 바랍니다.


귀찮으신 분은 빌드된 버전을 사용합시다.


OpenSSL 빌드 : http://yokkohama.tistory.com/entry/OpenSSL-%EB%B9%8C%EB%93%9C%ED%95%98%EA%B8%B0-Visual-Studio-2010-%EB%98%90%EB%8A%94-libeay32dll-ssleay32dll-%EB%8B%A4%EC%9A%B4%EB%A1%9C%EB%93%9C



"openssl-1.0.1f_vc_no-idea no-mdc2 no-rc5_build.zip" 는 no-idea no-mdc2 no-rc5  로 빌드된, 특허문제가 해결 된 바이너리입니다.


openssl-1.0.1f_vc_no-idea no-mdc2 no-rc5_build.zip



압축 해제 후 파일을 프로젝트 폴더로 이동



프로젝트속성 > VC++ 디렉터리 > 디렉터리 설정 (포함 디렉터리, 라이브러리 디렉터리)






별도의 클래스를 만들어 사용 하였습니다.







#pragma once

#include 
#include 
#include 
#include 


struct ctr_state {
	unsigned char ivec[AES_BLOCK_SIZE];
	unsigned int num;
	unsigned char ecount[AES_BLOCK_SIZE];
};



class CAESCTR
{
public:
	AES_KEY key;
	int BYTES_SIZE = 1024;
	int KEY_SIZE = 128;
	unsigned char ckey[32];
	unsigned char iv[8];
	int init_ctr(struct ctr_state *state, const unsigned char iv[8]);
	void encrypt(unsigned char *indata, unsigned char *outdata, int bytes_read);
	void encrypt(CString& indata, CString& outdata, int bytes_read);
	CAESCTR();
	CAESCTR::CAESCTR(unsigned char* iv, unsigned char* ckey);
	~CAESCTR();
};







#include "stdafx.h"
#include "AESCTR.h"

int CAESCTR::init_ctr(struct ctr_state *state, const unsigned char iv[8]){
	state->num = 0;
	memset(state->ecount, 0, AES_BLOCK_SIZE);
	memset(state->ivec + 8, 0, 8);
	memcpy(state->ivec, iv, 8);

	return 0;
}
// encrypt twice  == decrypt

void CAESCTR::encrypt(unsigned char *indata, unsigned char *outdata, int bytes_read){

	int i = 0;
	int mod_len = 0;

	AES_set_encrypt_key(ckey, KEY_SIZE, &key);

	if (bytes_read < BYTES_SIZE){
		struct ctr_state state;
		init_ctr(&state, iv);
		AES_ctr128_encrypt(indata, outdata, bytes_read, &key, state.ivec, state.ecount, &state.num);
		return;
	}
	// loop block size  = [ BYTES_SIZE ]
	for (i = BYTES_SIZE; i <= bytes_read; i += BYTES_SIZE){
		struct ctr_state state;
		init_ctr(&state, iv);
		AES_ctr128_encrypt(indata, outdata, BYTES_SIZE, &key, state.ivec, state.ecount, &state.num);
		indata += BYTES_SIZE;
		outdata += BYTES_SIZE;
	}

	mod_len = bytes_read % BYTES_SIZE;
	if (mod_len != 0){
		struct ctr_state state;
		init_ctr(&state, iv);
		AES_ctr128_encrypt(indata, outdata, mod_len, &key, state.ivec, state.ecount, &state.num);
	}
}

void CAESCTR::encrypt(CString& instr, CString& outstr, int bytes_read){

	int i = 0;
	int mod_len = 0;
	unsigned char *indata;
	unsigned char *outdata;

	indata = (unsigned char *)malloc(instr.GetLength() + 1);
	outdata = (unsigned char *)malloc(instr.GetLength() + 1);



	strncpy((char*)indata, (LPSTR)(LPCSTR)instr, instr.GetLength());
	indata[instr.GetLength()] = NULL;


	

	AES_set_encrypt_key(ckey, KEY_SIZE, &key);

	if (bytes_read < BYTES_SIZE){
		struct ctr_state state;
		init_ctr(&state, iv);
		AES_ctr128_encrypt(indata, outdata, bytes_read, &key, state.ivec, state.ecount, &state.num);

		outdata[instr.GetLength()] = NULL;
		outstr = outdata;
		return;
	}
	// loop block size  = [ BYTES_SIZE ]
	for (i = BYTES_SIZE; i <= bytes_read; i += BYTES_SIZE){
		struct ctr_state state;
		init_ctr(&state, iv);
		AES_ctr128_encrypt(indata, outdata, BYTES_SIZE, &key, state.ivec, state.ecount, &state.num);
		indata += BYTES_SIZE;
		outdata += BYTES_SIZE;
	}

	mod_len = bytes_read % BYTES_SIZE;
	if (mod_len != 0){
		struct ctr_state state;
		init_ctr(&state, iv);
		AES_ctr128_encrypt(indata, outdata, mod_len, &key, state.ivec, state.ecount, &state.num);
	}
	outdata[instr.GetLength()] = NULL;
	outstr = outdata;
}

CAESCTR::CAESCTR()
{
	unsigned char temp_iv[8] = { 0x66, 0x61, 0x63, 0x65, 0x73, 0x65, 0x61, 0x00 };
	memcpy(iv, temp_iv, 8);

	unsigned char temp_ckey[32] = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
		0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
		0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
		0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56 }; // 32bytes = AES256, 16bytes = AES128
	memcpy(ckey, temp_ckey, 32);
}

CAESCTR::CAESCTR(unsigned char* iv, unsigned char* ckey)
{
	memcpy(this->iv, iv, 8);
	memcpy(this->ckey, ckey, 32);
}

CAESCTR::~CAESCTR()
{
}






그리고, 프로젝트 속성에서


구성 속성 > 문자 집합 > 설정 안 함


으로 하여서 사용하였습니다.



사용예시










void CPasswordEncoderDlg::OnEnChangeEdit1()
{
	// TODO:  RICHEDIT 컨트롤인 경우, 이 컨트롤은
	// CDialogEx::OnInitDialog() 함수를 재지정 
	//하고 마스크에 OR 연산하여 설정된 ENM_CHANGE 플래그를 지정하여 CRichEditCtrl().SetEventMask()를 호출하지 않으면
	// 이 알림 메시지를 보내지 않습니다.

	// TODO:  여기에 컨트롤 알림 처리기 코드를 추가합니다.
	CAESCTR m_AESCTR;

	CString editText;
	m_Edit1.GetWindowTextA(editText);
		
	int editTextLength = editText.GetLength();

	unsigned char* editTextCharSeq;
	editTextCharSeq = (unsigned char *)malloc(editTextLength+1);

	strncpy((char*)editTextCharSeq, (LPSTR)(LPCSTR)editText, editTextLength);
	editTextCharSeq[editTextLength] = NULL;

	unsigned char* outTextCharSeq;
	outTextCharSeq = (unsigned char *)malloc(editTextLength + 1);

	m_AESCTR.encrypt(editTextCharSeq, outTextCharSeq, editTextLength);
	outTextCharSeq[editTextLength] = NULL;
	
	editText = outTextCharSeq;
	m_Edit2.SetWindowTextA(editText);
	
	m_AESCTR.encrypt(editText, editText, editTextLength);

	m_Edit3.SetWindowTextA(editText);

	free(editTextCharSeq);
	free(outTextCharSeq);
}










'Programming > C,CPP,CS' 카테고리의 다른 글

openssl AES encrypt (AES_ctr128_encrypt)  (0) 2016.09.19
openssl AES Mode : ECB, CBC, CFB, OFB, CTR  (0) 2016.09.05
CDateTimeCtrl 사용법  (0) 2016.08.25
Apache License, Version 2.0  (0) 2016.08.22
Log4cxx ChainSaw Appender  (0) 2016.08.22

MFC File Icon Drag and Drop

Programming/MFC 2016. 8. 30. 11:19 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

MFC File Icon Drag and Drop










드래그앤드랍기능을 쓰고 싶은


Dialog 나 ListControl 을 리소스 뷰에서 선택한다.











속성 항목


[동작] [Accept Files] 항목을 True 로 바꾼다.



Files 을 드래그앤드랍으로 받을 수 있게 된다.












해당 컴포넌트에 드래그앤드랍이 발생할 경우


OnDropFiles(HDROP hDropInfo)


함수로 메시지가 들어오게 된다.











해당 함수를 오버라이딩 하는 방법은


해당 컴포넌트의 Dialog 클래스를


클래스 뷰에서 선택하고 속성 창을 연다.






WM_DROPFILES 메시지에 OnDropFiles 를 활성화 시켜준다.







그러면 Dialog 클래스 cpp 파일에 OnDropFiles 함수가 생성된다.






다음 코드를 OnDropFiles(HDROP hDropInfo) 함수에 추가하여 실행하여 본다.





  int nFiles;


char szPathName[MAX_PATH];  // 파일 경로명이 들어간다.


CString strFileName;


// 드래그앤드롭된 파일의 갯수

nFiles = ::DragQueryFile(hDropInfo, 0xFFFFFFFF, szPathName, MAX_PATH);


for (int i = 0; i < nFiles; i++)

{

// 파일의 경로 얻어옴

::DragQueryFile(hDropInfo, i, szPathName, MAX_PATH);

MessageBox(szPathName, "DropAndDropFile");

}










CDateTimeCtrl 사용법

Programming/C,CPP,CS 2016. 8. 25. 17:56 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

CDateTimeCtrl 사용법



이름

설명

CDateTimeCtrl::CloseMonthCal

현재 날짜 및 시간 선택 컨트롤을 닫습니다.

CDateTimeCtrl::Create

날짜 및 시간 선택 컨트롤을 만들고이에 연결 된 CDateTimeCtrl 개체입니다.

CDateTimeCtrl::GetDateTimePickerInfo

현재 날짜 및 시간 선택 컨트롤에 대 한 정보를 검색합니다.

CDateTimeCtrl::GetIdealSize

현재 날짜나 시간을 표시 하는 데 필요한 시간 및 날짜 선택 컨트롤의 이상적인 크기를 반환 합니다.

CDateTimeCtrl::GetMonthCalColor

월 달력에서 날짜 및 시간 선택 컨트롤의 특정된 부분에 대 한 색을 검색합니다.

CDateTimeCtrl::GetMonthCalCtrl

검색은 CMonthCalCtrl 개체의 날짜 및 시간 선택 컨트롤에 연결 합니다.

CDateTimeCtrl::GetMonthCalFont

현재 날짜 및 시간 선택 컨트롤의 자식 컨트롤에서 사용 되는 글꼴을 검색 합니다.

CDateTimeCtrl::GetMonthCalStyle

현재 날짜 및 시간 선택 컨트롤의 스타일을 가져옵니다.

CDateTimeCtrl::GetRange

현재 최소 및 최대 허용 시스템 시간 날짜 및 시간 선택 컨트롤을 검색 합니다.

CDateTimeCtrl::GetTime

날짜 및 시간 선택 컨트롤에서 현재 선택한 시간을 검색 하 고 지정 된 배치 SYSTEMTIME 구조.

CDateTimeCtrl::SetFormat

지정 된 형식 문자열에 따라 날짜 및 시간 선택 컨트롤의 표시를 설정합니다.

CDateTimeCtrl::SetMonthCalColor

월 달력에서 날짜 및 시간 선택 컨트롤의 특정된 부분에 대 한 색을 설정합니다.

CDateTimeCtrl::SetMonthCalFont

날짜 및 시간 선택 컨트롤의 자식 컨트롤을 사용 하는 글꼴을 설정 합니다.

CDateTimeCtrl::SetMonthCalStyle

현재 날짜 및 시간 선택 컨트롤의 스타일을 설정합니다.

CDateTimeCtrl::SetRange

날짜 및 시간 선택 컨트롤에 대 한 최소 및 최대 허용 된 시스템 시간을 설정합니다.

CDateTimeCtrl::SetTime

날짜 및 시간 선택 컨트롤에는 시간을 설정합니다.




// set with a CTime
CTime timeTime(1998, 4, 3, 0, 0, 0);
VERIFY(m_DateTimeCtrl.SetTime(&timeTime));

// set with a COleDateTime object
COleDateTime oletimeTime(1998, 4, 3, 0, 0, 0);
VERIFY(m_DateTimeCtrl.SetTime(oletimeTime));

// set using the SYSTEMTIME
SYSTEMTIME sysTime;
memset(&sysTime, 0, sizeof(sysTime));
sysTime.wYear = 1998;
sysTime.wMonth = 4;
sysTime.wDay = 3;
VERIFY(m_DateTimeCtrl.SetTime(&sysTime));
void CDateTimeDlg::OnBnClickedTimebutton()
{
   // get as a CTime
   CTime timeTime;
   DWORD dwResult = m_DateTimeCtrl.GetTime(timeTime);
   if (dwResult == GDT_VALID)
   {
      // the user checked the box and specified data
      CString str;

      // is it a time-only control, or a date-only control?
      if ((m_DateTimeCtrl.GetStyle() & DTS_TIMEFORMAT) == DTS_TIMEFORMAT)
         str = timeTime.Format(_T("%X"));
      else
         str = timeTime.Format(_T("%x"));
      AfxMessageBox(str);
   }
   else
   {
      // the user unmarked the "none" box
      AfxMessageBox(_T("Time not set!"));
   }

   // Calling as SYSTIME is much the same, but calling for a COleDateTime
   // has us test the state of the COleDateTime object for validity to 
   // see if the user did or didn't check the "none" box.
}











336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

MFC Dialog 가 이상한 위치에 배치, (0,0)에 배치



MFC TabCtrl 기반의 Dialog 를 Child로 배치 하였을때






Tab 별 Child Dialog 가 (0,0) 위치에 배치되어


TabCtrl 이 보이지 않는 경우가 발생하는 경우,













Child Dialog 가 OnInitDialog 실행 중 예외처리나 비정상 처리로 인해


제대로 된 값을 반환하지 못하는 경우


그런 상태가 발생 할 수 있다.





예외처리 시 return 으로


OnInitDialog 를 정상적으로 종료시킨 후 


동작시켜야 한다.










336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

log4cxx MFC Client 와 log4j Java Server 연결



MFC Client 는 로그를 파일과 서버로 보내고,


Java Server 는 여러개의 MFC Client 가 보내는 로그를 저장한다.




테스트 환경은


MFC Client 와 Java Server 가 동일 호스트 이다.




MFC Client


log4j.rootLogger=DEBUG, filelog, remoteserver


rootLogger 에 필요한 로그 Appender 를 추가한다.


remoteserver라는 Appender 를 설정한다.


SocketAppender 를 사용하고, localhost:4445 에 연결한다.


# using remoteserver appender

log4j.appender.remoteserver=org.apache.log4j.net.SocketAppender

log4j.appender.remoteserver.remoteHost=localhost

log4j.appender.remoteserver.port=4445

log4j.appender.remoteserver.locationInfo=true

log4j.appender.remoteserver.ReconnectionDelay=10000






Java Server



테스트에서는 


log4j-1.2.17 버전을 사용하였다.


log4j-1.2.17.zip



압축을 푼 후 jar 파일을 Library 로 add 한다.





서버의 설정은 log4j-server.properties


RollingFileAppender 를 사용하여


파일 단위로 Log 를 저장한다.




log4j.rootLogger=DEBUG, file

log4j.appender.file=org.apache.log4j.RollingFileAppender

log4j.appender.file.File=logfile.log

log4j.appender.file.MaxFileSize=1MB

log4j.appender.file.MaxBackupIndex=1

log4j.appender.file.layout=org.apache.log4j.PatternLayout

log4j.appender.file.layout.ConversionPattern=[%d] [%t] [%m]%n





Java Server Code



public class Test

{

public static void main(String[] args) {

        try  

        {  

       

        String[] arguments = {"4445", "log4j-server.properties"};  

        SimpleSocketServer.main(arguments);  


        }  

        catch (Exception ex)  

        {  

          System.out.println(ex.getMessage());

        }  

}

}





MFC CTextProgressCtrl

Programming/MFC 2016. 8. 17. 15:50 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

MFC CTextProgressCtrl




코드만 가져다가 ProgressCtrl 을 TextProgressCtrl 로 변환 시켜서 사용할 수 있다.






MemDC 가 필요한데 VS2010 이상 버전에서는


CGridCtrl 을 참고하여 추가 설정이 필요하다.

(시스템에 존재하는 MemDC 클래스와 중복되기 때문)












http://www.codeproject.com/Articles/80/Progress-Control-with-Text


Progress Control with Text

























This is a simple CProgressCtrl derived class that allows text to be displayed on top of the progress bar in much the same way as many "Setup" programs display the progress of long operations.

The control is extremely simple and allows the same operations as a standard CProgressCtrl, as well as: 

void SetShowText(BOOL bShow);Specifies whether or not the text for the control will be displayed during updates
COLORREF SetBarColor(COLORREF crBarClr = CLR_DEFAULT);Specifies the colour of the progress control bar, and returns the previous colour. If the colour is set asCLR_DEFAULT then the Windows default colour is used.
COLORREF GetBarColor();Returns the colour of the progress control bar, orCLR_DEFAULT if the default Windows colours are being used.
COLORREF SetBarBkColor(COLORREF crBarClr = CLR_DEFAULT);Specifies the colour for the control's background, and returns the previous background colour. If the colour is set as CLR_DEFAULT then the Windows default colour is used.
COLORREF GetBarBkColor();Returns the colour of the control's background, orCLR_DEFAULT if the default Windows colours are being used.
COLORREF SetTextColor(COLORREF crBarClr = CLR_DEFAULT);Specifies the colour of the text, and returns the previous colour. If the colour is set as CLR_DEFAULT then the Windows default colour is used.
COLORREF GetTextColor();Returns the colour of the text, or CLR_DEFAULT if the default Windows colours are being used.
COLORREF SetTextBkColor(COLORREF crBarClr = CLR_DEFAULT);Specifies the background colour of the text, and returns the previous background colour. If the colour is set asCLR_DEFAULT then the Windows default colour is used.
COLORREF GetTextBkColor();Returns the background colour of the text, orCLR_DEFAULT if the default Windows colours are being used.
BOOL SetShowPercent(BOOL bShow)Sets whether or not to show the percentage value of the bar, and returns the old value
DWORD AlignText(DWORD dwAlignment = DT_CENTER)Sets the text alignment and returns the old value
BOOL SetMarquee(BOOL bOn, UINT uMsecBetweenUpdate)Sets whether or not the progress control is in marquee mode, as well as the interval in milliseconds between steps of the marquee block
int SetMarqueeOptions(int nBarSize)Sets the size of the marquee as a percentage of the total control width

To set the text to be displayed use the standard CWnd::SetWindowText. If you call SetShowText(TRUE) but do not specify any window text using CWnd::SetWindowText, then the percentage fraction of progress will be displayed as default.

To use the control, just include a CProgressCtrl in your app as per usual (either dynamically or by using a dialog template) and change the variable type from CProgressCtrl to CTextProgressCtrl. (Make sure you include TextProgressCtrl.h)

At present the progress is only displayed as a smooth bar, and colours are strictly windows default colours. (These may be changed in the future versions.)

Acknowledgements
Thanks to Keith Rule for his CMemDC class.

Updates

Pete Arends went to town on the code. His updates:

  1. Set the font used to the parent window font
  2. Added SetTextColour() and GetTextColour() functions
  3. Added a bunch of message handlers, so the control now responds to the standard progress bar PBM_*messages. It is now possible to control the text progress control by sending messages to it. (works great from a worker thread).
  4. Added 2 new messages PBM_SETSHOWTEXT and PBM_SETTEXTCOLOR.
  5. Added an OnGetPos() handler. The function GetPos() now works!!

Thanks Pete!

3 Jan 05: Kriz has also extended the code with two basic methods that allow switching between the three alignment styles LEFTCENTER and RIGHT - even on the fly if that's needed.

Changes to the code

  • Created a protected DWORD member m_dwTextStyle
  • Disabled all dwTextStyle variables in OnPaint or replaced them by
    m_dwTextStyle
  • Added two methods called AlignText and AlignTextInvalidate

Syntax

BOOL AlignText(DWORD aligment = DT_CENTER);
BOOL AlignTextInvalidate(DWORD aligment = DT_CENTER);

Params/Return:

"alignment" can be DT_LEFTDT_CENTER (default) or DT_RIGHT. Using the invalidating version forces the control to repaint itself automatically. Both methods will return FALSE if a wrong alignment flag was given, otherwise they will return TRUE to the caller.

Thank you Kriz!

I've also updated the code so it compiles in VC7.X.

9 mar 06: Tony Bommarito has updated the code to include more settings for colours, made corrections to vertical text mode and added a new marquee mode.

26 Feb 07: Tony Mommarito has provided further updates:

  • Fixed bug where outside edge of progress bar wasn't drawn on XP when using an application manifest.
  • Added complete turn-off of marquee mode in a slightly different manner than that suggested in Robert Pickford message.
  • Fixed Unicode compile bug reported in dev75040 message.
  • Added three SLN and VCPROJ file sets; one each for VS2002, VS2003 and VS2005. By removing the VS… extension from the proper set, any of the three IDEs can be used.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)