游戏开发论坛

 找回密码
 立即注册
搜索
楼主: 自由蜂

如何快速构建c++类?

[复制链接]

31

主题

278

帖子

298

积分

中级会员

Rank: 3Rank: 3

积分
298
发表于 2008-1-3 12:41:00 | 显示全部楼层

Re:如何快速构建c++类?

刀比枪轻,你就拿它上战场吧,没人逼你

0

主题

12

帖子

12

积分

新手上路

Rank: 1

积分
12
发表于 2008-1-4 20:33:00 | 显示全部楼层

Re:如何快速构建c++类?

1,减少文件的数量:可以把相关类集中到一对h,cpp中。以后方便时再做物理分离。
2,函数声明和实现体书写:使用visual assist的refactor功能集中的有关辅助工具,加速书写效率。

59

主题

1104

帖子

1199

积分

金牌会员

Rank: 6Rank: 6

积分
1199
发表于 2008-1-6 01:25:00 | 显示全部楼层

Re:如何快速构建c++类?

很多CPP和H也是很正常的,关键是对CPP和H也要进行相应的目录管理,有必要的话,可以把一个工程分成多个子工程。

362

主题

3023

帖子

3553

积分

论坛元老

Rank: 8Rank: 8

积分
3553
发表于 2008-1-14 03:27:00 | 显示全部楼层

Re:如何快速构建c++类?

//instMedia.h
#ifndef INST_MEDIA_H
#define INST_MEDIA_H


#include <instTypes.h>
#include <instDefines.h>
#include <instStr.h>
#include <instProcess.h>



#include <dshow.h>


namespace inst
{


class CMedia
{
private:
        IGraphBuilder *m_pGraphBuilder;
        IMediaControl *m_pMediaControl;
        IMediaPosition *m_pMediaPosition;
        IBasicAudio *m_pBasicAudio;
        IBasicVideo *m_pBasicVideo;
        IVideoWindow *m_pVideoWindow;
        Bool m_bPlaying;
        Bool m_bLoop;
        CTimer *tmrTimer;
        void tmrTimer_Tick(CTimer *es)
        {
                if(!IsOpened())return;
                if(!m_bPlaying)return;
                if(GetCrrtPos()>=GetDuration())Seek(0);
        }
        CProcessMgr *m_pProcessMgr;
public:
        CMedia(CProcessMgr *processmgr)
        {
                m_pGraphBuilder=null;
                m_pMediaControl=null;
                m_pMediaPosition=null;
                m_pBasicAudio=null;
                m_pBasicVideo=null;
                m_pVideoWindow=null;
                m_bPlaying=False;
                m_bLoop=False;
                tmrTimer=new CTimer();
                AddCallBack(tmrTimer->Tick,this,CMedia::tmrTimer_Tick);
                tmrTimer->SetEnabled(False);
                tmrTimer->SetInterval(1000);
                m_pProcessMgr=processmgr;
                if(m_pProcessMgr)m_pProcessMgr->AddProcess(tmrTimer);
        }
        ~CMedia(){ if(m_pProcessMgr)m_pProcessMgr->RemoveProcess(tmrTimer); SafeDel(tmrTimer); }

        Bool IsOpened()
        {
                return m_pGraphBuilder!=null;
        }

        Bool IsPlaying()
        {
                return m_bPlaying;
        }

        Bool IsLoop()
        {
                return m_bLoop;
        }

        void SetLoop(Bool loop)
        {
                if(!tmrTimer)return;
                tmrTimer->SetEnabled(loop);
        }

        void Open(const CStr &filename)
        {
                CoInitialize(NULL);
                CoCreateInstance(CLSID_FilterGraph,NULL,CLSCTX_INPROC,IID_IGraphBuilder,(void**)&m_pGraphBuilder);
                m_pGraphBuilder->QueryInterface(IID_IMediaControl,(void**)&m_pMediaControl);
                m_pGraphBuilder->QueryInterface(IID_IMediaPosition,(void**)&m_pMediaPosition);
                m_pGraphBuilder->QueryInterface(IID_IBasicAudio,(void**)&m_pBasicAudio);
                m_pGraphBuilder->QueryInterface(IID_IBasicVideo,(void**)&m_pBasicVideo);
                m_pGraphBuilder->QueryInterface(IID_IVideoWindow,(void**)&m_pVideoWindow);
                m_pMediaControl->RenderFile((BSTR)filename.ReadW());
                m_bPlaying=False;
        }

        void Close()
        {
                m_bPlaying=False;
                SafeRelease(m_pVideoWindow);
                SafeRelease(m_pBasicVideo);
                SafeRelease(m_pBasicAudio);
                SafeRelease(m_pMediaPosition);
                SafeRelease(m_pMediaControl);
                SafeRelease(m_pGraphBuilder);
                CoUninitialize();
        }

        void Play()
        {
                if(!m_pMediaControl)return;
                if(0==(m_pMediaControl->Run()))return;
                m_bPlaying=True;
        }

        void Pause()
        {
                if(!m_pMediaControl)return;
                if(0==(m_pMediaControl-&gtause()))return;
                m_bPlaying=False;
        }

        void Stop()
        {
                if(!m_pMediaControl)return;
                if(0==(m_pMediaControl->Stop()))return;
                m_bPlaying=False;
        }

        void Seek(Double pos)
        {
                if(!m_pMediaPosition)return;
                m_pMediaPosition->put_CurrentPosition(pos);
        }

