|  | 
				
					
			  
	置顶随笔
	
 
			
			
			
绘图时经常用到坐标范围设置,常常大家不理解坐标系统的建立。 
诚然WINDOWS 的坐标系统比较容易把人搞晕,事实上我个人也容易写错。 
现在发布一个可以方便转化成 OPENGL坐标系统 使用习惯的类,函数名也保持和 OPENGL相同。 
如果你连OPENEL 坐标也不懂,那请查一下相关文档吧。
  1 2 class CViewportWapper
 3 {
 4 public:
 5     CViewportWapper( HDC hdc )
 6         : hdc_( hdc )
 7     {
 8     }
 9
 10     void SetViewport( int left, int top, int width, int height)
 11     {
 12         view_left_ = left;
 13         view_top_ = top;
 14         view_width_ = width;
 15         view_height_ = height;
 16     }
 17
 18     void SetOrtho( int left, int right, int bottom, int top)
 19     {
 20         ::SetMapMode( hdc_, MM_ANISOTROPIC );
 21
 22         ::SetViewportOrgEx( hdc_, view_left_, view_top_, NULL );
 23         ::SetViewportExtEx( hdc_, view_width_, view_height_, NULL);
 24
 25         ::SetWindowOrgEx( hdc_, left, top, NULL );
 26         ::SetWindowExtEx( hdc_, right - left, bottom - top, NULL );
 27     }
 28
 29 private:
 30     HDC hdc_;
 31     int view_left_, view_top_, view_width_, view_height_;
 32 };
 
			  
	2013年7月5日
	
 
			
			
			
