我的技术规范

C/C++, Algorithm
随笔 - 11, 文章 - 7, 评论 - 1, 引用 - 0
数据加载中……

置顶随笔

[置顶]CDC 转 OPENGL坐标系使用习惯


绘图时经常用到坐标范围设置,常常大家不理解坐标系统的建立。
诚然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 };


posted @ 2013-07-05 22:48 panchao 阅读(1491) | 评论 (1)编辑 收藏

2013年7月5日

CDC 转 OPENGL坐标系使用习惯


绘图时经常用到坐标范围设置,常常大家不理解坐标系统的建立。
诚然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 };


posted @ 2013-07-05 22:48 panchao 阅读(1491) | 评论 (1)编辑 收藏

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;
    }
}



posted @ 2013-06-03 22:02 panchao 阅读(219) | 评论 (0)编辑 收藏

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

posted @ 2012-08-02 08:47 panchao 阅读(317) | 评论 (0)编辑 收藏

2012年8月1日

BCG 和 MFC类名对应


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

EnableDescriptionArea
EnableWindowsTheming

GetUserBarByIndex GetPane

AFX_WM_TOOLBARMENU
AFX_CUSTOMIZE_MENU_ANIMATIONS

 

posted @ 2012-08-01 14:02 panchao 阅读(1134) | 评论 (0)编辑 收藏

2012年3月29日

CDC坐标系统


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 );
}

posted @ 2012-03-29 19:54 panchao 阅读(422) | 评论 (0)编辑 收藏

2012年2月19日

stl_vector.h

     摘要:   阅读全文

posted @ 2012-02-19 21:45 panchao 阅读(1727) | 评论 (0)编辑 收藏

2012年2月17日

stl_iterator_base.h

     摘要:   阅读全文

posted @ 2012-02-17 08:25 panchao 阅读(722) | 评论 (0)编辑 收藏

stl_uninitialized.h

     摘要:   阅读全文

posted @ 2012-02-17 08:23 panchao 阅读(505) | 评论 (0)编辑 收藏

atl_alloc.h

     摘要:   阅读全文

posted @ 2012-02-17 08:23 panchao 阅读(705) | 评论 (0)编辑 收藏

stl_construct.h

     摘要:   阅读全文

posted @ 2012-02-17 08:21 panchao 阅读(498) | 评论 (0)编辑 收藏