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

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



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






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


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













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


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


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





예외처리 시 return 으로


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


동작시켜야 한다.










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)







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

Visual Studio 2013에서 MSFlexGrid 추가 할 때 Error




Dialog 에서 ActiveX 컨트롤 삽입한다.



그러면 이처럼 FlexGrid Control 이 삽입이 될것이고,





FlexGrid Control 을 코드 내부에서 변수로 사용하고자 하면


일단 해당 Dialog 를 클래스로 만든다.








Dialog 클래스가 만들어지고나면



FlexGrid 의 변수를 만들어준다.







이제 FlexGrid Control 을 잘 사용하면 된다.







...



하지만 여기서 에러가 난다.








error C4146: 단항 빼기 연산자가 부호 없는 형식에 적용되었습니다. 결과는 역시 unsigned입니다.







flexOLEDropEffectScroll = -2147483648 


이 구문의 문제이다.




flexOLEDropEffectScroll = -2147483648LL



으로 바꾸어주면 잘 동작한다.


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

성동구 인근 지역 프로그래밍 과외 합니다.


지역 : 서울 성동구 인근


종목 : 프로그래밍, 정보올림피아드, CCNA, CCNP


경력 : 지도학생) 2013 초등부 정보올림피아드 전국대회 은상 수상

        지도학생) 정보올림피아드 본선 진출 다수


         전) 서울 서울특별시립종합직업전문학교 외부강사

         전) 천안 그린컴퓨터학원 프로그래밍 강사

         전) 한국기술교육대학교 대학원 컴퓨터공학부 박사과정 수료

         전) 청주 그린컴퓨터학원 프로그래밍 강사

         전) 아산소재 대학교 시간강사

         전) 천안소재 대학교 시간강사



         현) 한국기술교육대학교 평생능력개발 이러닝 운영강사

         현) IT기업 연구소 재직중




자세한 문의는


tansanc23@gmail.com 으로 문의해 주세요.

공일공-구구육이-일사일칠



MFC 4대 Class간 참조

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

 

4 Class간 참조

//각각 헤더파일 include

 









#include "MainFrm.h" //메인프레임 헤더파일

 

#include "ClassDoc.h"   //Doc클래스 헤더파일

 

#include "ClassView.h" //View include 할때는 반드시 Doc 헤더파일이 위에있어야한다

 

#include "Class.h" //APP Class 의 헤더파일

 

 









void CClassView::OnMenuView() //뷰클래스

 

CClassApp *pApp = (CClassApp *)AfxGetApp();   //View -> App

CMainFrame *pMain = (CMainFrame *)AfxGetMainWnd();  //View -> MainFrm

 

//View -> MainFrm -> Doc

 

CClassDoc *pDoc = (CClassDoc *)pMain->GetActiveDocument();

 

CClassDoc *pDoc = (CClassDoc *)GetDocument();         //View -> Doc

 

 









//MainFrame 클래스

 

CClassView *pView = (CClassView *)GetActiveView();  //MainFrm -> View

 

CClassDoc *pDoc = (CClassDoc *)GetActiveDocument();  //MainFrm -> Doc

 

CClassApp *pApp = (CClassApp *)AfxGetApp(); //MainFrm -> App

 

 









//Doc 클래스

 

CClassApp *pApp = (CClassApp *)AfxGetApp(); //Doc -> App

 

CMainFrame *pMain = (CMainFrame *)AfxGetMainWnd(); //Doc -> MainFrm

 

// Doc -> MainFrm -> View

 

CClassView *pView = (CClassView *)pMain->GetActiveView();

 

CClassView *pView = (CClassView *)m_viewList.GetHead();      // Doc -> View

 

 











//App 클래스

 

CMainFrame *pMain = (CMainFrame *)AfxGetMainWnd(); //App -> MainFrm

 

//App -> MainFrm -> View

 

CClassView *pView = (CClassView *)pMain->GetActiveView();

 

//App -> MainFrm -> Doc

 

CClassDoc *pDoc = (CClassDoc *)pMain->GetActiveDocument();








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

How to prevent MFC dialog closing on Enter and Escape keys?


There is an alternative to the previous answer, which is useful if you wish to still have an OK / Close button. If you override the PreTranslateMessage function, you can catch the use of VK_ESCAPE / VK_RETURN like so:



BOOL CMainDialog::PreTranslateMessage(MSG* pMsg)

{


if (pMsg->message == WM_KEYDOWN)

{

if (pMsg->wParam == VK_RETURN || pMsg->wParam == VK_ESCAPE)

{

return TRUE;                // Do not process further

}

}


return CDialogEx::PreTranslateMessage(pMsg);

}




이렇게 수정하여야 한다.




PreTranslateMessage 함수를 생성하는 방법은


1. Enter, ESC 키를 차단할 DialogClass 를 우클릭


2. [클래스 마법사] 를 켠다.


3. [가상 함수]


4. 가상 함수 탭에서 PreTranslateMessage 를 선택


5. [함수 추가]


6. 추가된 함수에


if (pMsg->message == WM_KEYDOWN)

{

if (pMsg->wParam == VK_RETURN || pMsg->wParam == VK_ESCAPE)

{

return TRUE;                // Do not process further

}

}


추가 작성