一个MDI窗口框架,可作为简单的MIS窗口框架使用

这是我学习VC MDI框架时写的,在VC6下通过。源代码已上传至CSDN资源。http://download.csdn.net/source/2448780

 


一、创建MDI项目
1、建立MDI项目WorkHelper,MDI类型,初始视图为FormView。
2、添加ADO数据库支持。
    1) StdAfx.h中加入
#pragma warning (disable: 4146)
#import "c:/Program Files/Common Files/system/ado/msadox.dll"
#import "c:/program files/common files/system/ado/msado15.dll" no_namespace rename("EOF","adoEOF")
#pragma warning (default: 4146)
    2) App的InitInstance中加入OLE库支持。
    3) App中添加以下变量及数据库连接函数。
    _RecordsetPtr m_pRecordset;        //记录
    _ConnectionPtr m_pConnection;    //连接
    int DisConnectDB(void);        //断开连接
    int ConnectDB();                //连接数据库
    4) 在ExitInstance()加入数据库实例清理功能。
    if(m_pConnection != NULL)
        DisConnectDB();
3、其它
    1) 加入只允许一个实例。
        protected:
            HANDLE hMutex;
        //只允许一个实例运行
    CString smutex="oneInstanceMutesNew";
    hMutex = OpenMutex(MUTEX_ALL_ACCESS,FALSE,smutex);
    if(hMutex == NULL)
    {
        hMutex = CreateMutex(NULL,TRUE,smutex);
    }
    else
    {
        AfxMessageBox("系统已经运行!");
        return FALSE;
    }
2) 添加CZWfun和md5类。 //CZWfun是我自己使用的一个小工具类,没难度
    3)添加Splash。
工程->添加工程->Components and Controls … ->插入 Splash Screen。
更改资源中的IDB_SPLASH图片。
CSplashWnd::OnCreate中更改Splash显示时间。
二、登录与注销
1、登录
    CDlgLogin对话框类,检测用户名与密码不能用空,密码加密,然后连接数据库核对用户名密码,如核对成功,则更新登录时间。允许错误三次,三次后则退出。
2、注销
    直接响应应用程序关闭消息,暂不做其它处理。

三、主窗口
1、CwinApp
定义
    CMultiDocTemplate* pDocTemplateDiary;
    CMultiDocTemplate* pDocTemplateSystem;
    CMultiDocTemplate* pDocTemplate;

WorkHelper.cpp中加入必要的头文件

#define IDR_SYSTEMTYPE WM_USER+1
#define IDR_DIARYTYPE WM_USER+2

在InitInstance()中
    pDocTemplate = new CMultiDocTemplate(    //主窗口
        IDR_WORKHETYPE,
        RUNTIME_CLASS(CWorkHelperDoc),
        RUNTIME_CLASS(CChildFrame), // custom MDI child frame
        RUNTIME_CLASS(CWorkHelperView));
    AddDocTemplate(pDocTemplate);
    pDocTemplateSystem = new CMultiDocTemplate(    //系统配置
        IDR_SYSTEMTYPE,
        RUNTIME_CLASS(CWorkHelperDoc),
        RUNTIME_CLASS(CChildFrame), // custom MDI child frame
        RUNTIME_CLASS(CDlgSystem));
    AddDocTemplate(pDocTemplateSystem);
    pDocTemplateDiary = new CMultiDocTemplate(    //业务日记
        IDR_DIARYTYPE,
        RUNTIME_CLASS(CWorkHelperDoc),
        RUNTIME_CLASS(CChildFrame), // custom MDI child frame
        RUNTIME_CLASS(CDlgDiary));
    AddDocTemplate(pDocTemplateDiary);

2、CMainFrame
加入对应的消息映射处理
void CMainFrame::OnOfficeDiary()
{
    // TODO: Add your command handler code here
    CMDIChildWnd* pChild = MDIGetActive();
    CDocument * pDoc;
    if(pChild == NULL || (pDoc=pChild->GetActiveDocument()) == NULL)
    {
        pChild = new CMDIChildWnd();
        pDoc = new CWorkHelperDoc();
    }

    CView*   pView; 
    POSITION   pos   =   pDoc->GetFirstViewPosition(); 
    while   (pos   !=   NULL) 
    { 
        pView   =   pDoc->GetNextView(pos); 
        if   (pView->IsKindOf(RUNTIME_CLASS(CDlgDiary)))  //如子窗口已打开则激活
        {     
            pView->GetParentFrame()->ActivateFrame(); 
            return; 
        }
    } 
   
//创建相应子窗口
    CDocTemplate * pTemplate = ((CWorkHelperApp *)AfxGetApp())->pDocTemplateDiary;
    ASSERT_VALID(pTemplate);
    CFrameWnd * pFrame = pTemplate->CreateNewFrame(pDoc,pChild);
    if(pFrame == NULL)
    {
        AfxMessageBox(AFX_IDP_COMMAND_FAILURE);
        return;
    }
    pTemplate->InitialUpdateFrame(pFrame,pDoc);

    //动态设置窗口风格
    pView = pFrame->GetActiveView();
//pView->GetParentFrame()->ModifyStyle(WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_SYSMENU,WS_CAPTION,   SWP_DRAWFRAME);   
    pView->GetParentFrame()->ModifyStyle(0,WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_SYSMENU,SWP_DRAWFRAME);   
   
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值