怎么查三星手机真假9298怎么看真假

自定义状态栏和工具栏
我的图书馆
自定义状态栏和工具栏
目录转自()
(本章节中例子都是用 VS2005 编译调试的)
相关类: & &&& &, &
创建工具栏:&  
加载工具栏:&  
移动窗口:&  
获得客服区/窗口区域:&   /&
调整和重置窗口客户区的控制栏(工具栏/状态栏)位置:  &
获得请求的窗口对象:  &
获得在窗口管理链表中的下个窗口:  &
设置工具栏按钮和按钮上图像大小:&  
设置对话框按钮:&  
获得 CToolBarCtrl 对象:&  
设置图标:&  
加载工具栏
在对话框中添加工具栏,首先添加一个工具栏资源(资源 ID 为&IDR_TOOLBAR1),工具栏资源和对话框资源,资源视图如下:
然后为对话框添加一个 CToolBar 对象变量名为 m_tbar,然后在对话框初始化函数(即
OnInitDialog&函数)中添加实现代码,代码如下:
//创建 ToolBar 和加载资源
if(m_tbar.Create(this) && m_tbar.LoadToolBar(IDR_TOOLBAR1))
/* 前期准备工作 *************************************************************************/
CRect rcClientO
CRect rcClientN
// 用 rcClientOld 获取客户区间
GetClientRect(rcClientOld);
// 用 rcClientNew 获得除了 ToolBar 区的对话框客户区
RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,<span style="COLOR: #,reposQuery,rcClientNew);
//获得在加入 ToolBar 后控件应该移动的偏移偏移量
CPoint ptOffset(rcClientNew.left-rcClientOld.left,rcClientNew.top-rcClientOld.top);
/* 重新设置对话框的窗体区间 *************************************************************/
//得到对话框窗体区间
GetWindowRect(rcWindow);
//修改对话框宽度和高度,即让对话框添加上 ToolBar 的高度和适应 ToolBar 的高度
rcWindow.right += rcClientOld.Width() - rcClientNew.Width();
rcWindow.bottom += rcClientOld.Height() - rcClientNew.Height();
//移动对话框
MoveWindow(rcWindow,FALSE);
/* 调整控件位置 *************************************************************************/
//获得窗口控件
CWnd* pwndChild = GetWindow(GW_CHILD);
//遍历控件
while(pwndChild)
//获得控件区间
pwndChild-&GetWindowRect(rcChild);
//将屏幕坐标转换为客户区坐标
ScreenToClient(rcChild);
//将控件移动相对位置
rcChild.OffsetRect(ptOffset);
//移动控件
pwndChild-&MoveWindow(rcChild,FALSE);
//获得下个控件句柄
pwndChild = pwndChild-&GetNextWindow();
//显示 ToolBar
RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,<span style="COLOR: #);
加载自定义位图的工具栏
在对话框中添加工具栏,首先添加一个位图资源(资源 ID 为&IDB_BITMAP1),位图资源和对话框资源,资源视图如下:
然后为对话框添加一个 CToolBar 对象变量名为 m_tbar,然后在对话框初始化函数(即
OnInitDialog&函数)中添加实现代码,(具体代码和添加工具栏中的相似)代码如下:
//创建工具栏
if(m_tbar.Create(this,WS_CHILD|WS_VISIBLE|CBRS_SIZE_FIXED|CBRS_TOP|CBRS_TOOLTIPS))
/* 创建自定义位图的工具栏初始化工作 ***************************************************/
//定义工具栏上的按钮的所对应的标识
static UINT BASED_CODE DockTool[]={IDOK,IDCANCEL};
//加载工具栏要用的位图
bitmap.LoadBitmapW(IDB_BITMAP1);
//建立工具栏中的图片列表
static CImageList m_ilToolB
m_ilToolBar.Create(<span style="COLOR: #0,<span style="COLOR: #0,ILC_COLOR32,<span style="COLOR: #,<span style="COLOR: #);//以宽 100,长 100 像素来切割图片
m_ilToolBar.Add(&bitmap,(CBitmap*)NULL);
//设置工具栏按钮图片
m_tbar.GetToolBarCtrl().SetImageList(&m_ilToolBar);
//设置工具栏的按钮大小,和按钮中位图大小(注意: 按钮大小必须大于按钮中位图大小)
SIZE sbutton,sI
sbutton.cx= <span style="COLOR: #0;
sbutton.cy=<span style="COLOR: #0;
sImage.cx=<span style="COLOR: #0;
sImage.cy=<span style="COLOR: #0;
m_tbar.SetSizes(sbutton,sImage);
//设置工具栏上按钮的所对应的标识,和按钮个数
m_tbar.SetButtons(DockTool,(UINT)<span style="COLOR: #);
/* 前期准备工作 *************************************************************************/
CRect rcClientO
CRect rcClientN
// 用 rcClientOld 获取客户区间
GetClientRect(rcClientOld);
// 用 rcClientNew 获得除了 ToolBar 区的对话框客户区
RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,<span style="COLOR: #,reposQuery,rcClientNew);
//获得在加入 ToolBar 后控件应该移动的偏移偏移量
CPoint ptOffset(rcClientNew.left-rcClientOld.left,rcClientNew.top-rcClientOld.top);
/* 重新设置对话框的窗体区间 *************************************************************/
//得到对话框窗体区间
GetWindowRect(rcWindow);
//修改对话框宽度和高度,即让对话框添加上 ToolBar 的高度和适应 ToolBar 的高度
rcWindow.right += rcClientOld.Width() - rcClientNew.Width();
rcWindow.bottom += rcClientOld.Height() - rcClientNew.Height();
//移动对话框
MoveWindow(rcWindow,FALSE);
/* 调整控件位置 *************************************************************************/
//获得窗口控件
CWnd* pwndChild = GetWindow(GW_CHILD);
//遍历控件
while(pwndChild)
//获得控件区间
pwndChild-&GetWindowRect(rcChild);
//将屏幕坐标转换为客户区坐标
ScreenToClient(rcChild);
//将控件移动相对位置
rcChild.OffsetRect(ptOffset);
//移动控件
pwndChild-&MoveWindow(rcChild,FALSE);
//获得下个控件句柄
pwndChild = pwndChild-&GetNextWindow();
//显示 ToolBar
RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,<span style="COLOR: #);
创建工具栏:&  
加载工具栏:&  
设置工具栏按钮和按钮上图像大小:&  
设置对话框按钮:&  
获得 CToolBarCtrl 对象:&  
设置图标:&  
设置工具栏可以停靠位置:&  
设置框架窗口被工具栏停靠:  &
设置框架可以让工具栏停靠位置:&  
判断窗口是否可见:&  
隐藏/显示工具栏:&  
加载工具栏
在文档中添加工具栏,这个功能只能在框架类中完成(即&CFrameWnd 类),由于一生成 单文档/多文档 工程时候,会为程序添加一个默认的工具栏(资源
ID 为).这里用的是单文档工程这个工具栏的资源视图如下:
这个工具栏的添加在框架类的初始化(即 OnCreate 函数)中,具体代码如下(省略了无关代码):
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
if (CFrameWnd::OnCreate(lpCreateStruct) == -<span style="COLOR: #)
return -<span style="COLOR: #;
//创建一个工具栏
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("未能创建工具栏\n");
return -<span style="COLOR: #;
// 未能创建
//使工具栏可以停靠
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
加载自定义位图的工具栏
在文档中添加工具栏,这个功能只能在框架类中完成(即&CFrameWnd 类),这里生成的是单文档工程,然后为文档添加一个位图资源,资源视图如下:
然后为框架类添加一个&CToolBar 对象变量名为 m_Mytbar,在框架类的初始化(即 OnCreate
函数)中,添加相关的实现代码,具体代码如下:
//创建自定义工具栏
if (m_Mytbar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC))
//定义工具栏上的按钮的所对应的标识
static UINT BASED_CODE DockTool[]={ID_FILE_NEW,ID_FILE_OPEN};
//加载工具栏要用的位图
bitmap.LoadBitmapW(IDB_BITMAP1);
//建立工具栏中的图片列表
static CImageList ilToolB
ilToolBar.Create(<span style="COLOR: #0,<span style="COLOR: #0,ILC_COLOR32,<span style="COLOR: #,<span style="COLOR: #);//以宽 100,长 100 像素来切割图片
ilToolBar.Add(&bitmap,(CBitmap*)NULL);
//设置工具栏按钮图片
m_Mytbar.GetToolBarCtrl().SetImageList(&ilToolBar);
//设置工具栏的按钮大小,和按钮中位图大小(注意: 按钮大小必须大于按钮中位图大小)
SIZE sbutton,sI
sbutton.cx= <span style="COLOR: #0;
sbutton.cy=<span style="COLOR: #0;
sImage.cx=<span style="COLOR: #0;
sImage.cy=<span style="COLOR: #0;
m_Mytbar.SetSizes(sbutton,sImage);
//设置工具栏上按钮的所对应的标识,和按钮个数
m_Mytbar.SetButtons(DockTool,(UINT)<span style="COLOR: #);
//设置工具栏使其可以停靠在框架窗口上
m_Mytbar.EnableDocking(CBRS_ALIGN_ANY);
//把工具栏停靠在框架窗口上
DockControlBar(&m_Mytbar);
工具栏的显示与隐藏
接着上个代码示例,为文档程序在主菜单栏上添加个 显示/隐藏工具栏 的菜单项,完成 显示/隐藏工具栏 的这个功能.菜单资源(菜单资源 ID
为&IDR_MAINFRAME,菜单项 ID 为 ID_TB)视图如下:
为菜单项 显示/隐藏工具栏&在框架类中添加事件响应函数,后在事件响应函数中添加相关操作,具体代码如下:
if(m_Mytbar.IsWindowVisible())
ShowControlBar(&m_Mytbar,false,false);
ShowControlBar(&m_Mytbar,true,false);
相关类:  && , &
移动窗口:&  
获得客服区/窗口区域:&  &/&
调整和重置窗口客户区的控制栏(工具栏/状态栏)位置:  &
创建状态栏:&  
设置状态栏指示器(用于添加或减少状态栏上窗格):&  
获得&/&设置状态栏上窗格的显示的字符串:&   /&
用标识获得窗格索引:&  
获得 / 设置窗格属性(ID,样式,宽度):&  /&
获得索引窗口格的矩形大小:&  
获得索引窗口格的 ID:&  
获得 / 设置索引窗口格的风格:&  &/&
设置工具宽度:&  
设置所有窗口格的图标:&  
在对话框中添加状态栏,首先添加两个图标资源(资源 ID 为 IDI_ICON1,IDI_ICON2),图标资源和对话框资源,资源视图如下:
然后为对话框添加一个 CStatusBar&对象变量名为 m_StatBar,然后在对话框初始化函数(即
OnInitDialog&函数)中添加实现代码,具体代码如下:
//创建状态栏
if(m_StatBar.Create(this))
// 状态行指示器对应 ID
static UINT indicators[] =
ID_SEPARATOR,
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
// 设置状态栏指示器 ID 和指示器个数
m_StatBar.SetIndicators(indicators,sizeof(indicators)/sizeof(UINT));
// 设置状态栏指示器文本
m_StatBar.SetPaneText(<span style="COLOR: #,L"指示器1",<span style="COLOR: #);
m_StatBar.SetPaneText(<span style="COLOR: #,L"指示器2",<span style="COLOR: #);
m_StatBar.SetPaneText(<span style="COLOR: #,L"指示器3",<span style="COLOR: #);
m_StatBar.SetPaneText(<span style="COLOR: #,L"指示器4",<span style="COLOR: #);
// 设置状态栏指示器属性
m_StatBar.SetPaneInfo(<span style="COLOR: #,ID_SEPARATOR,SBPS_NORMAL
,<span style="COLOR: #0);
m_StatBar.SetPaneInfo(<span style="COLOR: #,ID_INDICATOR_CAPS,SBPS_NORMAL
,<span style="COLOR: #0);
m_StatBar.SetPaneInfo(<span style="COLOR: #,ID_INDICATOR_NUM,SBPS_NORMAL
,<span style="COLOR: #0);
m_StatBar.SetPaneInfo(<span style="COLOR: #,ID_INDICATOR_SCRL,SBPS_NORMAL
,<span style="COLOR: #0);
//为状态栏指示器添加图标
HICON icon[<span style="COLOR: #];
icon[<span style="COLOR: #] = AfxGetApp()-&LoadIcon (IDI_ICON1);
icon[<span style="COLOR: #] = AfxGetApp()-&LoadIcon (IDI_ICON2);
m_StatBar.GetStatusBarCtrl().SetIcon(<span style="COLOR: #,icon[<span style="COLOR: #]);
m_StatBar.GetStatusBarCtrl().SetIcon(<span style="COLOR: #,icon[<span style="COLOR: #]);
m_StatBar.GetStatusBarCtrl().SetIcon(<span style="COLOR: #,icon[<span style="COLOR: #]);
m_StatBar.GetStatusBarCtrl().SetIcon(<span style="COLOR: #,icon[<span style="COLOR: #]);
//设置状态栏高度
m_StatBar.GetStatusBarCtrl().SetMinHeight(<span style="COLOR: #);
/* 前期准备工作 *************************************************************************/
CRect rcClientO
CRect rcClientN
// 用 rcClientOld 获取客户区间
GetClientRect(rcClientOld);
// 用 rcClientNew 获得除了 CStatusBar 区的对话框客户区
RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,<span style="COLOR: #,reposQuery,rcClientNew);
/* 这里要注意下如果你在对话框中添加了工具栏和状态栏,那么这里获得的是这些控制栏的矩形区,即高度是控制栏(工具栏加状态栏)的总和,宽度是控制栏中最宽的那个..********/
/* 重新设置对话框的窗体区间 *************************************************************/
// 得到对话框窗体区间
GetWindowRect(rcWindow);
// 修改对话框宽度和高度,即让对话框添加上 CStatusBar 的高度和适应 CStatusBar 的宽度
rcWindow.right += rcClientOld.Width() - rcClientNew.Width();
rcWindow.bottom += rcClientOld.Height() - rcClientNew.Height();
// 移动对话框
MoveWindow(rcWindow,FALSE);
// 显示状态栏
RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,<span style="COLOR: #);
创建状态栏:&  
设置状态栏指示器(用于添加或减少状态栏上窗格):&  
获得&/&设置状态栏上窗格的显示的字符串:&  &/&
用标识获得窗格索引:&  
获得 / 设置窗格属性(ID,样式,宽度):&  /&
获得索引窗口格的矩形大小:&  
获得索引窗口格的 ID:&  
获得 / 设置索引窗口格的风格:&  &/&
设置工具宽度:&  
设置所有窗口格的图标:&  
在文档中添加状态栏,这个功能只能在框架类中完成(即&CFrameWnd 类),由于一生成 单文档/多文档
工程时候,会为程序添加一个默认的状态栏.为了希望在这个默认的状态栏上添加资源图标(资源 ID 为
IDI_ICON1,IDI_ICON2),定义的两个图标资源视图如下:
这个状态栏的添加在框架类的初始化(即 OnCreate 函数)中,而窗格的索引值在框架类的实现文件头出定义,具体代码如下(省略了无关代码):
// 状态行指示器对应 ID
static UINT indicators[] =
ID_SEPARATOR,
// 状态行指示器
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
TRACE0("未能创建状态栏\n");
return -<span style="COLOR: #;
// 未能创建
/* 以下是我为状态栏添加图标的实现代码 *****************/
//为状态栏指示器添加图标
HICON icon[<span style="COLOR: #];
icon[<span style="COLOR: #] = AfxGetApp()-&LoadIcon (IDI_ICON1);
icon[<span style="COLOR: #] = AfxGetApp()-&LoadIcon (IDI_ICON2);
m_wndStatusBar.GetStatusBarCtrl().SetIcon(<span style="COLOR: #,icon[<span style="COLOR: #]);
m_wndStatusBar.GetStatusBarCtrl().SetIcon(<span style="COLOR: #,icon[<span style="COLOR: #]);
m_wndStatusBar.GetStatusBarCtrl().SetIcon(<span style="COLOR: #,icon[<span style="COLOR: #]);
m_wndStatusBar.GetStatusBarCtrl().SetIcon(<span style="COLOR: #,icon[<span style="COLOR: #]);
//设置状态栏高度
m_wndStatusBar.GetStatusBarCtrl().SetMinHeight(<span style="COLOR: #);
// 设置状态栏指示器属性
m_wndStatusBar.SetPaneInfo(<span style="COLOR: #,ID_SEPARATOR,SBPS_NORMAL
,<span style="COLOR: #0);
m_wndStatusBar.SetPaneInfo(<span style="COLOR: #,ID_INDICATOR_CAPS,SBPS_NORMAL
,<span style="COLOR: #0);
m_wndStatusBar.SetPaneInfo(<span style="COLOR: #,ID_INDICATOR_NUM,SBPS_NORMAL
,<span style="COLOR: #0);
m_wndStatusBar.SetPaneInfo(<span style="COLOR: #,ID_INDICATOR_SCRL,SBPS_NORMAL
,<span style="COLOR: #0);
return <span style="COLOR: #;
两种方法:1.使用CStatusBar类。步骤如下:&&& (1)在C***Dlg类为添加成员变量:CStatusBar m_StatusBar&& (2)在String Table中添加一些要显示在状态栏上的字符串。&& (3)在C***Dlg源文件中定义一个全局数组:&&&&&&&&& static UINT indicators[]={&&&&&&&&&&&&&&&&&&&&&&&&&& ID_SEPARATOR,&&&&&&&&&&&&&&&&&&&&&&&&& IDS_COMPANY,&&&&&&&&&&&&&&&&&&&&&&&&& IDS_MICROSOFT,&&&&&&&&&&&&&&&&&&&&&&&& IDS_TIME&&&&&&&&&& };&& (4)在OnInitDialog()函数中添加如下代码:&&&&&&&&&&&& CRect R&&&&&&&&&&& GetClientRect(&Rect);&&&&&&&&&&&&&&&&&&&&&&&&&& //获取客户区域&&&&&&&&&&& if(!m_StatusBar.Create(this) || !m_StatusBar.SetIndicators(indicators,sizeof(indicators)/sizeof(UINT)))&&&&&&&&&& {&&&&&&&&&&&&&&&&&&& TRACE0("Failed to create status bar\n");&&&&&&&&&&&&&&&&&&&& return -1;&&&&&&&&&&&& }&&&&&&&&&& m_StatusBar.MoveWindow(0,Rect.bottom-20,Rect.right,20);&&&&&&&&&&&& //设置状态栏位置2.使用CStatusBarCtrl类。步骤如下:&& (1)在C***Dlg类为添加成员变量:CStatusBarCtrl m_StatusBar&& (2)在OnInitDialog()函数中添加如下代码:&&&&&&& CRect R&&&&&&& this-&GetClientRect(&Rect);&&&&&&&&&&&&&&&&& //获取客户区域&&&&&&&& m_StatusBar.Create(WS_CHILD | WS_VISIBLE,CRect(0,0,0,0),this,IDR_STATUSBAR);&&&&&&& int width[5];&&&&&&& width[0]=Rect.Width()*0.1;&&&&&& width[1]=Rect.Width()*0.4;&&&&&&& width[2]=Rect.Width()*0.6;&&&&&&& width[3]=Rect.Width()*0.8;&&&&&&& width[4]=Rect.Width();&&&&&&& m_StatusBar.SetParts(5,width);&&&&&&& m_StatusBar.SetText("公司",0,0);&&&&&&& m_StatusBar.SetText("微软(中国)有限公司",1,0);&&&&&&& m_StatusBar.SetText("系统时间",3,0);&&&&&&& SetTimer(1,1000,NULL);&&&&&&&&&&&&&&&&&&&&&&&&&&&& //设置定时器&& (3)在C***Dlg类上添加WM_TIMER消息响应,编写响应函数OnTimer(UINT nIDEvent):&&&&&&&&& CTime time=CTime::GetCurrentTime();&&&&&&&&&&&& //获取当前时间&&&&&&&&& CString str=time.Format("%H:%M:%S");&&&&&&&&&&&& //时间格式化为字符串&&&&&&&&& m_StatusBar.SetText(str,4,0);最终效果:注解:SetParts函数的原型如下:BOOL&SetParts(&int&nParts,&int*&pWidths&);其中nParts指示将状态栏分为多少个部分;pWidths指向一个int型的数组,数组中每一个元素指示状态栏各部分相对于客户区域的右边界。SetText函数的原型如下:BOOL&SetText(&LPCTSTR&lpszText,&int&nPane,&int&nType&);其中lpszText指向状态栏字符串;nPane指示要设置文本的状态栏部分的索引号;nType指示绘画操作的类型。应该说也是一个老生常谈的问题了,写一写总结回顾一下。
TA的最新馆藏下次自动登录
现在的位置:
& 综合 & 正文
VC中单文档框架删除菜单的调试经历
最近想在VC中单文档框架中删除菜单,状态栏,工具栏 。状态栏,工具栏在CMainFrame::OnCreate中就可以注释调,但是怎么样将菜单删掉呢?百度了一下,不太好找到。只好依靠现有知识,自己找到办法了。通过跟踪调试MFC的居然让我找到了办法。
首先,我们先想办法达到在单文档界面中不显示菜单的效果。
通过现有知识,我们知道MFC是在CMainFrame::OnCreate中生成状态栏,工具栏的。如下:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct){
if (CFrameWnd::OnCreate(lpCreateStruct) == -<span style="COLOR: #)
return -<span style="COLOR: #;
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("未能创建工具栏 ");
return -<span style="COLOR: #;
// 未能创建
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
TRACE0("未能创建状态栏 ");
return -<span style="COLOR: #;
// 未能创建
// TODO: 如果不需要工具栏可停靠,则删除这三行
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
return <span style="COLOR: #;}
所以如果不想要状态栏,工具栏,直接在CMainFrame::OnCreate中将相关代码注释调就行了。那么,菜单相关的代码在哪呢?遍历一遍CMainFrame类,没找到。根据代码相关性,既然状态栏,工具栏是在 CMainFrame::OnCreate中生成的,那么菜单估计也是在这个函数里面生成的。
首先在 if (CFrameWnd::OnCreate(lpCreateStruct) == -1) 处下断点,进入函数内部,代码如下:
int CFrameWnd::OnCreate(LPCREATESTRUCT lpcs){
ENSURE_ARG(lpcs != NULL);
CCreateContext* pContext = (CCreateContext*)lpcs-&lpCreateP
return OnCreateHelper(lpcs, pContext);}
继续进入OnCreateHelper函数,代码如下:
int CFrameWnd::OnCreateHelper(LPCREATESTRUCT lpcs, CCreateContext* pContext){
if (CWnd::OnCreate(lpcs) == -<span style="COLOR: #)
return -<span style="COLOR: #;
// create special children first
if (!OnCreateClient(lpcs, pContext))
TRACE(traceAppMsg, <span style="COLOR: #, "Failed to create client pane/view for frame. ");
return -<span style="COLOR: #;
// post message for initial message string
PostMessage(WM_SETMESSAGESTRING, AFX_IDS_IDLEMESSAGE);
// make sure the child windows have been properly sized
RecalcLayout();
return <span style="COLOR: #;
// create ok}
下一步进入OnCreateClient,代码如下:
BOOL CFrameWnd::OnCreateClient(LPCREATESTRUCT, CCreateContext* pContext){
// default create client will create a view if asked for it
if (pContext != NULL && pContext-&m_pNewViewClass != NULL)
if (CreateView(pContext, AFX_IDW_PANE_FIRST) == NULL)
return FALSE;
return TRUE;}
进入CreateView,代码如下:
CWnd* CFrameWnd::CreateView(CCreateContext* pContext, UINT nID){
ASSERT(m_hWnd != NULL);
ASSERT(::IsWindow(m_hWnd));
ENSURE_ARG(pContext != NULL);
ENSURE_ARG(pContext-&m_pNewViewClass != NULL);
// Note: can be a CWnd with PostNcDestroy self cleanup
CWnd* pView = (CWnd*)pContext-&m_pNewViewClass-&CreateObject();
if (pView == NULL)
TRACE(traceAppMsg, <span style="COLOR: #, "Warning: Dynamic create of view type %hs failed. ",
pContext-&m_pNewViewClass-&m_lpszClassName);
return NULL;
ASSERT_KINDOF(CWnd, pView);
// views are always created with a border!
if (!pView-&Create(NULL, NULL, AFX_WS_DEFAULT_VIEW,
CRect(<span style="COLOR: #,<span style="COLOR: #,<span style="COLOR: #,<span style="COLOR: #), this, nID, pContext))
TRACE(traceAppMsg, <span style="COLOR: #, "Warning: could not create view for frame. ");
return NULL;
// can't continue without a view
if (pView-&GetExStyle() & WS_EX_CLIENTEDGE)
// remove the 3d style from the frame, since the view is
providing it.
// make sure to recalc the non-client area
ModifyStyleEx(WS_EX_CLIENTEDGE, <span style="COLOR: #, SWP_FRAMECHANGED);
return pV}
进入 if (!pView-&Create(NULL, NULL, AFX_WS_DEFAULT_VIEW,CRect(0,0,0,0), this, nID, pContext)),代码如下:
BOOL CWnd::Create(LPCTSTR lpszClassName,
LPCTSTR lpszWindowName, DWORD dwStyle,
const RECT& rect,
CWnd* pParentWnd, UINT nID,
CCreateContext* pContext){
// can't use for desktop or pop-up windows (use CreateEx instead)
ASSERT(pParentWnd != NULL);
ASSERT((dwStyle & WS_POPUP) == <span style="COLOR: #);
return CreateEx(<span style="COLOR: #, lpszClassName, lpszWindowName,
dwStyle | WS_CHILD,
rect.left, rect.top,
rect.right - rect.left, rect.bottom - rect.top,
pParentWnd-&GetSafeHwnd(), (HMENU)(UINT_PTR)nID, (LPVOID)pContext);}
进入CreateEx,代码如下:
BOOL CWnd::CreateEx(DWORD dwExStyle, LPCTSTR lpszClassName,
LPCTSTR lpszWindowName, DWORD dwStyle,
int x, int y, int nWidth, int nHeight,
HWND hWndParent, HMENU nIDorHMenu, LPVOID lpParam){
ASSERT(lpszClassName == NULL || AfxIsValidString(lpszClassName) ||
AfxIsValidAtom(lpszClassName));
ENSURE_ARG(lpszWindowName == NULL || AfxIsValidString(lpszWindowName));
// allow modification of several common create parameters
CREATESTRUCT
cs.dwExStyle = dwExS
cs.lpszClass = lpszClassN
cs.lpszName = lpszWindowN
cs.style = dwS
cs.cx = nW
cs.cy = nH
cs.hwndParent = hWndP
cs.hMenu = nIDorHM
cs.hInstance = AfxGetInstanceHandle();
cs.lpCreateParams = lpP
if (!PreCreateWindow(cs))
PostNcDestroy();
return FALSE;
AfxHookWindowCreate(this);
HWND hWnd = ::AfxCtxCreateWindowEx(cs.dwExStyle, cs.lpszClass,
cs.lpszName, cs.style, cs.x, cs.y, cs.cx, cs.cy,
cs.hwndParent, cs.hMenu, cs.hInstance, cs.lpCreateParams);#ifdef _DEBUG
if (hWnd == NULL)
TRACE(traceAppMsg, <span style="COLOR: #, "Warning: Window creation failed: GetLastError returns 0x%8.8X ",
GetLastError());
if (!AfxUnhookWindowCreate())
PostNcDestroy();
// cleanup if CreateWindowEx fails too soon
if (hWnd == NULL)
return FALSE;
ASSERT(hWnd == m_hWnd); // should have been set in send msg hook
return TRUE;}
注意 cs.hMenu = nIDorHM
这段代码明显是与菜单有关的代码,那么找到了框架是如何生成菜单的,将菜单加入到框架中的,我们又如何在框架中将菜单删除呢?菜单的赋值是赋给CREATESTRUCT结构,所以猜测CREATESTRUCT结构可以控制菜单。返回到CMainFrame中,我们可以看到CMainFrame::OnCreate()的参数是LPCREATESTRUCT,所以先修改CMainFrame::OnCreate()如下:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct){
lpCreateStruct-&hMenu = NULL;
if (CFrameWnd::OnCreate(lpCreateStruct) == -<span style="COLOR: #)
return -<span style="COLOR: #;
return <span style="COLOR: #;l}
编译,运行。还有菜单。 再回到CMainFrame中,发现PreCreateWindow也有CREATESTRUCT结构,修改代码如下:
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs){
cs.hMenu = NULL;
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: 在此处通过修改
CREATESTRUCT cs 来修改窗口类或样式
return TRUE;}
编译运行,成功了。菜单没了。
第二步,既然菜单没用了,那么我们可不可以把wizard自动生成的菜单删除调呢?说干就干,删除菜单IDR_MAINFRAME,编译运行,什么“建立空文档失败”,直接退出。继续跟踪,调试吧。
首先估计是在CMainFrame中出的问题,在CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)中下断点,编译运行,结果没进入断点,程序就出错了,那在App类的InitInstance()中下断点吧。跟踪,发现是在
if (!ProcessShellCommand(cmdInfo))
return FALSE;
中出错的。再次调试,进入ProcessShellCommand()函数内部,这次出错地方在
case CCommandLineInfo::FileNew:
if (!AfxGetApp()-&OnCmdMsg(ID_FILE_NEW, <span style="COLOR: #, NULL, NULL))
OnFileNew();
同理,一步一步的,我们就可以找到最后出错的确切地点,中间过程省略。最后发现出错代码如下:
BOOL CFrameWnd::Create(LPCTSTR lpszClassName,
LPCTSTR lpszWindowName,
DWORD dwStyle,
const RECT& rect,
CWnd* pParentWnd,
LPCTSTR lpszMenuName,
DWORD dwExStyle,
CCreateContext* pContext){
HMENU hMenu = NULL;
if (lpszMenuName != NULL)
// load in a menu that will get destroyed when window gets destroyed
HINSTANCE hInst = AfxFindResourceHandle(lpszMenuName, ATL_RT_MENU);
if ((hMenu = ::LoadMenu(hInst, lpszMenuName)) == NULL)
TRACE(traceAppMsg, <span style="COLOR: #, "Warning: failed to load menu for CFrameWnd. ");
PostNcDestroy();
// perhaps delete the C++ object
return FALSE;
m_strTitle = lpszWindowN
// save title for later
if<span style="COLOR: #00
&&&&推荐文章:
【上篇】【下篇】

我要回帖

更多关于 三星9298如何看真假 的文章

 

随机推荐