MFC SDI单文档 状态栏 进度条 启动画面编程技巧 ...
状态栏的编程离不开 CStatusBar类 CProgressCtrl 进 度条相关的控件 下面我们介绍状态栏 编程技巧 以及在状态栏添加进度条 应用程序的启动界面 状态栏的添加步骤 SDI 单文档中 下面是MFC给的 状态栏的创建步骤 Construct the CStatusBar object. 构造一个 CS
状态栏的编程离不开 CStatusBar类 CProgressCtrl 进 度条相关的控件 下面我们介绍状态栏 编程技巧 以及在状态栏添加进度条 应用程序的启动界面
状态栏的添加步骤 SDI 单文档中 下面是MFC给的 状态栏的创建步骤
Construct the CStatusBar object.
构造一个 CStatusBar对象
Call the Create (or CreateEx) function to create the status-bar window and attach it to the CStatusBar object.
调用CreateEx函数创建一个状态栏
Call SetIndicators to associate a string ID with each indicator
调用SetIndicators 为每个指示器附加一个 字符串资源ID static UINT indicators[]={
........
};
1. 下面是在框架类的处理 添加我们自己的状态栏指示器 我们可以定义自己的指示器数组
static UINT indicator[] =
{
ID_SEPARATOR, // status line indicator 最长的那个格索引为 0
ID_INDICATOR_CAPS, //每个代表一个字符串资源
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
...... //这里增加字符串资源 会反映到状态栏
};
OnCreate(LPCREATESTRUCTION lp)函数中 有如下代码
if (!m_wndStatusBar.Create(this) || //创建
!m_wndStatusBar.SetIndicators(indicator, //设置指示器的个数
sizeof(indicator)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
2.给状态栏 指定ID号的指示器 增加时间 这时候用到 CTime类 获得系统时间 下面是代码 CStatusBar m_statusBar; 在相应WM_PAINT消息相应函数 OnPaint
SetTimer(1000,1000,NULL);
捕获WM_TIMER消息 在OnTimer函数中 添加如下代码
CTime time=CTime::GetCurrentTime();// 经过静态方法返回一个CTime对象
CString str=time.Format("%H:%M:%S"); //格式化时间 到str
CClientDC dc(this); //创建一个 框架类的dc
CSize size=dc.GetTextExtent(str); //获得字符串中在屏幕上显示的尺寸
int index =m_wndStatusBar.CommandToIndex(IDS_TIMER); //通过ID获取索引
m_wndStatusBar.SetPaneInfo(index,IDS_TIMER,SBPS_NORMAL,size.cx); //设置指示器的宽度
m_wndStatusBar.SetPaneText(index,str); //设置指定索引指示器的文本
3.在状态栏的 IDS_PROGRESS上添加一个 进度条 CProgressCtrl 类 在框架类增加变量 CProgressCtrl m_progress;
在OnPaint函数 添加代码响应 WM_PAINT消息
CRect rect; //创建CRect对象
m_wndStatusBar.GetItemRect(m_wndStatusBar.CommandToIndex(IDS_PROGRESS),&rect); //获得一个指定索引的指示器的矩形区域
if(!m_progress.m_hWnd) //判断句柄是否为空
{
m_progress.Create(PBS_SMOOTH|WS_CHILD|WS_VISIBLE,rect,&m_wndStatusBar,123); //如果句柄为空那么创建进度条
}
else
{
m_progress.MoveWindow(&rect); //否则移动到当前区域
}
m_progress.SetPos(50); //设置进度条初始位置 50
在 OnTimer函数中加上 m_stausBar.StepIt();//进度条按指定步长 一秒 前进一次
4.在最长的指示器上显示 视图的X Y坐标 我们需要相应视图的 WM_MOUSEMOVE事件 并且调用 框架类的函数执行
#include "MainFrm.h"
void CMyView::OnMouseMove(UINT nFlags, CPoint point)
{
CString str="";
str.Format("x=%d,y=%d",point.x,point.y);
// (((CMainFrame*)GetParent())->m_wndStatusBar).SetWindowText(str); //直接通过状态栏指针设置索引为0指示器
// (((CMainFrame*)GetParent())->m_wndStatusBar).SetPaneText(0,str); //设置按钮文本 索引为0
// ((CMainFrame*)GetParent())->SetMessageText(str);//框架类的函数 直接设置 索引为0的状态栏指示器文本
// ((CMainFrame*)GetParent())->GetMessageBar()->SetWindowText(str); //通过框架类函数获得 状态栏指针 然后调用SetWindowText设置文本
GetParent()->GetDescendantWindow(AFX_IDW_STATUS_BAR)->SetWindowText(str); //CWnd类的函数获得一个子孙窗体的指针 我们可以传递状态栏ID获得
CView::OnMouseMove(nFlags, point);
}
5.增加启动画面 我们可以利用向导增加之后 我们自行设置 启动画面的 style
project->add to project ->comments controls 添加-> vc++ components -> splash screen 就完成了启动画面的添加
对于启动时间 画面 我们可以自行在生成的类中设置

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

This article will introduce how to solve the problem of insufficient memory or disk space to repage or print the document in Microsoft Word. This error usually occurs when users try to print a Word document. If you encounter a similar error, please refer to the suggestions provided in this article to resolve it. Insufficient memory or disk space to repage or print this document Word error How to resolve the Microsoft Word printing error "There is not enough memory or disk space to repage or print the document." Update Microsoft Office Close memory-hogging applications Change your default printer Start Word in safe mode Rename the NorMal.dotm file Save the Word file as another

When a friend's computer is missing certain files, the application cannot start normally with error code 0xc000012d. In fact, it can be solved by re-downloading the files and installing them. The application cannot start normally 0xc000012d: 1. First, the user needs to download ".netframework". 2. Then find the download address and download it to your computer. 3. Then double-click on the desktop to start running. 4. After the installation is completed, return to the wrong program location and open the program again.

"The connection status in the event log message shows Standby: Disconnected due to NIC compliance. This means that the system is in standby mode and the network interface card (NIC) has been disconnected. Although this is usually a network issue , but can also be caused by software and hardware conflicts. In the following discussion, we will explore how to solve this problem." What is the reason for standby connection disconnection? NIC compliance? If you see the "ConnectivityStatusinStandby:DisConnected,Reason:NICCompliance" message in Windows Event Viewer, this indicates that there may be a problem with your NIC or network interface controller. This situation is usually

Practical tips and methods to solve the black screen on Ubuntu startup Introduction: Ubuntu is a popular Linux operating system, but sometimes you may encounter a black screen problem during the startup process. This problem can be caused by a variety of reasons, such as graphics card driver issues, software conflicts, or system errors. This article will introduce some practical tips and methods to help solve the black screen problem at Ubuntu startup to ensure the stable operation of the system. 1. Update and reinstall the graphics card driver to enter recovery mode: press the Shift key during startup to enter

Reinstalling the system may not be a foolproof solution, but after reinstalling, I found that when the computer is turned on, it will display white text on a black background, and then give a prompt: rebootandselectproperbootdevice, what is going on? Such a prompt is usually caused by a boot error. In order to help everyone, the editor has brought you a solution. Computer use is becoming more and more popular, and computer failures are becoming more and more common. No, recently some users encountered a black screen when turning on the computer, and prompted Reboot and Select Proper Boot device, and the computer system could not start normally. What's going on? How to solve it? The user is confused. Next, the editor will follow

It is 395 words, which is 495. This article will show you how to add red lines in Word documents. Redlining a document refers to making modifications to the document so that users can clearly see the changes. This feature is very important when multiple people are editing a document together. What redline means Marking a document Redlining means using red lines or callouts to indicate changes, edits, or revisions to a document. The term was inspired by the practice of using a red pen to mark printed documents. Redline comments are widely used in different scenarios, such as clearly showing recommended changes to authors, editors, and reviewers when editing a document. Propose changes and modifications in legal agreements or contracts Provide constructive criticism and suggestions on papers, presentations, etc. How to give W

WPS is a very widely used office software, including documents, forms and PPT, and supports multi-terminal synchronization. If the prompt "The source application for this object cannot be launched" appears when editing wps, how to solve it? This problem may occur because you are trying to open a link or file, but its source application no longer exists or has been deleted. Here are some fixes: 1. Reinstall WPS software: Try reinstalling WPSOffice to fix the problem and make sure you are using the latest version. 2. Manually change the default program: Try to change the default program to WPS. You can right-click the file you want to open, select "Open with", and then

In recent years, with the continuous development of network technology, our lives are inseparable from various digital tools and the Internet. When processing documents, especially in writing, we often use word documents. However, sometimes we may encounter a difficult problem, that is, the hyperlink in the word document cannot be opened. This issue will be discussed below. First of all, we need to make it clear that hyperlinks refer to links added in word documents to other documents, web pages, directories, bookmarks, etc. When we click on these links, I