        Double GetDuration()
        {
                Double ret=0;
                if(!m_pMediaPosition)return 0;
                m_pMediaPosition->get_Duration(&ret);
                return ret;
        }

        Double GetCrrtPos()
        {
                Double ret=0;
                if(!m_pMediaPosition)return 0;
                m_pMediaPosition->get_CurrentPosition(&ret);
                return ret;
        }

        Double GetRate()
        {
                Double ret=0;
                if(!m_pMediaPosition)return 0;
                m_pMediaPosition->get_Rate(&ret);
                return ret;
        }

        void SetRate(Double rate)
        {
                if(!m_pMediaPosition)return;
                m_pMediaPosition->put_Rate(rate);
        }

        Int32 GetVolume()
        {
                Int32 ret=0;
                if(!m_pBasicAudio)return 0;
                m_pBasicAudio->get_Volume(&ret);
                return ret;
        }

        void SetVolume(Int32 vol)
        {
                if(!m_pBasicAudio)return;
                m_pBasicAudio->put_Volume(vol);
        }

        void GetVideoSize(POS *w,POS *h)
        {
                if(!m_pBasicVideo)return;
                m_pBasicVideo->GetVideoSize(w,h);
        }

        void GetDestPos(POS *l,POS *t,POS *w,POS *h)
        {
                if(!m_pBasicVideo)return;
                m_pBasicVideo->GetDestinationPosition(l,t,w,h);
        }

        void SetDestPos(POS l,POS t,POS w,POS h)
        {
                if(!m_pBasicVideo)return;
                m_pBasicVideo->SetDestinationPosition(l,t,w,h);
        }

        void GetSrcPos(POS *l,POS *t,POS *w,POS *h)
        {
                if(!m_pBasicVideo)return;
                m_pBasicVideo->GetSourcePosition(l,t,w,h);
        }

        void SetSrcPos(POS l,POS t,POS w,POS h)
        {
                if(!m_pBasicVideo)return;
                m_pBasicVideo->SetSourcePosition(l,t,w,h);
        }

        Int32 GetVideoWndStyle()
        {
                Int32 ret=0;
                if(!m_pVideoWindow)return 0;
                m_pVideoWindow->get_WindowStyle(&ret);
                return ret;
        }

        void SetVideoWndStyle(Int32 style)
        {
                if(!m_pVideoWindow)return;
                m_pVideoWindow->put_WindowStyle(style);
        }

        HWND GetVideoWndOwner()
        {
                HWND ret=(HWND)null;
                if(!m_pVideoWindow)return (HWND)null;
                m_pVideoWindow->get_Owner((OAHWND*)(&ret));
                return ret;
        }

        void SetVideoWndOwner(HWND hwnd)
        {
                if(!m_pVideoWindow)return;
                m_pVideoWindow->put_Owner((OAHWND)hwnd);
        }

        void GetVideoWndPos(POS *l,POS *t,POS *w,POS *h)
        {
                if(!m_pVideoWindow)return;
                m_pVideoWindow->GetWindowPosition(l,t,w,h);
        }

        void SetVideoWndPos(POS l,POS t,POS w,POS h)
        {
                if(!m_pVideoWindow)return;
                m_pVideoWindow->SetWindowPosition(l,t,w,h);
        }

};


}// end of namespace inst


#endif

5

主题

68

帖子

75

积分

注册会员

Rank: 2

积分
75
QQ
发表于 2009-1-18 00:42:00 | 显示全部楼层

Re:如何快速构建c++类?

LS就是不写注释的典型,LZ切莫效仿

2

主题

38

帖子

44

积分

注册会员

Rank: 2

积分
44
发表于 2009-1-18 20:33:00 | 显示全部楼层

Re:如何快速构建c++类?

这么喜欢面向对象 那用JAVA或者C#吧.。。那个纯粹的类堆砌 你一定会觉得很爽~

3

主题

263

帖子

267

积分

中级会员

Rank: 3Rank: 3

积分
267
发表于 2009-2-10 16:29:00 | 显示全部楼层

Re: Re:如何快速构建c++类?

xoyojank: Re:如何快速构建c++类?

用VisualAssist就很方便

同意.
最好yongVAX自定义一下自己想要的class{}块.

12

主题

733

帖子

734

积分

高级会员

Rank: 4

积分
734
发表于 2009-2-17 01:44:00 | 显示全部楼层

Re:如何快速构建c++类?

一定要一个类占一份文件么?貌似没人规定一份头文件和CPP文件里面不能放几个类吧

1

主题

57

帖子

59

积分

注册会员

Rank: 2

积分
59
QQ
发表于 2009-2-28 10:45:00 | 显示全部楼层

Re: Re:如何快速构建c++类?

DrZinc: Re:如何快速构建c++类?

这么喜欢面向对象 那用JAVA或者C#吧.。。那个纯粹的类堆砌 你一定会觉得很爽~



看起来你不是很喜欢面向对象.
在工程经常需要扩展的时候,面向对象就体现价值了.对不习惯写类或者感觉用面向对象方法写程序不方便的同行,可以去找一本叫<<大话设计模式>>的书来看看,看完你会有收获的

1

主题

57

帖子

59

积分

注册会员

Rank: 2

积分
59
QQ
发表于 2009-2-28 10:46:00 | 显示全部楼层

Re:如何快速构建c++类?

不好意思各位,我不知道这是个坟,参于挖坟了抱歉
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2026-1-20 05:07

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表