OnCreate(LPCREATESTRUCT lpCreateStruct) 参数lpCreateStruct参数详解

合集下载

学生成绩管理系统(详细操作过程)

学生成绩管理系统(详细操作过程)

学生成绩管理系统我将把我的实现步骤完整的写出来,我是在VC 6.0版本下用MFC实现的。

我创建的基于单文档的应用程序,过程不介绍,大家都会。

下面的是我系统菜单:思路:刚进入系统时,只有“登录”菜单可用,其他三个菜单项都是灰色不可用的。

当用户点“进入系统”菜单项时,用户输入用户名、密码和用户类型,系统将根据相应的用户权限使相应的菜单可用,并且“进入系统”菜单项变为不可用。

如:如果用户类型是学生,那么只有学生权限菜单可用,而“教师权限”和“管理员权限”都不可用,同时“进入系统”变为不可用。

“学生权限”下只有“查询成绩”,因为学生只可以查询自己相应的成绩;“教师权限”下有“查询学生成绩”和“增改删学生成绩”两个菜单项,因为教师除了可以查询学生成绩还可以增加、修改和删除学生成绩;“管理员权限”下有“管理学生”和“管理教师”两个菜单项。

整体设计:因为我们要设置系统菜单的状态,所以必须在CMainFrame中添加相应的函数和代码,具体步骤如下:【步骤1】由于系统要使用ODBC类操作数据库,所以需要在stdafx.h中加入代码:#include <afxdb.h>【步骤2】在CMainFrame中的OnCreat()中添加代码如下,实现菜单的初始化工作,当用户没进入系统之前,只有“登陆”菜单下的“进入系统”菜单项可用,而“退出系统”和其他3个权限菜单都不可用,即都是灰色的。

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct){//使“退出系统”和其他3个权限菜单都不可用,即都是灰色的GetMenu()->GetSubMenu(0)-> EnableMenuItem(1,MF_BYPOSITION | MF_DISABLED | MF_GRAYED);GetMenu()-> EnableMenuItem(1,MF_BYPOSITION | MF_DISABLED | MF_GRAYED);GetMenu()-> EnableMenuItem(2,MF_BYPOSITION | MF_DISABLED | MF_GRAYED);GetMenu()-> EnableMenuItem(3,MF_BYPOSITION | MF_DISABLED | MF_GRAYED);}【步骤3】在CMainFrame中添加自己定义的函数void SetMenuSta(int type),此函数在登陆对话框的OnOK()中被调用,即当用户进入系统后使“进入系统”菜单项不可用,并根据用户类型使相应菜单可用。

VS2010中CMFCToolBar的用法

VS2010中CMFCToolBar的用法

VS2010中CMFCToolBar的用法自从VS2008中增加了一些特性的菜单,但这些特性在帮助中说明的很少,给使用者造成了很多麻烦。

笔者经过搜索以及自己的摸索,对其的用法有了初步了解,形成本文,如果能够为后来者解决一些问题,笔者将会感到欣慰。

一、向导自动生成的CMFCToolBar由于应用了系统风格,向导生成的菜单确实很漂亮。

如下图:但在某些情况下(至于哪些情况,笔者还不能确定),向导自动生成的菜单会没有名字,在“工具栏和停靠窗口”的子菜单下会显示空。

如下图:出现这种情况的解决办法就是自己给工具栏命个名称。

在CMainFrame::OnCreate()事件中给工具栏命名:int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct){……// TODO: 如果您不希望工具栏和菜单栏可停靠,请删除这五行m_wndMenuBar.EnableDocking(CBRS_ALIGN_ANY);m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);EnableDocking(CBRS_ALIGN_ANY);DockPane(&m_wndMenuBar);DockPane(&m_wndToolBar);m_wndToolBar.SetWi ndowText(_T(“工具栏”)); //这是自己添加的……return 0;}二、自己添加一条工具栏自己添加的工具栏如果按照向导生成的样子去做,在菜单中是不会显示出来的,虽然工具栏已经生成了。

如下图:要想让菜单在“工具栏和停靠窗口”中显示,是不能完全按照向导生成的样子做的。

需要模仿向导生成的样子做但仍有点变化。

(1)创建自已的工具栏在头文件中定义一个工具栏变量。

CMFCToolBar m_wndToolBar2;在CMainFrame::OnCreate()事件中创建并加载工具栏:if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP |CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||!m_wndToolBar.LoadToolBar(theApp.m_bHiColorIcons ? IDR_MAINFRAME_256 :IDR_MAINFRAME)){TRACE0("未能创建工具栏\n");return -1; // 未能创建}//自己创建的工具栏if (!m_wndToolBar2.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY |CBRS_SIZE_DYNAMIC,CRect(1,1,1,1),theApp.m_bHiColorIcons ? IDR_MAINFRAME_256 +1:IDR_MAINFRAME+1) ||!m_wndToolBar2.LoadToolBar(theApp.m_bHiColorIcons ? IDR_MAINFRAME_256 :IDR_MAINFRAME)){TRACE0("未能创建工具栏\n");return -1; // 未能创建}(2)自己的工具栏浮动或停靠窗口// TODO: 如果您不希望工具栏和菜单栏可停靠,请删除这五行m_wndMenuBar.EnableDocking(CBRS_ALIGN_ANY);m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);m_wndToolBar2.EnableDocking(CBRS_ALIGN_ANY);//自己创建的工具栏EnableDocking(CBRS_ALIGN_ANY);DockPane(&m_wndMenuBar);DockPane(&m_wndToolBar);DockPane(&m_wndToolBar2);//自己创建的工具栏这时候再运行程序会显示如下图:(3)给自己的工具栏命名m_wndToolBar2.SetWindowText(_T("我的工具栏"));此时程序运行如下图:三、浮动我的工具栏在以前CToolBar的时候,浮动工具栏可以使用FloatControlBar()函数。

vc中显示时间

vc中显示时间

.LOG1:在对话框拖一个edit控件,用类向导设置为CString型变量s2:用类向导为XXXXDlg类创建三个Message函数,如下:int CDuihuaDlg::OnCreate(LPCREATESTRUCT lpCreateStruct){if (CDialog::OnCreate(lpCreateStruct) == -1)return -1;// TODO: Add your specialized creation code hereSetTimer(1,1000,NULL);return 0;}void CDuihuaDlg::OnClose(){// TODO: Add your message handler code here and/or call defaultKillTimer(1);CDialog::OnClose();}void CDuihuaDlg::OnTimer(UINT nIDEvent){// TODO: Add your message handler code here and/or call defaultCTime time;time=CTime::GetCurrentTime();CString s1=time.Format("%Y-%m-%d\t");CString s2=time.Format("%H:%m:%S");s=s1+s2;UpdateData(FALSE);CDialog::OnTimer(nIDEvent);}CDuihuaDlg是我的创建的对话框。

CTime 使用总结1.初始化m_begintime=CTime(2004,1,1,0,0,0,-1);//参数依次为year,month,day,hour,minite,second m_endtime =CTime::GetCurrentTime();//当前时间 2.日期比较CTimeSpan span;span=time1-time2;得到两时间的间隔.可以取得span.GetHours().等 3.access数据库查询使用DateDiff()函数,具体参照access帮助CString timesql; timesql.Format(" Where DateDiff('d',%s,'%s')<=0","日期",m_begintime.Format("%Y-%m-%d"));4读取日期字段(odbc) CDBVariant var; recset.GetFieldValue(i,var);s.Format("%d-%d-%d",(var.m_pdate)->year,(var.m_pdate)->month,(var.m_pdate)->day);我知道库函数 localtime() 可以把 time_t 转换成结构 struct tm, 而 ctime() 可以把time_t 转换成为可打印的字符串。

在CFormView或对话框中动态添加CScrollView、CFormView

在CFormView或对话框中动态添加CScrollView、CFormView

在CFormView或对话框中动态添加CScrollView、CFormView 在CFormView或对话框中动态添加CScrollView、CFormView本代码可以在CFormView中,根据事先画好的控件位置创建CScrollView也可以在CDialog中创建CScrollView、CFormView等注:若以下代码放在CMainRightView::OnCreate(LPCREATESTRUCT lpCreateStruct)内,则GetDlgItem()函数将调⽤失败,因为此时控件都还未被创建!void CMainRightView::OnInitialUpdate(){CFormView::OnInitialUpdate();// TODO: Add your specialized code here and/or call the base class//获得⽬标位置控件UINT TargetCtrlID = IDC_STATIC_SCROLLVIEW;CWnd *pWnd = this->GetDlgItem(TargetCtrlID);CRect RectTargetCtrl;pWnd->GetWindowRect(RectTargetCtrl);pWnd->DestroyWindow();this->ScreenToClient(RectTargetCtrl);//在⽬标位置动态创建CScrollViewCEMapView *pEMapView = (CEMapView*)RUNTIME_CLASS(CEMapView)->CreateObject();pEMapView->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, RectTargetCtrl, this, TargetCtrlID);//使⽤CreateView创建的视图不能⾃动调⽤OnInitialUpdate函数,需要⼈⼯调⽤OnInitialUpdate函数或者发送 WM_INITIALUPDATE消息 pEMapView->OnInitialUpdate();//SetScrollSizes()必须被调⽤,否则运⾏时会出ASSERT错误,当然,也可以在⽬标View内的OnInitialUpdate()中调⽤pEMapView->SetScrollSizes(MM_TEXT, CSize(RectTargetCtrl.Width()-10, RectTargetCtrl.Height()-10));// 使⽤CreateView创建的视图不会⾃动显⽰并且激活,需要⼈⼯操作pEMapView->ShowWindow(SW_SHOW);}注:如果需要在CDialog中创建CScrollView、CFormView,则需要在View中overload、override这些View中以下的4个⽅法,否则会出ASSERT 错误afx_msg int OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message);afx_msg void OnDestroy();virtual void PostNcDestroy();virtual void OnActivateFrame(UINT nState, CFrameWnd* pDeactivateFrame);int CFormViewPrint::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message){// TODO: Add your message handler code here and/or call defaultreturn CWnd::OnMouseActivate(pDesktopWnd, nHitTest, message);}void CFormViewPrint::OnDestroy(){CWnd::OnDestroy();// TODO: Add your message handler code here}void CFormViewPrint::PostNcDestroy(){// TODO: Add your specialized code here and/or call the base classCWnd::PostNcDestroy();}void CFormViewPrint::OnActivateFrame(UINT nState, CFrameWnd* pDeactivateFrame){// TODO: Add your specialized code here and/or call the base classCWnd::OnActivateFrame(nState, pDeactivateFrame);}原因可参考View和Control的区别(如何在对话框上使⽤CView类)CView继承类,和其他窗⼝类的区别,很重要的就是对CDocument类和CFrameWnd类的操作,⽽其中,涉及CDocument类的操作,都进⾏了有效性判断(m_pDocument != NULL),CView类初始化的时候,m_pDocument = NULL,因此并不影响CView类作为控件的使⽤。

用Visual C++实现带阴影弹出窗口的技术

用Visual C++实现带阴影弹出窗口的技术

用Visual C++实现带阴影弹出窗口的技术一.问题的提出在WINDOWS的WINHELPER帮助系统中大量使用一类带阴影的弹出窗口, 这类窗口非常简洁,并具有立体感,它们用来显示一些只读信息.此类弹出窗口不同于一般的窗口,它们没有标题和滚动杆,但都具有带阴影的边框, 并且其窗口的大小随显示字符串多少而自动调节,当显示信息弹出之后,任何来自键盘或鼠标的消息都将导致弹出窗口的消失。

然而WINDOWS API接口中没有现成的函数来实现此项功能,即使是最新版的VISUAL C++ MFC也没有提供现成的类和函数来实现带阴影的此类窗口。

为此,笔者基于面向对象的程序设计思想,从CWnd派生一个新类来实现这个功能,并且将该类窗口的所有函数完全封装在一起,使用就像调用“ MessageBox()”函数显示信息一样简单。

二.实现方法的几个关键部分说明如下,要解决怎样画非用户区的问题:当WINDOWS需要创建一个窗口时,它发送两个消息:WM_NCPAINT和WM_PAINT到应用程序消息队列。

WM_NCPAINT用于重画窗口的非用户区,如标题,边框和滚动杆,本程序正是响应WM_NCPAINT消息来重画带阴影的弹出窗口的边框;画客户区很简单,只需响应WM_PAINT消息处理字符的显示即可.2.如何动态调整弹出窗口的尺寸:大家知道,在一个矩形内显示文本串时,常用函数DrawText(HDC hDC,LPTSTR lpszText,int cbCount,RECT FAR* lpRect,UINT fuFormat).但是,此时我们的带阴影的弹出窗口并为建立.当然不能利用它来显示.然而,我们注意到上述函数中的最后一个参数FuFormat, 它是文字格式的组合,其中有一个鲜为人知的参数DT_CALCRECT, 使用这个参数,字符串不显示,但它根据当前字体测量待显示串的高度, 本程序正是根据这个参数来确定弹出窗口的大小,并以此建立一个随字符串大小而变化的窗口,下面给出其实现该功能的片断: void CShadowWnd::ShowText(CString sText) dc.CreateDC("DISPLAY",NULL,NULL,NULL); //创建一个显示设备描述表dc.SelectObject(GetStockObject(SYSTEM_FONT)); //选择字体到设备描述表CRect rect(0,0,MAXWIDTH,0);////获得待显示的字符串sText 的实际高度和宽度,并将其存入矩形rect中dc.DrawText(sText,rect,DT_WORDBREAK|DT_CENTER|DT_CALCRECT|DT_NOPREFIX);3.怎样获取对系统的控制权:在带阴影的弹出窗口显示之后,怎样获取对系统的控制权,使得当用户按下键盘任意键或鼠标时都将使带阴影的弹出窗口消失,这里采取的方法是,当弹出窗口创建和显示之后,立即进入一个消息循环,从应用程序队列中获取所有消息,并判断是否为鼠标消息或键盘消息,如是,则摧毁窗口结束,并将控制权归还给调用程序.实现片断如下://进入消息循环,获取全部消息,控制整个系统MSG Msg;BOOL bDone;SetCapture();bDone=FALSE;while(!bDone){if(PeekMessage(&Msg,NULL,0,0,PM_REMOVE))if(Msg.message==WM_KEYDOWN||Msg.message==WM_SYSKEYDOWN|| Msg.message==WM_LBUTTONDOWN||Msg.message==WM_RBUTTONDOWN) bDone=TRUE;else{TranslateMessage(&Msg);DispatchMessage(&Msg);}}ReleaseCapture();DestroyWindow();……}. 带阴影的类CShadowWnd 类的头文件及其实现文件的全部细节//头文件:#if !defined(AFX_SHADOWWND_H__B971A958_59CC_11D2_AC8F_0060084237F6__INCLUDED_) #define AFX_SHADOWWND_H__B971A958_59CC_11D2_AC8F_0060084237F6__INCLUDED_#if _MSC_VER >= 1000#pragma once#endif // _MSC_VER >= 1000// ShadowWnd.h : header file///////////////////////////////////////////////////////////////////////////////// CShadowWnd windowclass CShadowWnd : public CWnd{// Constructionpublic:CShadowWnd();// Attributespublic:// Operationspublic:// Overrides// ClassWizard generated virtual function overrides//{{AFX_VIRTUAL(CShadowWnd)public:virtual BOOL Create(const RECT& rect, CWnd* pParentWnd); //}}AFX_VIRTUAL// Implementationpublic:CString m_sShowText;void ShowReadOnlyText(CString sText);CBrush m_bmpBrush;virtual ~CShadowWnd();// Generated message map functionsprotected://{{AFX_MSG(CShadowWnd)afx_msg void OnNcPaint();afx_msg void OnPaint();afx_msg int OnCreate(LPCREA TESTRUCT lpCreateStruct);//}}AFX_MSGDECLARE_MESSAGE_MAP()};///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCA TION}}// Microsoft Developer Studio will insert additional declarations immediately before the previous line.#endif // !defined(AFX_SHADOWWND_H__B971A958_59CC_11D2_AC8F_0060084237F6__INCLUDED_)//实现文件}// ShadowWnd.cpp : implementation file//#include "stdafx.h"#include "Shadow.h"#include "ShadowWnd.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif//定义常数static int aPattern[]={0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55};//阴影位图数组#define SPOPUP_SHADOWWIDTH 10 //阴影宽度#define SPOPUP_SHADOWHEIGHT 13 //阴影高度#define MAXWIDTH 400 //显示字符矩形的最大宽度/////////////////////////////////////////////////////////////////////////////// CShadowWndCShadowWnd::CShadowWnd(){CBitmap bmp;bmp.CreateBitmap(8,8,1,1,(void* )aPattern);//创建一个阴影位图m_bmpBrush.CreatePatternBrush(&bmp); //创建一把阴影刷}CShadowWnd::~CShadowWnd(){}BEGIN_MESSAGE_MAP(CShadowWnd, CWnd)//{{AFX_MSG_MAP(CShadowWnd)ON_WM_NCPAINT()ON_WM_PAINT()ON_WM_CREA TE()//}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CShadowWnd message handlersBOOL CShadowWnd::Create(const RECT& rect, CWnd* pParentWnd){// TODO: Add your specialized code here and/or call the base classconst char* pClassName=AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW);return CWnd::CreateEx(WS_EX_STATICEDGE,pClassName, "Shadow window", WS_POPUP,rect.left,rect.top,rect.right,rect.bottom,pParentWnd->GetSafeHwnd(),0,NULL);}void CShadowWnd::OnNcPaint(){// TODO: Add your message handler code hereCWindowDC dc(this);CRect rc;GetWindowRect(&rc);rc.right-=rc.left; //widthrc.bottom-=rc.top; //heightrc.top=0;rc.left=0;m_bmpBrush.UnrealizeObject();CBrush* OldBrush=dc.SelectObject(&m_bmpBrush);//画底部阴影dc.PatBlt(rc.left+SPOPUP_SHADOWWIDTH,rc.bottom-SPOPUP_SHADOWHEIGHT, rc.right-SPOPUP_SHADOWWIDTH,SPOPUP_SHADOWHEIGHT,PATCOPY);//画右边阴影dc.PatBlt(rc.right-SPOPUP_SHADOWWIDTH,rc.top+SPOPUP_SHADOWHEIGHT,SPOPUP_SHADOWWIDTH,rc.bottom,PA TCOPY);dc.SelectObject(OldBrush); //restore old brushCBrush* pBrush=CBrush::FromHandle(GetSysColorBrush(COLOR_WINDOWFRAME)); rc.right-=SPOPUP_SHADOWWIDTH;rc.bottom-=SPOPUP_SHADOWHEIGHT;dc.FrameRect(rc,pBrush); //画边框// Do not call CWnd::OnNcPaint() for painting messages}void CShadowWnd::OnPaint(){CPaintDC dc(this); // device context for painting// TODO: Add your message handler code hereCRect rect;GetClientRect(&rect);rect.left+=5; rect.top+=5;rect.right-=SPOPUP_SHADOWWIDTH;rect.bottom-=SPOPUP_SHADOWHEIGHT;dc.SetTextColor(RGB(0,0,255));//设置显示文本颜色dc.DrawText(m_sShowText,rect,DT_WORDBREAK|DT_NOPREFIX);// Do not call CWnd::OnPaint() for painting messages}void CShadowWnd::ShowReadOnlyText(CString sText){m_sShowText=sText; //存入显示字符串CDC dc;dc.CreateDC("DISPLAY",NULL,NULL,NULL); //创建一个显示设备描述表dc.SelectObject(GetStockObject(SYSTEM_FONT)); //选择字体到设备描述表CRect rect(0,0,MAXWIDTH,0);//获得待显示的字符串sText 的实际高度和宽度dc.DrawText(sText,rect,DT_WORDBREAK|DT_CENTER|DT_CALCRECT|DT_NOPREFIX); //为矩形留些余量rect.right+=3*SPOPUP_SHADOWWIDTH;rect.bottom+=3*SPOPUP_SHADOWHEIGHT;this->Create(rect,0);//创建窗口this->ShowWindow(SW_SHOW); //显示窗口this->UpdateWindow(); //立刻更新窗口//进入消息循环,获取全部消息,控制整个系统MSG Msg;BOOL bDone;SetCapture();bDone=FALSE;while(!bDone){if(PeekMessage(&Msg,NULL,0,0,PM_REMOVE))if(Msg.message==WM_KEYDOWN||Msg.message==WM_SYSKEYDOWN|| Msg.message==WM_LBUTTONDOWN||Msg.message==WM_RBUTTONDOWN) bDone=TRUE;else{TranslateMessage(&Msg);DispatchMessage(&Msg);}}ReleaseCapture();DestroyWindow();}int CShadowWnd::OnCreate(LPCREATESTRUCT lpCreateStruct){if (CWnd::OnCreate(lpCreateStruct) == -1)return -1;// TODO: Add your specialized creation code hereCenterWindow();return 0;}四.使用方法:1. 将该类增加到一个项目文件中2. 在你欲使用函数的类(一般为视类或框架窗口类)中增加一个成员变量(如:CshadowWnd m_ShadowWnd),当需要使用带阴影的弹出窗口显示信息时,调用成员函数(如: m_ShadowWnd.ShowText(String sText)即可,无须考虑其实现细节本程序在Visual C++ 5.0环境下编译通过.此例也说明了对于WINDOWS 下的程序设计,必须掌握OOP 方法,同时也体现出VISUAL C++ MFC类库的强大功能.。

OnInitialUpdate详解

OnInitialUpdate详解

{
OnUpdate(NULL, 0, NULL);
// initial update
}
CView 基类中的 OnUpdate 函数
void CView::OnUpdate(CView* pSender, LPARAM /*lHint*/, CObject* /*pHint*/) {
ASSERT(pSender != this); UNUSED(pSender); // unused in release builds
// TODO: Add your specialized creation code here CRect rect(20,20,100,50); m_ctrlButton.Create("Button1",WS_CHILD|WS_VISIBLE,rect,this,NULL); //创建按扭控件 CFont *pFont=CFont::FromHandle((HFONT)::GetStockObject(ANSI_VAR_FONT)); CRect rect1(150,20,350,100); m_combobox.Create(WS_CHILD|WS_VISIBLE|CBS_SIMPLE|CBS_NOINTE GRALHEIGHT|WS_VSCROLL,rect1,this,NULL); return 0; }
函数被调用—》用户编辑数据: CMyView 类中函数对 CMyDocument 数据成
员进行更新—》退出程序: CMyView 对象被删除—》CMyDocument 对象被
删除
在 MFC 程序设计中,按照传统的设计,如果处理 WM_PAINT 消息,一般 会派生一个 OnPaint 函数,映射到 WM_PAINT 消息上进行绘图处理。但是很 多程序中并没有出现 OnPaint,一个 OnDraw 函数做了更多的绘图操作。而 在消息映射的列表中,也没有见到 WM_PAINT 到 OnDraw 的映射。

C++MFC(13)-双缓冲技术实现绘图

C++MFC(13)-双缓冲技术实现绘图

C++MFC(13)-双缓冲技术实现绘图双缓冲即在内存中创建⼀个与屏幕绘图区域⼀致的对象,先将图形绘制到内存中的这个对象上,再⼀次性将这个对象上的图形拷贝到屏幕上,这样能⼤⼤加快绘图的速度。

MARK⼀下实现步骤,略去了项⽬的绘画代码,亲测有效。

我程序中是在int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)CMainFrame::OnSize()CDC MemDC; //⾸先定义⼀个显⽰设备对象CBitmap MemBitmap;//定义⼀个位图对象 //随后建⽴与屏幕显⽰兼容的内存显⽰设备MemDC.CreateCompatibleDC(NULL); //这时还不能绘图,因为没有地⽅画 ^_^MemBitmap.CreateCompatibleBitmap(pDC,nWidth,nHeight); //建⽴⼀个与屏幕显⽰兼容的位图,⾄于位图的⼤⼩嘛,可以⽤窗⼝的⼤⼩,也可以⾃⼰定义CBitmap *pOldBit=MemDC.SelectObject(&MemBitmap); //将位图选⼊到内存显⽰设备中MemDC.FillSolidRect(0,0,nWidth,nHeight,RGB(255,255,255)); //先⽤背景⾊将位图清除⼲净,这⾥我⽤的是⽩⾊作为背景 你也可以⽤⾃⼰应该⽤的颜⾊//绘图内容MemDC.MoveTo(……); MemDC.LineTo(……); pDC->BitBlt(0,0,nWidth,nHeight,&MemDC,0,0,SRCCOPY); //将内存中的图拷贝到屏幕上进⾏显⽰MemDC.SelectObject(pOldBit); MemBitmap.DeleteObject(); MemDC.DeleteDC();。

VC C 如何防止程序同时启动多次

VC C  如何防止程序同时启动多次
CEllipseWndDlg dlg; m_pMainWnd = &dlg; int nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel } // Since the dialog has been closed, return FALSE so that we exit the // application, rather than start the application's message pump. return FALSE; }
下面的 InitInstance、OnCreate 和 OnDestroy 函数代码将实现上述的操作:
BOOL CEllipseWndApp::InitInstance() { // 用应用程序名创建信号量 HANDLE hSem = CreateSemaphore(NULL, 1, 1, m_pszExeName);
================再其他============
用命名的互斥! 在你的程序启动是先判断一个互斥 A 有没有,如果互斥 A 不存在,就说明该程序没 有启动,则启动该程序 并创建该互斥 A,在程序结束时销毁互斥 A
对以上代码的补充: 查看代码和 VC 的帮助后,发现问题在于原文在创建信号量和设置寻找标记时使 用 的是 CWinApp 的成员变量 m_pszExeName,该成员变量其实是应用程序执行文件 的名 称去掉扩展名后的部分,而不是应用程序名。

mschart安装使用

mschart安装使用

mschart安装使用最近需要为程序显示一些柱状图、线图之类的,查了一下微软的mschart不错,功能强大。

可是自vc6.0之后mschart控件就从ms的IDE里去掉了,如果用只能自己下载安装。

安装mschart需要1 .net framewrok 3.5 sp1(注意是sp1),没有安装的话就去下载吧,完整包大概200多M2 安装MSChart.exe MSChart_VisualStudioAddOn.exe 下载mschrt20.ocx 到C:\WINDOWS\system32目录下。

命令行运行regsvr32 mschrt20.ocx注册控件3 在vs2005之后的平台上,你要么在class view下add class->MFC Class f rom ActiveX Control然后有两个,你可以选择registy然后选择ms mschart 6.0(o led),这样只能出现一个类CMSCHART,或者选择File然后浏览mschrt20.ocx,这里面生成了很多类,你全部添加进去,最后就可以用了。

第二、你可以在一个MFC dialog上insert axtivex control或者toolbox选择choose item->com选择组件让它出现在工具箱中,这样也可以有控件。

我们自己选择生成的很多类,跟网上有示例的类函数名称上有所不同,可能会给使用带来麻烦。

其实最简单的就是找到一个Demo把里面相关的CMSCHART和其它相关的十几个类都拷贝到我的工程文件夹里,再添加进来,就ok了。

网上很多例子可供参考,比如:/document/viewdoc/?id=9 59关于遇到的一些问题。

在设置图形类型的时候,m_chart.SetChartType(1|2);显示出2D曲线图,而我们用m_chart.SetChartType(16);的时候如果你只设置了m_chart. SetColumnCount(1); 就不会显示,因为16的散列图需要的是一对坐标点,你至少需要设置m_chart.SetColumnCount(2);为2。

mfc单文档例子

mfc单文档例子

mfc单文档例子以下是一个简单的MFC单文档(SDI)应用程序的示例:1. 首先,创建一个新的MFC应用程序项目。

在Visual Studio中,选择“文件”菜单,然后选择“新建”->“项目”。

在“新建项目”对话框中,选择“MFC应用程序”,然后输入项目名称和位置,并单击“确定”。

2. 在“MFC应用程序向导”中,选择“单文档”作为应用程序类型,并单击“完成”按钮。

3. 在生成的代码中,找到`CMainFrame`类。

这是应用程序的主窗口类。

4. 在`CMainFrame`类的`OnCreateClient`函数中,添加以下代码:```cppvoid CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext pContext){// 创建视图窗口m_(_T("My View"), WS_CHILD WS_VISIBLE WS_BORDERWS_HSCROLL WS_VSCROLL, CRect(0, 0, 800, 600), this,ID_VIEW_WIN);}```5. 在`CMainFrame`类的`OnCreate`函数中,添加以下代码:```cppBOOL CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) {if (CFrameWnd::OnCreate(lpCreateStruct) == -1)return -1;// 创建工具栏和状态栏CToolBarCtrl tb;CRect rect(0, 0, 800, 24);(WS_CHILD WS_VISIBLE CBRS_TOP CBRS_GRIPPERCBRS_TOOLTIPS CBRS_FLYBY, rect, this, ID_VIEW_TB);m_(WS_CHILD WS_VISIBLE CBRS_TOP CBRS_GRIPPER CBRS_TOOLTIPS CBRS_FLYBY, rect, this, ID_VIEW_TB);m_(this);m_(0, ID_VIEW_STATUSBAR, SBPS_STRETCH, 0);m_(1, ID_VIEW_STATUSBAR2, SBPS_STRETCH, 0);m_(2, ID_VIEW_STATUSBAR3, SBPS_STRETCH, 0);m_(0, SBPS_NORMAL);m_(1, SBPS_NORMAL);m_(2, SBPS_NORMAL);m_(0, _T("Ready"));m_(1, _T("Ready"));m_(2, _T("Ready"));return TRUE;}```6. 编译并运行应用程序。

VC++状态栏中显示进度条

VC++状态栏中显示进度条

VC++之工具栏与状态栏之显示进度条一、编程思路二、创建新工程三、添加字符串资源四、添加函数五、添加代码1、于“CMainFrame”类之头文件内添加自定义消息2、于“CMainFrame”类之头文件内添加变量、声明自定义消息的响应函数3、于“CMainFrame”类内添加自定义消息到响应函数映射4、于“CMainFrame”类内定义自定义消息的响应函数5、于“CMainFrame”类的OnCreate()内添加初始化代码int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct){if (CFrameWnd::OnCreate(lpCreateStruct) == -1)return -1;if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || !m_wndToolBar.LoadToolBar(IDR_MAINFRAME)){TRACE0("Failed to create toolbar\n");return -1; // fail to create}if (!m_wndStatusBar.Create(this) ||!m_wndStatusBar.SetIndicators(indicators,sizeof(indicators)/sizeof(UINT))){TRACE0("Failed to create status bar\n");return -1; // fail to create}// TODO: Delete these three lines if you don't want the toolbar to // be dockablem_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);EnableDocking(CBRS_ALIGN_ANY);DockControlBar(&m_wndToolBar);PostMessage(USER_PROGRESS); //发送自定义消息SetTimer(1,1000,NULL); //添加定时器return 0;}6、于“CMainFrame”类内添加新增函数代码void CMainFrame::OnTimer(UINT nIDEvent){// TODO: Add your message handler code here and/or call default static int number=0;CString str;m_progress.SetPos(number); //设定进度信息number+=10;str.Format("%d",number);m_wndStatusBar.SetPaneText(2,str); //显示进度信息if(number>=100)number=0;CFrameWnd::OnTimer(nIDEvent);}void CMainFrame::OnPaint(){CPaintDC dc(this); // device context for painting// TODO: Add your message handler code hereCRect rect;m_wndStatusBar.GetItemRect(1,&rect);if(m_progress.m_hWnd)m_progress.MoveWindow(rect);//将进度栏移到新位置// Do not call CFrameWnd::OnPaint() for painting messages}六、编译七、运行八、函数说明1、CStaticBar::GetItemRect函数声明void GetItemRect(int nIndex,LPRECT lpRect)constnIndex:状态栏窗格的索引lpRect:保持状态栏窗格位置的指针功能:通过状态栏窗格索引获取窗格位置。

MFC工具栏ToolBar按钮添加下拉菜单

MFC工具栏ToolBar按钮添加下拉菜单

MFC工具栏ToolBar按钮添加下拉菜单(转)2010-07-04 11:001.在MainFrm.cpp的int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)函数末尾添加如下代码://为画图工具栏的按钮添加下拉菜单m_wndToolBar.GetToolBarCtrl().SetExtendedStyle(TBSTYLE_EX_DRAWDDARRO WS);//取值TBSTYLE_EX_DRAWDDARROWS,可以为某一个按钮添加下拉按钮。

DWORD dwStyle =m_wndToolBar.GetButtonStyle(m_mandToIndex(ID_DRAW_LINE ));dwStyle |= TBSTYLE_DROPDOWN; //其中ID_DRAW_LINE是你要添加下拉菜单的按钮的IDm_wndToolBar.SetButtonStyle(m_mandToIndex(ID_DRAW_LINE ),dwStyle);2.新建你要在点击按钮ID_DRAW_LINE出现的下拉菜单,即在工程的Resourceview选择目录树的条目点击右键,插入新的Resouse:Menu,在这里我新建的Menu它的ID是IDR_POPUP_LINE,如下图所示:3.在CMainFrame类的消息映射中(即MainFrm.cpp )加入下拉箭头的TBN_DROPDOWN消息映射:ON_NOTIFY(TBN_DROPDOWN,AFX_IDW_TOOLBAR,OnToolbarDropDown)如下:BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)//{{AFX_MSG_MAP(CMainFrame)ON_WM_CREATE()ON_NOTIFY(TBN_DROPDOWN,AFX_IDW_TOOLBAR,OnToolbarDropDo wn)//此行即为新增的ON_NOTIFY消息映射//}}AFX_MSG_MAPEND_MESSAGE_MAP()4.在MainFrame.h头文件中加入消息处理函数的声明:afx_msg void OnToolbarDropDown(NMTOOLBAR* pnmh, LRESULT* plRes);如下:// Generated message map functionsprotected://{{AFX_MSG(CMainFrame)afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);afx_msg void OnToolbarDropDown(NMTOOLBAR* pnmh, LRESULT* plRes);//}}AFX_MSGDECLARE_MESSAGE_MAP()5.在MainFrame.cpp文件中加入TBN_DROPDOWN消息处理的实现代码:void CMainFrame::OnToolbarDropDown(NMTOOLBAR *pnmtb, LRESULT *plr){CWnd *pWnd;UINT nID;switch(pnmtb->iItem){case ID_DRAW_LINE: //ID_DRAW_LINE即是你要添加下拉菜单的ToolBar按钮的IDpWnd = &m_wndToolBar;nID = IDR_POPUP_LINE;//IDR_POPUP_LINE就是上面新制作的菜单ID,当然,如果你要添加多个下拉菜单,只要多加几个case就好了break;default:return;}CMenu menu;menu.LoadMenu(nID);CMenu* pPopup = menu.GetSubMenu(0);ASSERT(pPopup);CRect rc;pWnd->SendMessage(TB_GETRECT,pnmtb->iItem,(LPARAM)&r c);pWnd->ClientToScreen(&rc);pPopup->TrackPopupMenu(TPM_LEFTALIGN |TPM_LEFTBUTTON | TPM_VERTICAL,rc.left,rc.bottom,this,&rc);}运行后如图:。

visual 2015 mfc 计算器 代码

visual 2015 mfc 计算器 代码

以下是一个简单的 Visual Studio 2015 MFC 计算器的示例代码。

它包括两个窗口,一个用于输入和显示数字,另一个用于显示结果。

```cpp// MainFrm.cpp : implementation of the CMainFrame class //#include "pch.h"#include "framework.h"#include "Calculator.h"#include "MainFrm.h"#include "afxdialogex.h"#ifdef _DEBUG#define new DEBUG_NEW#endif// CMainFrameIMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)ON_WM_CREATE()ON_WM_DESTROY()ON_COMMAND(ID_APP_ABOUT,&CMainFrame::OnAppAbout)ON_COMMAND(ID_FILE_NEW, &CMainFrame::OnFileNew) ON_COMMAND(ID_FILE_EXIT, &CMainFrame::OnFileExit) ON_COMMAND(ID_EDIT_CLEAR,&CMainFrame::OnEditClear)ON_COMMAND(ID_EDIT_COPY,&CMainFrame::OnEditCopy)ON_COMMAND(ID_EDIT_PASTE,&CMainFrame::OnEditPaste)ON_COMMAND(ID_VIEW_SPLIT,&CMainFrame::OnViewSplit)ON_COMMAND(ID_VIEW_FULL,&CMainFrame::OnViewFull)ON_UPDATE_COMMAND_UI(ID_EDIT_CLEAR,&CMainFrame::OnUpdateEditClear)ON_UPDATE_COMMAND_UI(ID_EDIT_COPY,&CMainFrame::OnUpdateEditCopy)ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE,&CMainFrame::OnUpdateEditPaste)END_MESSAGE_MAP()static UINT indicators[] ={ID_SEPARATOR, // status line indicatorID_INDICATOR_CAPS,ID_INDICATOR_NUM,ID_INDICATOR_SCRL,};CMainFrame::CMainFrame() : CFrameWndEx(){m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);}CMainFrame::~CMainFrame(){}int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct){if (CFrameWndEx::OnCreate(lpCreateStruct) == -1)return -1;// Create a view to host the client window. This object will be responsible for drawing the client area.// Set initial host view properties.CView* pView = new CView;if (!pView)return -1;pView->Create(_T("Calculator"), WS_CHILD | WS_VISIBLE | WS_BORDER | 500, CRect(0, 0, 200, 200), this);m_viewList.AddTail(pView);// m_pActiveView = pView;// m_bIsSplitterBar = TRUE;// m_bIsHorzSplit = TRUE;// m_bIsVerSplit = FALSE;// m_bIsDocTemplate = TRUE;// Create a toolbar control and initialize it.CToolBarCtrl mtbBarCtrl;// Create a command bar control and initialize it.CCommandBarCtrl commandBarCtrl; // Create a status bar control and initialize it. // Create a menu control and initialize it. CMenu menuBar;menuBar.CreateMenu();menuBar.AppendMenu(MF_POPUP, IDM_FILE, _T("&File"));menuBar.AppendMenu(MF_POPUP, IDM_EDIT, _T("&Edit")); menuBar.AppendMenu(MF_POPUP,IDM_VIEW, _T("&View")); menuBar.AppendMenu(MF_POPUP, IDM_INSERT, _T("&Insert")); menuBar.AppendMenu(MF_POPUP, IDM_FORMAT, _T("&Format")); menuBar.AppendMenu。

使用ObjectARX2015开发类似outlook浮动面板窗格

使用ObjectARX2015开发类似outlook浮动面板窗格

使用ObjectARX2015开发类似outlook浮动面板窗格开发步骤如下:1.建立新项目,基于MFC类项目。

2.添加基于arx类库的浮动对话框类,添加完后,会自动生成DockControlBar和DockControlBarChildDlg文件。

3.在DockControlBarChildDlg设置CMFCOutlookBar 和CTreeCtrl变量函数。

4.运行程序,生成.arx文件,然后再AutoCAD2015中加载,效果如下:5.左侧面板中每个节点运行时可以对应一个已经开发完的arx程序,但首先应该在AutoCAD中加载这些函数。

附件:源程序DockControlBar.h// (C) Copyright 2002-2007 by Autodesk, Inc.//// Permission to use, copy, modify, and distribute this software in// object code form for any purpose and without fee is hereby granted,// provided that the above copyright notice appears in all copies and// that both that copyright notice and the limited warranty and// restricted rights notice below appear in all supporting// documentation.//// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC. // DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE// UNINTERRUPTED OR ERROR FREE.//// Use, duplication, or disclosure by the U.S. Government is subject to// restrictions set forth in FAR 52.227-19 (Commercial Computer// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)// (Rights in Technical Data and Computer Software), as applicable.////-----------------------------------------------------------------------------//----- DockControlBar.h : Declaration of the CDockControlBar//-----------------------------------------------------------------------------#pragma once//-----------------------------------------------------------------------------#include"acui.h"#include"DockControlBarChildDlg.h"//-----------------------------------------------------------------------------class CDockControlBar : public CAcUiDockControlBar {DECLARE_DYNAMIC (CDockControlBar)public://----- Child dialog which will use the resource id suppliedCDockControlBarChildDlg *mChildDlg ;public:CDockControlBar ();virtual ~CDockControlBar ();public:virtual BOOL Create (CWnd *pParent, LPCTSTR lpszTitle) ;virtual void SizeChanged (CRect *lpRect, BOOL bFloating, int flags) ;virtual CSize CalcFixedLayout( BOOL bStretch , BOOL bHorz );afx_msg int OnCreate (LPCREATESTRUCT lpCreateStruct) ;afx_msg void OnSysCommand (UINT nID, LPARAM lParam) ;afx_msg void OnSize (UINT nType, int cx, int cy) ;DECLARE_MESSAGE_MAP()afx_msg void OnClose();} ;DockControlBar.cpp// (C) Copyright 2002-2007 by Autodesk, Inc.//// Permission to use, copy, modify, and distribute this software in// object code form for any purpose and without fee is hereby granted,// provided that the above copyright notice appears in all copies and// that both that copyright notice and the limited warranty and// restricted rights notice below appear in all supporting// documentation.//// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC. // DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE// UNINTERRUPTED OR ERROR FREE.//// Use, duplication, or disclosure by the U.S. Government is subject to// restrictions set forth in FAR 52.227-19 (Commercial Computer// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)// (Rights in Technical Data and Computer Software), as applicable.////-----------------------------------------------------------------------------//----- DockControlBar.cpp : Implementation of CDockControlBar//-----------------------------------------------------------------------------#include"StdAfx.h"#include"resource.h"#include"DockControlBar.h"//-----------------------------------------------------------------------------IMPLEMENT_DYNAMIC (CDockControlBar, CAcUiDockControlBar)BEGIN_MESSAGE_MAP(CDockControlBar, CAcUiDockControlBar)ON_WM_CREATE()ON_WM_SYSCOMMAND()ON_WM_SIZE()ON_WM_CLOSE()END_MESSAGE_MAP()//-----------------------------------------------------------------------------//----- CDockControlBar *pInstance = new CDockControlBar;//----- pInstance->Create (acedGetAcadFrame (), "My title bar") ;//----- pInstance->EnableDocking (CBRS_ALIGN_ANY) ;//----- pInstance->RestoreControlBar () ;//-----------------------------------------------------------------------------static CLSID clsCDockControlBar = {0xeab78c04, 0x2194, 0x47ad, {0xa4, 0xf2, 0xad, 0xca, 0x3e, 0x3b, 0xb6, 0x3c}} ;//-----------------------------------------------------------------------------CDockControlBar::CDockControlBar () : CAcUiDockControlBar() {mChildDlg = NULL;}//-----------------------------------------------------------------------------CDockControlBar::~CDockControlBar () {}//-----------------------------------------------------------------------------#ifdef _DEBUG//- Please uncomment the 2 following lines to avoid linker error when compiling//- in release mode. But make sure to uncomment these lines only once per project//- if you derive multiple times from CAdUiDockControlBar/CAcUiDockControlBar//- classes.//void CAdUiDockControlBar::AssertValid () const {//}#endif//-----------------------------------------------------------------------------BOOL CDockControlBar::Create (CWnd *pParent, LPCTSTR lpszTitle) {CString strWndClass ;strWndClass =AfxRegisterWndClass (CS_DBLCLKS, LoadCursor (NULL, IDC_ARROW)) ;CRect rect (0, 0, 150, 200) ;if (!CAcUiDockControlBar::Create (strWndClass, lpszTitle, WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN,rect, pParent, 0))return (FALSE) ;SetToolID (&clsCDockControlBar) ;// TODO: Add your code herereturn (TRUE) ;}//-----------------------------------------------------------------------------//----- This member function is called when an application requests the window be//----- created by calling the Create or CreateEx member functionint CDockControlBar::OnCreate (LPCREATESTRUCT lpCreateStruct) {if ( CAcUiDockControlBar::OnCreate (lpCreateStruct) == -1 )return (-1) ;//----- Point to our resourceCAcModuleResourceOverride resourceOverride;//----- Create it and set the parent as the dockctrl barmChildDlg = new CDockControlBarChildDlg;mChildDlg->Create (IDD_DOCKCONTROLBAR, this) ;//----- Move the window over so we can see the control linesmChildDlg->MoveWindow (0, 0, 150, 100, TRUE) ;return (0) ;}//-----------------------------------------------------------------------------void CDockControlBar::SizeChanged (CRect *lpRect, BOOL bFloating, int flags) { // If validif (::IsWindow (mChildDlg->GetSafeHwnd ())){//----- Always point to our resource to be safeCAcModuleResourceOverride resourceOverride ;//----- Then update its window size relativelymChildDlg->SetWindowPos (this, lpRect->left + 4, lpRect->top + 4, lpRect->Width (), lpRect->Height (), SWP_NOZORDER) ;}}//-----------------------------------------------------------------------------CSize CDockControlBar::CalcFixedLayout( BOOL bStretch , BOOL bHorz ){//如果当前处于浮动状态if (IsFloating()){CRect m_r1;GetClientRect(m_r1);//m_childDlg->SetWindowPos (this, m_r1.left+2, m_r1.top, m_r1.Width (), m_r1.Height (), SWP_NOZORDER) ;return CSize(150,450);}else//处于固定状态{return CSize(150,450);}}//-----------------------------------------------------------------------------//----- Function called when user selects a command from Control menu or when user//----- selects the Maximize or the Minimize button.void CDockControlBar::OnSysCommand (UINT nID, LPARAM lParam) {CAcUiDockControlBar::OnSysCommand (nID, lParam) ;}//-----------------------------------------------------------------------------//----- The framework calls this member function after the window's size has changedvoid CDockControlBar::OnSize (UINT nType, int cx, int cy) {CAcUiDockControlBar::OnSize (nType, cx, cy) ;// If validif (::IsWindow (mChildDlg->GetSafeHwnd ())){//----- Always point to our resource to be safeCAcModuleResourceOverride resourceOverride ;//----- then update its window position relativelymChildDlg->MoveWindow (0, 0, cx, cy) ;}}void CDockControlBar::OnClose(){// TODO: Add your message handler code here and/or call defaultif (mChildDlg != NULL){DestroyWindow();}CAcUiDockControlBar::OnClose();}DockControlBarChildDlg.h// (C) Copyright 2002-2007 by Autodesk, Inc.//// Permission to use, copy, modify, and distribute this software in// object code form for any purpose and without fee is hereby granted,// provided that the above copyright notice appears in all copies and// that both that copyright notice and the limited warranty and// restricted rights notice below appear in all supporting// documentation.//// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC. // DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE// UNINTERRUPTED OR ERROR FREE.//// Use, duplication, or disclosure by the U.S. Government is subject to// restrictions set forth in FAR 52.227-19 (Commercial Computer// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)// (Rights in Technical Data and Computer Software), as applicable.////-----------------------------------------------------------------------------//----- DockControlBarChildDlg.h : Declaration of the CDockControlBarChildDlg//-----------------------------------------------------------------------------#pragma once//-----------------------------------------------------------------------------#include"acui.h"//-----------------------------------------------------------------------------class CDockControlBarChildDlg : public CAcUiDialog {DECLARE_DYNAMIC (CDockControlBarChildDlg)public:CDockControlBarChildDlg (CWnd *pParent =NULL, HINSTANCE hInstance =NULL) ;enum { IDD = IDD_DOCKCONTROLBAR};public:CMFCOutlookBar m_wndOutlookBar;//CMFCOutlookBarPane m_wndOutlookPane;CTreeCtrl m_wndTree; //结构分析CTreeCtrl m_wndTree1;//工具箱CTreeCtrl m_wndTree2;//绘图CImageList Treelist;protected:virtual void DoDataExchange (CDataExchange *pDX) ;virtual BOOL OnCommand (WPARAM wParam, LPARAM lParam) ;protected:afx_msg LRESULT OnAcadKeepFocus (WPARAM wParam, LPARAM lParam) ;afx_msg void OnDblClkTree(NMHDR* pNMHDR, LRESULT* pResult);afx_msg void OnDblClkTree1(NMHDR* pNMHDR, LRESULT* pResult);afx_msg void OnDblClkTree2(NMHDR* pNMHDR, LRESULT* pResult); protected:DECLARE_MESSAGE_MAP()public:virtual BOOL OnInitDialog();BOOL CreateTreeControl();BOOL CreateTreeControl1();BOOL CreateTreeControl2();} ;DockControlBarChildDlg.cpp// (C) Copyright 2002-2007 by Autodesk, Inc.//// Permission to use, copy, modify, and distribute this software in// object code form for any purpose and without fee is hereby granted,// provided that the above copyright notice appears in all copies and// that both that copyright notice and the limited warranty and// restricted rights notice below appear in all supporting// documentation.//// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE// UNINTERRUPTED OR ERROR FREE.//// Use, duplication, or disclosure by the U.S. Government is subject to// restrictions set forth in FAR 52.227-19 (Commercial Computer// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)// (Rights in Technical Data and Computer Software), as applicable.////-----------------------------------------------------------------------------//- DockControlBar.cpp : Implementation of CDockControlBarChildDlg//-----------------------------------------------------------------------------#include"StdAfx.h"#include"resource.h"#include"DockControlBarChildDlg.h"#include"My_SubFunctions.h"//-----------------------------------------------------------------------------#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif//-----------------------------------------------------------------------------IMPLEMENT_DYNAMIC (CDockControlBarChildDlg, CAcUiDialog)BEGIN_MESSAGE_MAP(CDockControlBarChildDlg, CAcUiDialog)//{{AFX_MSG_MAP(CDockControlBarChildDlg)ON_MESSAGE(WM_ACAD_KEEPFOCUS, OnAcadKeepFocus) // Needed for modeless dialog.//}}AFX_MSG_MAPON_NOTIFY(NM_DBLCLK, ID_VIEW_TASKPANE_CTREE, OnDblClkTree)ON_NOTIFY(NM_DBLCLK, ID_VIEW_TASKPANE_CTREE1, OnDblClkTree1)ON_NOTIFY(NM_DBLCLK, ID_VIEW_TASKPANE_CTREE2, OnDblClkTree2)END_MESSAGE_MAP()//-----------------------------------------------------------------------------CDockControlBarChildDlg::CDockControlBarChildDlg (CWnd *pParent/*=NULL*/, HINSTANCE hInstance/*=NULL*/) : CAcUiDialog (CDockControlBarChildDlg::IDD, pParent, hInstance) { //{{AFX_DATA_INIT(CDockControlBarChildDlg)//}}AFX_DATA_INIT}//-----------------------------------------------------------------------------void CDockControlBarChildDlg::DoDataExchange (CDataExchange *pDX) {CAcUiDialog::DoDataExchange (pDX) ;//{{AFX_DATA_MAP(CDockControlBarChildDlg)//}}AFX_DATA_MAP}//-----------------------------------------------------------------------------//- Needed for modeless dialogs to keep focus.//- Return FALSE to not keep the focus, return TRUE to keep the focusLRESULT CDockControlBarChildDlg::OnAcadKeepFocus (WPARAM wParam, LPARAM lParam) { return (TRUE) ;}//-----------------------------------------------------------------------------//- As this dialog is a child dialog we need to disable ok and cancelBOOL CDockControlBarChildDlg::OnCommand (WPARAM wParam, LPARAM lParam) { switch ( wParam ) {case IDOK:case IDCANCEL:return (FALSE) ;}return (CAcUiDialog::OnCommand (wParam, lParam)) ;}BOOL CDockControlBarChildDlg::OnInitDialog(){CAcUiDialog::OnInitDialog();// TODO: Add extra initialization hereCMFCOutlookBarTabCtrl::EnableAnimation ();if (!m_wndOutlookBar.Create (_T("Shortcuts"), this,CRect(0,0,150-5,450-30),ID_VIEW_OUTLOOKBAR, WS_CHILD | WS_VISIBLE | CBRS_LEFT)) {TRACE0("Failed to create outlook bar\n");return FALSE; // fail to create}CMFCOutlookBarTabCtrl* pShortcutsBarContainer = DYNAMIC_DOWNCAST(CMFCOutlookBarTabCtrl, m_wndOutlookBar.GetUnderlyingWindow ());if (pShortcutsBarContainer == NULL){TRACE0("Cannot get outlook bar container\n");return FALSE;}//***************************************if (!CreateTreeControl()){TRACE0("Failed to create the custom window\n");return -1; // fail to create}pShortcutsBarContainer->AddTab(&m_wndTree, _T("结构分析"), 0, FALSE);//***************************************if (!CreateTreeControl1()){TRACE0("Failed to create the custom window\n");return -1; // fail to create}pShortcutsBarContainer->AddTab(&m_wndTree1, _T("工具箱"), 1, FALSE);//***************************************if (!CreateTreeControl2()){TRACE0("Failed to create the custom window\n");return -1; // fail to create}pShortcutsBarContainer->AddTab(&m_wndTree2, _T("绘图"), 2, FALSE);return TRUE; // return TRUE unless you set the focus to a control// EXCEPTION: OCX Property Pages should return FALSE}BOOL CDockControlBarChildDlg::CreateTreeControl(){Treelist.Create(16,16,ILC_COLOR32|ILC_MASK,0,0);Treelist.Add(::AfxGetApp()->LoadIconW(IDI_ICON_XY));Treelist.Add(::AfxGetApp()->LoadIconW(IDI_ICON_XY));CRect rectDummy (0, 0, 0, 0);const DWORD dwTreeStyle = WS_CHILD | WS_VISIBLE | TVS_HASLINES |TVS_LINESATROOT | TVS_HASBUTTONS;if(!m_wndTree.Create (dwTreeStyle, rectDummy, this, ID_VIEW_TASKPANE_CTREE)){TRACE0("Failed to create the custom window\n");return FALSE;}m_wndTree.SetImageList(&Treelist,TVSIL_NORMAL);HTREEITEM tree;m_wndTree.ModifyStyle(NULL,TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS);tree=m_wndTree.InsertItem(_T("结构静力计算"),0,0); //"0"为项的图像在tree view控件的图像列表中的索引。

关于VC++中两种自定义消息的发送与接收的方法实现进行说明

关于VC++中两种自定义消息的发送与接收的方法实现进行说明

在MFC中添加用户自定义消息首先弄清楚两点:(1)谁要发送这个消息(2)谁要接受这个消息。

用一个简单的例子来说明。

对象A向B(也可以就是A到A)发送消息。

1 发送消息首先在A的头文件中定义这个消息:#define WM_USERMESSAGE WM_USER+30所有自定义消息都是以WM_USER消息为基础加上一个任意的自然数来表示的。

A是向外发送消息的对象,因此在A的某个方法(函数)里就会调用用来发消息的函数B::SendMessage()/B::PostMessage(),因为是B接受消息,因此是如上的形式。

2 接受消息对象接受一个消息,应该有三部分:在头文件中有该消息的处理函数的原型;在实现文件中有接受消息映射的宏;以及该消息的处理函数的具体实现。

2.1 头文件中加上自定义消息的处理函数原型在DECLARE_MESSAGE_MAP()语句之前,一对AFX_MSG之间加上如下形式的函数原型:afx_msg LRESULT OnProcName( WPARAM wParam, LPARAM lParam );对Win32来说,wParam, lParam是传递消息最常用的手段。

2.2 在实现文件中加上接受消息映射的宏在cpp文件里,BEGIN_MESSAGE_MAP语句之后,在一对AFX_MSG_MAP之间,增加如下形式的代码:ON_MESSAGE(WM_USERMESSAGE, OnProcName)上面是不用分号结尾的。

2.3 在实现文件中给出消息处理函数的具体实现。

发信人: Amia (小羊·橘子·和中南海有缘), 信区: VisualC标题: MFC中自由使用自定义消息发信站: 哈工大紫丁香(2003年11月26日07:45:34 星期三), 站内信件消息映射、循环机制是Windows程序运行的基本方式。

V C++MFC 中有许多现成的消息句柄,可当我们需要完成其它的任务,需要自定义消息,就遇到了一些困难。

CDockablePane类的使用

CDockablePane类的使用

CDockablePane类的使用目录CDockablePane与对话框类联合使用方法 (2)CDockablePane与CTreeCtrl类联合使用的方法 (6)CDockablePane同CFormView类的联合使用方法 (9)两个带图标的CDockablePane派生类与CFormView类的联合使用方法 (12)CDockablePane类的布局设计 (15)CDockablePane窗口风格设置 (22)去除VS2010风格的框架菜单 (23)在View视图类中使用CSplitterWnd来拆分视图窗口(不在CMainFrame类的虚函数OnCreateClient中拆分视图框架窗口) (24)禁止dockablepane停靠浮动拖动 (26)VS2010菜单修改不了问题 (27)VS2010 DockablePane 每次打开都自动隐藏 (29)EnableDocking函数解释 (30)CDockablePane与对话框类联合使用方法1、新建对话框资源:①新建一个对话框资源IDD_DIALOG_DOCKDLG,Style设为Child,Border设为None;②把默认的OK和Cancel按键去掉,因为一般情况下点击这两个按钮后,对话框会销毁,而这里是不需要销毁的(如果没去掉点击了,悬浮框中的对话框内容就不能用了);③如下添加一个按钮IDC_BUTTON_TEST,后为对话框添加类CTestDlg;④为按钮添加响应void CTestDlg::OnBnClickedButtonTest(){// TODO: Add your control notification handler code hereMessageBox(_T("Hello World!"));}2、派生CDockablePane类①添加继承自CDockablePane的类CMyPane②添加此类的WM_CREATE和WM_SIZE消息响应,并添加上面对话框的成员变量CTestDlg m_TestDlg;③在CMyPane::OnCreate和CMyPane::OnSize函数中添加代码int CMyPane::OnCreate(LPCREATESTRUCT lpCreateStruct){if (CDockablePane::OnCreate(lpCreateStruct) == -1)return -1;// TODO: Add your specialized creation code hereCRect rectDummy;rectDummy.SetRectEmpty();// 创建选项卡窗口:if (!m_TestDlg.Create(IDD_DIALOG_DOCKDLG,this)){TRACE0("未能创建输出选项卡窗口/n");return -1; // 未能创建}m_TestDlg.ShowWindow(SW_SHOW);return 0;}void CMyPane::OnSize(UINT nType, int cx, int cy){CDockablePane::OnSize(nType, cx, cy);// TODO: Add your message handler code here// 选项卡控件应覆盖整个工作区m_TestDlg.SetWindowPos (this, -1, -1, cx, cy, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);m_TestDlg.ShowWindow(SW_SHOW);}3、修改MainFrame类①然后在MainFrame.h代码中添加成员变量CMyPane m_MyPane;②在CMainFrame::OnCreate函数中添加代码if (!m_wndStatusBar.Create(this)){TRACE0("Failed to create status bar\n");return -1; // fail to create}m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT));if (!m_MyPane.Create(_T("MyPane"), this, CRect(0, 0, 100, 100), TRUE,IDD_DIALOG_DOCKDLG, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI)){TRACE0("未能创建输出窗口/n");return FALSE;}m_MyPane.EnableDocking(CBRS_ALIGN_ANY);// TODO: Delete these five lines if you don't want the toolbar and menubar to be dockablem_wndMenuBar.EnableDocking(CBRS_ALIGN_ANY);m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);EnableDocking(CBRS_ALIGN_ANY);DockPane(&m_wndMenuBar);DockPane(&m_wndToolBar);DockPane(&m_MyPane); // 调整m_MyPane的大小使之适合父窗口4、运行结果5、补充① CDockablePane派生类销毁时,对话框也销毁掉(没有试验)void ControlPanel::OnDestroy(){CDockablePane::OnDestroy();// TODO: Add your message handler code herem_dlg.DestroyWindow();}② CDockablePane派生类对象的Create函数里面的666是这个停靠栏的ID,这里是随便指定的一个数值,只要不和其他已用资源重复即可,真正应用的时候,以在字符串表中添加一个ID,前面使用的是对话框的IDDm_Panel.Create(_T("tset"),this,CRect(0,0,300,300),TRUE,666,WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI);CDockablePane与CTreeCtrl类联合使用的方法1、从CDockablePane继承,创建一个自定义类CNavView① CNavView.h的代码#pragma once// CNavViewclass CNavView : public CDockablePane{DECLARE_DYNAMIC(CNavView)public:CNavView();virtual ~CNavView();protected:afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);afx_msg void OnSize(UINT nType, int cx, int cy);public:CTreeCtrl m_wndClassView;void AdjustLayout();protected:DECLARE_MESSAGE_MAP()};② CNavView.cpp的代码// NavView.cpp : implementation file//#include "stdafx.h"#include "MDISample.h"#include "NavView.h"// CNavViewIMPLEMENT_DYNAMIC(CNavView, CDockablePane)CNavView::CNavView(){}CNavView::~CNavView(){}BEGIN_MESSAGE_MAP(CNavView, CDockablePane)ON_WM_CREATE()ON_WM_SIZE()END_MESSAGE_MAP()void CNavView::OnSize(UINT nType, int cx, int cy){CDockablePane::OnSize(nType, cx, cy);AdjustLayout();}void CNavView::AdjustLayout(){if (GetSafeHwnd() == NULL){return;}CRect rectClient;GetClientRect(rectClient);int cyTlb = 3;m_wndClassView.SetWindowPos(NULL, rectClient.left + 1, rectClient.top + cyTlb + 1, rectClient.Width() - 2, rectClient.Height() - cyTlb - 2, SWP_NOACTIVATE | SWP_NOZORDER);}// CNavView message handlersint CNavView::OnCreate(LPCREATESTRUCT lpCreateStruct){CRect rectDummy;rectDummy.SetRectEmpty();// Create views:const DWORD dwViewStyle = WS_CHILD | WS_VISIBLE | TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;if (!m_wndClassView.Create(dwViewStyle, rectDummy, this, 2)){TRACE0("Failed to create Class View/n");return -1; // fail to create}HTREEITEM hRoot = m_wndClassView.InsertItem(_T("FakeApp classes"), 0, 0); m_wndClassView.SetItemState(hRoot, TVIS_BOLD, TVIS_BOLD);HTREEITEM hClass = m_wndClassView.InsertItem(_T("CFakeAboutDlg"), 1, 1, hRoot);m_wndClassView.InsertItem(_T("CFakeAboutDlg()"), 3, 3, hClass);m_wndClassView.Expand(hRoot, TVE_EXPAND);hClass = m_wndClassView.InsertItem(_T("CFakeApp"), 1, 1, hRoot);m_wndClassView.InsertItem(_T("CFakeApp()"), 3, 3, hClass);m_wndClassView.InsertItem(_T("InitInstance()"), 3, 3, hClass);m_wndClassView.InsertItem(_T("OnAppAbout()"), 3, 3, hClass);hClass = m_wndClassView.InsertItem(_T("CFakeAppDoc"), 1, 1, hRoot);m_wndClassView.InsertItem(_T("CFakeAppDoc()"), 4, 4, hClass);m_wndClassView.InsertItem(_T("~CFakeAppDoc()"), 3, 3, hClass);m_wndClassView.InsertItem(_T("OnNewDocument()"), 3, 3, hClass);hClass = m_wndClassView.InsertItem(_T("CFakeAppView"), 1, 1, hRoot);m_wndClassView.InsertItem(_T("CFakeAppView()"), 4, 4, hClass);m_wndClassView.InsertItem(_T("~CFakeAppView()"), 3, 3, hClass);m_wndClassView.InsertItem(_T("GetDocument()"), 3, 3, hClass);m_wndClassView.Expand(hClass, TVE_EXPAND);hClass = m_wndClassView.InsertItem(_T("CFakeAppFrame"), 1, 1, hRoot);m_wndClassView.InsertItem(_T("CFakeAppFrame()"), 3, 3, hClass);m_wndClassView.InsertItem(_T("~CFakeAppFrame()"), 3, 3, hClass);m_wndClassView.InsertItem(_T("m_wndMenuBar"), 6, 6, hClass);m_wndClassView.InsertItem(_T("m_wndToolBar"), 6, 6, hClass);m_wndClassView.InsertItem(_T("m_wndStatusBar"), 6, 6, hClass);hClass = m_wndClassView.InsertItem(_T("Globals"), 2, 2, hRoot);m_wndClassView.InsertItem(_T("theFakeApp"), 5, 5, hClass);m_wndClassView.Expand(hClass, TVE_EXPAND);return 0;}2、修改MainFrm.cpp① OnCreate方法最后加入如下代码CString str;str.LoadString(ID_VIEW_NAV);if (!m_Nav.Create(str, this, CRect(0, 0, 200, 200), TRUE, ID_VIEW_NAV, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI)){TRACE0("Failed to create navigate window/n");return FALSE; // failed to create}m_Nav.EnableDocking(CBRS_ALIGN_ANY);DockPane(&m_Nav);// ID_VIEW_NAV是自定义的字符串资源CDockablePane同CFormView类的联合使用方法1、CFormView简介① MFC提供了一个名为CFormView的特殊视图类,我们称其为表单视图.表单视图是指用控件来输入和输出数据的视图,用户可以方便地在表单视图中使用控件.表单视图具有对话框和滚动视图的特性,它使程序看起来象是一个具有滚动条的对话框.在有些情况下,用表单视图比用普通视图更符合用户的需要,例如,在向数据库输入数据时,显然用表单的形式可以更习惯些。

VC++中数据类型转换大全

VC++中数据类型转换大全

vc数据类型转换大全(转载)int i = 100;long l = 2001;float f=300.2;double d=12345.119;char username[]=”程佩君”;char temp[200];char *buf;CString str;_variant_t v1;_bstr_t v2;一、其它数据类型转换为字符串短整型(int)itoa(i,temp,10);///将i转换为字符串放入temp中,最后一个数字表示十进制itoa(i,temp,2); ///按二进制方式转换长整型(long)ltoa(l,temp,10);浮点数(float,double)用fcvt可以完成转换,这是MSDN中的例子:int decimal, sign;char *buffer;double source = 3.1415926535;buffer = _fcvt( source, 7, &decimal, &sign );运行结果:source: 3.1415926535 buffer: ‘31415927′ decimal: 1 sign: 0decimal表示小数点的位置,sign表示符号:0为正数,1为负数CString变量str = “2008北京奥运”;buf = (LPSTR)(LPCTSTR)str; //这个因为buf是个char*变量先把CString 变量转换为const char*类型的再变为char*类型的上面的CString转换为char*型号的必须经过两次反之的直接赋值就可以BSTR变量BSTR bstrValue = ::SysAllocStri ng(L”程序员”);char * buf = _com_util::ConvertBSTRToString(bstrValue); SysFreeString(bstrValue);一定注意凡是定义的指针变量一定要用delete显示删除AfxMessageBox(buf);delete(buf);CComBSTR变量CComBSTR bstrVar(”test”);char *buf = _com_util::ConvertBSTRToString(bstrVar.m_str); AfxMessageBox(buf);delete(buf);_bstr_t变量_bstr_t类型是对BSTR的封装,因为已经重载了=操作符,所以很容易使用_bstr_t bstrVar(”test”);const char *buf = bstrVar;///不要修改buf中的内容_bstr_t实际上是个字符指针型的AfxMessageBox(buf);通用方法(针对非COM数据类型)用sprintf完成转换char buffer[200];char c = ‘1′;int i = 35;long j = 1000;float f = 1.7320534f;sprintf( buffer, “%c”,c);sprintf( buffer, “%d”,i);sprintf( buffer, “%d”,j);sprintf( buffer, “%f”,f);二、字符串转换为其它数据类型strcpy(temp,”123″);短整型(int)i = atoi(temp);长整型(long)l = atol(temp);浮点(double)d = atof(temp);CString变量CString name = temp;BSTR变量BSTR bstrValue = ::SysAllocString(L”程序员”);…///完成对bstrValue的使用SysFreeString(bstrValue);CComBSTR变量CComBSTR类型变量可以直接赋值CComBSTR bstrVar1(”test”);CComBSTR bstrVar2(temp);_bstr_t变量_bstr_t类型的变量可以直接赋值_bstr_t bstrVar1(”test”);_bstr_t bstrVar2(temp);三、其它数据类型转换到CString使用CString的成员函数Format来转换,例如:整数(int)str.Format(”%d”,i);浮点数(float)str.Format(”%f”,i);字符串指针(char*)等已经被CString构造函数支持的数据类型可以直接赋值str = username;对于Format所不支持的数据类型,可以通过上面所说的关于其它数据类型转化到char*的方法先转到char *,然后赋值给CString变量。

OpenCASCADE6.7.0创建单文档多视图

OpenCASCADE6.7.0创建单文档多视图
AddDocTemplate(pDocTemplate);
pDocTemplate2D = new CMultiDocTemplate(IDR_MyViewerTYPE, RUNTIME_CLASS(CMyViewerDoc), RUNTIME_CLASS(/*CChildFrame*/CChildFrm2D),
if (!m_wndToolBar.Create(this) || !m_wndToolBar.LoadToolBar(IDR_3dCHILDFRAME)) {
改成下面的形式
#include "OCC_BaseChildFrame.h"
class CChildFrame : public /*CMDIChildWnd*/OCC_BaseChildFrame {
20. 对 MyViewerView.h 做如下修改
#include "OCC_3dView.h"
20. 添加两个类,通过右键单击→【类向导】,来添加两个类,方法如下图。
将这两个类的代码修改成如下的形式。 新添加的 View 类修改成下面的形式:
#include "OCC_2dView.h"
class CMyViewerView2D : public /*CView*/OCC_2dView {
10. 下面将设置工程的属性,可以通过在工程上单击右键,选属性,弹出属性页对话框, 在对话框中进行设置。首先修改包含目录,如下图所示,
11. 添加 WNT
12. 添加 lib 库
lib 库如下: TKBRep.lib FWOSPlugin.lib PTKernel.lib TKBool.lib TKCAF.lib TKCDF.lib TKernel.lib TKFeat.lib TKFillet.lib TKG2d.lib TKG3d.lib TKGeomAlgo.lib TKGeomBase.lib TKHLR.lib TKMath.lib TKOffset.lib TKPCAF.lib TKPrim.lib TKPShape.lib TKService.lib TKTopAlgo.lib TKV3d.lib TKOpenGl.lib mfcsample.lib

点击button之后弹出对话框

点击button之后弹出对话框

让点击CButton 以后弹出一个对话框1、在VIEW视类添加一个CButton类型的成员变量m_btn2、添加视类的ON_CREATE消息里面添加m_btn.Create("Click Me!!",WS_CHILD|WS_VISIBLE,CRect(0,0,100,100),this,ID_CMD1); ID_CMD1是我在资源列表预定的ID,以后统一使用这个ID3、在视类的.h文件中添加消息映射,找到如下// Generated message map functionsprotected://{{AFX_MSG(CWinformView)afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);afx_msg void OnLButtonDown(UINT nFlags, CPoint point);afx_msg void OnCMD1();afx_msg void OnLButtonUp(UINT nFlags, CPoint point);//}}AFX_MSGDECLARE_MESSAGE_MAP()private:CPoint m_pt_o;CButton m_btn;有颜色的一行是自己添加的,这里是影射一个函数4、然后进入视类的.CPP文件添加BEGIN_MESSAGE_MAP(CWinformView, CView)//{{AFX_MSG_MAP(CWinformView)ON_WM_CREATE()ON_WM_LBUTTONDOWN()ON_COMMAND(ID_CMD1, OnCMD1)ON_WM_LBUTTONUP()//}}AFX_MSG_MAP// Standard printing commandsON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview) END_MESSAGE_MAP()兰色一行为添加的!5、在视类的.CPP的尾部写函数描述void CWinformView::OnLButtonUp(UINT nFlags, CPoint point){// TODO: Add your message handler code here and/or call default CBitmap bitmap;bitmap.LoadBitmap(IDB_BITMAP1);CClientDC dc(this);dc.FillRect(CRect(m_pt_o,point),&CBrush(&bitmap));CView::OnLButtonUp(nFlags, point);}CWinformView为我的视类名称好了,可以运行,点击看下!。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

工具栏进行设置LPCREA TESTRUCT是一个指向结构CREA TESTRUCT的指针.以下是该结构的信息:The CREA TESTRUCT structure defines the initialization parameters passed to the window procedure of an application.typedef struct tagCREA TESTRUCT { // csLPVOID lpCreateParams;HINSTANCE hInstance;HMENU hMenu;HWND hwndParent;int cy;int cx;int y;int x;LONG style;LPCTSTR lpszName;LPCTSTR lpszClass;DWORD dwExStyle;} CREA TESTRUCT;MemberslpCreateParamsContains additional data which may be used to create the window. If the window is being created as a result of a call to the CreateWindow or CreateWindowEx function, this member contains the value of the lpParam parameter specified in the function call.If the window being created is an MDI window, this member contains a pointer to an MDICREA TESTRUCT structure.Windows NT: If the window is being created from a dialog template, this member is the address of a SHORT value that specifies the size, in bytes, of the window creation data. The value is immediately followed by the creation data. For more information, see the following Remarks section.hInstanceHandle to the module that owns the new window.hMenuHandle to the menu to be used by the new window.hwndParentHandle to the parent window, if the window is a child window. If the window is owned, this member identifies the owner window. If the window is not a child or owned window, this member is NULL.cySpecifies the height of the new window, in pixels.cxSpecifies the width of the new window, in pixels.ySpecifies the y-coordinate of the upper left corner of the new window. If the new window is a child window, coordinates are relative to the parent window. Otherwise, the coordinates are relative to the screen origin.xSpecifies the x-coordinate of the upper left corner of the new window. If the new window is a child window, coordinates are relative to the parent window. Otherwise, the coordinates are relative to the screen origin.styleSpecifies the style for the new window.lpszNamePointer to a null-terminated string that specifies the name of the new window.lpszClassPointer to a null-terminated string that specifies the class name of the new window.dwExStyleSpecifies the extended style for the new window.RemarksWindows NT: Y ou should access the data represented by the lpCreateParams member using a pointer that has been declared using the UNALIGNED type, because the pointer may not be DWORD aligned. This is demonstrated in the following example:typedef struct tagMyData{// Define creation data here.} MYDA TA;typedef struct tagMyDlgData{SHORT cbExtra;MYDA TA myData;} MYDLGDA TA, UNALIGNED *PMYDLGDA TA;PMYDLGDA TA pMyDlgdata =(PMYDLGDA TA) (((LPCREA TESTRUCT) lParam)->lpCreateParams);The WM_CREA TE message is sent when an application requests that a window be created by calling the CreateWindowEx or CreateWindow function. The window procedure of the new window receives this message after the window is created, but before the window becomes visible. The message is sent before the CreateWindowEx or CreateWindow function returns.WM_CREA TElpcs = (LPCREA TESTRUCT) lParam; // structure with creation dataParameterslParamV alue of lParam. Pointer to a CREA TESTRUCT structure that contains information about the window being created. The members of CREA TESTRUCT are identical to the parameters of the CreateWindowEx function.Return V aluesIf an application processes this message, it should return 0 to continue creation of the window. If the application returns –1, the window is destroyed and the CreateWindowEx or CreateWindow function returns a NULL handle.QuickInfo工具栏何志丹主要内容:1,概要。

2,常用函数3,实例。

4,动态建立工具条5,在工具栏中嵌控件6,用对话框加位图按钮作工具条我们可以在资源编辑器的ToolBar上单击右键,选择Insert ToolBar,选中一个工具栏后,在右边双击它的一项就可以编辑了。

我们可以用图形工具条及颜色盒画它的外表,它的属性有ID,长,宽及鼠标指向它时的说明。

一般CToolBar定义在CMainFrame中,其实现在CMainFrame的OnCreate函数中完成。

if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD |WS_VISIBLE | CBRS_TOP| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY |CBRS_SIZE_DYNAMIC) ||!m_wndToolBar.LoadToolBar(IDR_MAINFRAME)){TRACE0("Failed to create toolbar ");return -1; // fail to create}m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);EnableDocking(CBRS_ALIGN_ANY);DockControlBar(&m_wndToolBar);Bool Create(CWnd *pParentWnd,DWORD dwStu;e = WS_CHILD | WS_VISIBLE |CBRS_TOP,UINT nID = AFX_IDW_TOOLBAR);pParentWnd指定所属窗口。

dwStyle 指定工具栏风格CBRS_TOP 允许工具栏位于框架窗口顶端。

CBRS_BOTTOM 允许工具栏位于框架窗口底端CBRS_NOALIGN 父窗口改变尺寸后工具栏位置不变CBRS_TOOLTIPS 工具栏显示提示条CBRS_SIZE_DYNAMIC 工具幸是动态的CBRS_SIZE_FIXED 工具栏是固定的CBRS_FLOATING 工具栏是浮动的CBRS_FLYBY 当鼠标从命令按钮上掠过时显示提示信息CBRS_HIDE_INPLACE 工具栏对用户不可见SetButtonStyle()函数用来设定命令按钮的风格或间隔区,或设为一组,按钮的风格决定了按钮的外貌和对用户的反应方式.Void SetButtonStyle(int nIndex,UINT nStyle);nIndex 指定工具栏中按钮或间隔的索引号.nStyle TBBS_BUTTON 标准按钮,此为默认值TBBS_SEPARATOR 间隔区TBBS_CHECKBOX 自动确认区TBBS_GROUP 标记为一组按钮的开始TBBS_CHECKGROUP 标记为一组确认框的开始ControlBar类的EnableDocking函数和CFrameWnd类的DockControlBar函数配合,设定工具栏的可活动性.Void EanbleDocking(DWORD dwStyle)CBRS_ALIGN_TOP 允许工具栏位于客户区上侧CBRS_ALIGN_BOTTOM 允许工具栏位于客房区下侧CBRS_ALIGN_LEFT 允许工具栏位于客户区左侧CBRS_ALIGN_RIGHT 允许工具栏位于客户区右侧CBRS_ALIGN_ANY 允许工具栏位于客户区的任意位置CBRS_FLOAT_MULTI 允许多个控制栏在一个迷你框架窗口中浮动Void DockControlBar(….)pBar 要浮动的控制栏指针.nDockBarID指定允许浮动的位置,或为0则不允许浮动,可以由下列值组合而成:AFX_IDW_DOCKBAR_TOP 控制栏置于框架窗口上侧;AFX_IDW_DOCKBAR_BOTTOM 控制栏置于框架窗口下侧AFX_IDW_DOCKBAR_LEFT 控制栏置于框架窗口左侧AFX_IDW_DOCKBAR_RIGHT 控制栏置于框架窗口右侧改变工具栏的命令按钮风格,工具栏的按钮一般默认为命令按钮,当放开标鼠标,命令按钮就”弹出来”,如果我们希望命令按钮能留在被按上的状态,就可以把命令按钮的风格设为确认框。

相关文档
最新文档