绘图时经常用到坐标范围设置,常常大家不理解坐标系统的建立。 
诚然WINDOWS 的坐标系统比较容易把人搞晕,事实上我个人也容易写错。 
现在发布一个可以方便转化成 OPENGL坐标系统 使用习惯的类,函数名也保持和 OPENGL相同。 
如果你连OPENEL 坐标也不懂,那请查一下相关文档吧。
  1 2 class CViewportWapper
 3 {
 4 public:
 5     CViewportWapper( HDC hdc )
 6         : hdc_( hdc )
 7     {
 8     }
 9
 10     void SetViewport( int left, int top, int width, int height)
 11     {
 12         view_left_ = left;
 13         view_top_ = top;
 14         view_width_ = width;
 15         view_height_ = height;
 16     }
 17
 18     void SetOrtho( int left, int right, int bottom, int top)
 19     {
 20         ::SetMapMode( hdc_, MM_ANISOTROPIC );
 21
 22         ::SetViewportOrgEx( hdc_, view_left_, view_top_, NULL );
 23         ::SetViewportExtEx( hdc_, view_width_, view_height_, NULL);
 24
 25         ::SetWindowOrgEx( hdc_, left, top, NULL );
 26         ::SetWindowExtEx( hdc_, right - left, bottom - top, NULL );
 27     }
 28
 29 private:
 30     HDC hdc_;
 31     int view_left_, view_top_, view_width_, view_height_;
 32 };
 
			  
	2013年6月3日
	
 
			
			
			这里以 MFC 为例,标准 C++ 同样适用,替换成相应的 std::iostream 即可。
 
 class MydataBaseHardware {
 public:
 int d;
 };
 
 CArchive& operator<<( CArchive& ar, MydataBaseHardware& data)
 {
 return ar << (WORD)data.d;
 }
 
 CArchive& operator>>( CArchive& ar, MydataBaseHardware& data)
 {
 WORD d;
 ar >> d;
 data.d = d;
 return ar;
 }
 
 class MydataBase : public MydataBaseHardware{};
 
 CArchive& operator<<( CArchive& ar, MydataBase& data)
 {
 return ar << data.d;
 }
 
 CArchive& operator>>( CArchive& ar, MydataBase& data)
 {
 return ar >> data.d;
 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 class MydataHardware {
 public:
 int a;
 int b;
 int c;
 
 MydataBase base;
 };
 
 CArchive& operator<<( CArchive& ar, MydataHardware& data)
 {
 return ar << (WORD)data.a << (WORD)data.b << (WORD)data.c << (MydataBaseHardware)data.base;
 }
 
 CArchive& operator>>( CArchive& ar, MydataHardware& data)
 {
 WORD a, b, c;
 ar >> a >> b >> c;
 data.a = a;
 data.b = b;
 data.c = c;
 
 ar >> (MydataBaseHardware)data.base;
 return ar;
 }
 
 class Mydata : public MydataHardware{};
 
 CArchive& operator<<( CArchive& ar, Mydata& data)
 {
 return ar << data.a << data.b << data.c << data.base;
 }
 
 CArchive& operator>>( CArchive& ar, Mydata& data)
 {
 return ar >> data.a >> data.b >> data.c >> data.base;
 }
 
 
 
 
 
 
 
 void CMyDoc::Serialize(CArchive& ar)
 {
 Mydata data;
 MydataHardware& hd = data;
 
 if (ar.IsStoring())
 {
 // TODO: add storing code here
 ar << hd;
 }
 else
 {
 // TODO: add loading code here
 ar >> hd;
 }
 }
 
 
 
 
 
			  
	2012年8月2日
	
 
			
			
			///// C/C++ //////////////////////////////////////////
 outdir : $(SolutionDir)../$(Configuration)/bin/
 当模块信息时:
 $(SolutionDir)../$(Configuration)/bin/module/
 intdir :$(SolutionDir)../$(Configuration)/obj/$(ProjectName)/
 //////////////// addition include path :./;../include/;
 //////////////// precomplie output file :$(IntDir)$(TargetName).pch
 //////////////// asm list folder :$(IntDir)
 object file name :$(IntDir)
 program database file name :$(IntDir)
 xml document file name :$(IntDir)
 //////////////// brower information file name :$(IntDir)
 ///// Linker //////////////////////////////////////////
 output file :$(OutDir)$(TargetName)$(TargetExt)
 //////////////// addition libiary path :$(OutDir)../lib/;
 当模块信息时:
 $(OutDir)../../lib/;
 ////////////////
 module define file :.\$(TargetName).def
 //////////////// 清单文件 :$(IntDir)$(TargetName)$(TargetExt).intermediate.manifest
 //////////////// 生成程序数据库文件 :$(IntDir)$(TargetName).pdb
 //////////////// 按配置优化数据库 .pgd :$(IntDir)$(TargetName).pgd
 //////////////// 导入库 :$(OutDir)../lib/$(TargetName).lib
 当模块信息时:
 $(OutDir)../../lib/$(TargetName).lib
 ///// 清单工具 ////////////////////////////////////////// 输出清单文件:$(IntDir)$(TargetName)$(TargetExt).embed.manifest
 清单资源文件:$(IntDir)$(TargetName)$(TargetExt).embed.manifest.res
 ///// resource //////////////////////////////////////////
 resource file name :$(IntDir)%(Filename).res
 ///// xml 文档生成器 //////////////////////////////////////////
 输出文档文件 :$(IntDir)$(TargetName).xml
 ///// 浏览信息 //////////////////////////////////////////
 输出文件 :$(IntDir)$(TargetName).bsc
 
 
			  
	2012年8月1日
	
 
			
			
			CBCGPMaskEdit CMFCMaskedEdit
 CBCGPToolBar CMFCToolBar
 CBCGPMenuBar CMFCMenuBar
 CBCGPStatusBar CMFCStatusBar
 CBCGPButton CMFCButton
 CBCGPPropertyPage CMFCPropertyPage
 CBCGPMDIChildWnd CMDIChildWndEx
 CBCGPPropertySheet CMFCPropertySheet
 CBCGPTabWnd CMFCTabCtrl
 CBCGPPopupMenu CMFCPopupMenu
 CBCGPSplitterWnd CSplitterWndEx
 CBCGPDockingControlBar CDockablePane
 CBCGPListCtrl CMFCListCtrl
 CBCGPPropList CMFCPropertyGridCtrl
 CBCGPProp CMFCPropertyGridProperty
 CBCGPColorButton CMFCColorButton
 CBCGPContextMenuManager CContextMenuManager
 CBCGPShellManager CShellManager
 CBCGPVisualManager CMFCVisualManager
 CBCGPDockManager CDockingManager
 CBCGPToolbarCustomize CMFCToolBarsCustomizeDialog
 ----------
 BCGPPrintPreview AFXPrintPreview
 EnableDescriptionAreaEnableWindowsTheming
 GetUserBarByIndex GetPane AFX_WM_TOOLBARMENUAFX_CUSTOMIZE_MENU_ANIMATIONS
   
			  
	2012年3月29日
	
 
			
			
			void CChildView::OnPaint()
 {
 //如果是 0 开始的坐标范围选择,可以用 SetViewportOrg ,也可以用 SetWindowOrg
 CPaintDC dc(this);
 
 RECT rc;
 GetClientRect( &rc);
 
 pDC->SetMapMode( MM_ANISOTROPIC );
 
 pDC->SetWindowExt( 10000, 10000 );
 pDC->SetViewportExt( rc.right / 2, - rc.bottom / 2);
 
 pDC->SetViewportOrg( rc.right / 4, rc.bottom - rc.bottom / 4 );
 //pDC->SetWindowOrg( -5000, 15000 );
 
 pDC->Rectangle( 0, 0, 10000, 10000 );
 
 POINT pts[] = {  0, 0,    3000, 2000,  3500, 6000,    7000, 9000 };
 pDC->Polyline( pts, sizeof(pts) / sizeof(*pts) );
 
 pDC->SetBkMode( TRANSPARENT );
 
 
 for ( int i = 0; i < sizeof(pts) / sizeof(*pts) ; ++ i )
 {
 TCHAR szText[256];
 
 pDC->TextOut( pts[i].x, pts[i].y, szText,
 wsprintf ( szText, L"%d, %d", pts[i].x, pts[i].y ) );
 }
 
 pDC->TextOut( 10000, 10000, TEXT("1,1"), 3 );
 }
 
 
 void CChildView::OnPaint()
 {
 // 但如果不是从 0 开始,则坐标 必须由 SetWindowOrg 设置
 
 CPaintDC dc(this);
 
 RECT rc;
 GetClientRect( &rc);
 dc.Rectangle( rc.right / 4, rc.bottom / 4, rc.right - rc.right / 4, rc.bottom - rc.bottom / 4 );
 
 dc.SetMapMode( MM_ANISOTROPIC );
 
 dc.SetWindowExt( 10000, 10000 );
 dc.SetViewportExt( rc.right / 2, - rc.bottom / 2);
 
 //dc.SetViewportOrg( rc.right / 4, rc.bottom - rc.bottom / 4 );
 dc.SetWindowOrg( -2000, 17000 );
 
 //dc.Rectangle( 0, 0, 10000, 10000 );
 
 POINT pts[] = {  0, 0,    3000, 2000,  3500, 6000,    7000, 9000 };
 dc.Polyline( pts, sizeof(pts) / sizeof(*pts) );
 
 dc.SetBkMode( TRANSPARENT );
 
 
 for ( int i = 0; i < sizeof(pts) / sizeof(*pts) ; ++ i )
 {
 TCHAR szText[256];
 
 dc.TextOut( pts[i].x, pts[i].y, szText,
 wsprintf ( szText, L"%d, %d", pts[i].x, pts[i].y ) );
 }
 
 dc.TextOut( 10000, 10000, TEXT("1,1"), 3 );
 }
 
 
			  
	2012年2月19日
	
 
			  
	2012年2月17日
	
 |