- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有两个变量,m_GridSize 和 m_TimeDisplay,它们根据此处称为“world”的变量更新自身。现在,MFC 程序将显示“Grid size:”和“Time:”,但不会显示 double 值的实际值。我正在使用 Visual Studio Community 2013 制作 Win32 GUI 应用程序。
我在使用 CString 格式函数时遇到问题。
编辑以包含完整代码:
// smart_parking_guiDlg.cpp : implementation file
//
#include "stdafx.h"
#include "smart_parking_gui.h"
#include "smart_parking_guiDlg.h"
#include "afxdialogex.h"
#include "Cadd_Destination.h"
#include "Cadd_Lot.h"
#include "Cadd_Driver.h"
#include "Commands.h" // Used to handle commands
#include "Grid.h" // Contains the grid
#include <string>
#include <io.h>
#include <fcntl.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// Csmart_parking_guiDlg dialog
Csmart_parking_guiDlg::Csmart_parking_guiDlg(CWnd* pParent /*=NULL*/)
: CDialogEx(Csmart_parking_guiDlg::IDD, pParent)
, m_EchoSize(_T("Grid size: "))
, m_EchoTime(_T("Time: "))
, m_EchoStatus(_T("Open"))
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
this->world = new Grid(10, 5); // default grid
}
void Csmart_parking_guiDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Text(pDX, IDC_ST_GRIDSIZE, m_EchoSize);
DDX_Text(pDX, IDC_ST_TIME, m_EchoTime);
DDX_Text(pDX, IDC_ST_STATUS, m_EchoStatus);
}
BEGIN_MESSAGE_MAP(Csmart_parking_guiDlg, CDialogEx)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_B_OPEN_CONFIG, &Csmart_parking_guiDlg::OnBnClickedBOpenConfig)
ON_BN_CLICKED(IDC_B_SAVECONFIG, &Csmart_parking_guiDlg::OnBnClickedBSaveconfig)
ON_BN_CLICKED(IDC_B_NEXTEVENT, &Csmart_parking_guiDlg::OnBnClickedBNextevent)
ON_BN_CLICKED(IDC_B_NEWDEST, &Csmart_parking_guiDlg::OnBnClickedBNewdest)
ON_BN_CLICKED(IDC_B_NEWLOT, &Csmart_parking_guiDlg::OnBnClickedBNewlot)
ON_BN_CLICKED(IDC_B_NEWDRIVER, &Csmart_parking_guiDlg::OnBnClickedBNewdriver)
ON_BN_CLICKED(IDC_B_SIMEND, &Csmart_parking_guiDlg::OnBnClickedBSimend)
ON_BN_CLICKED(IDC_B_SHOWSTATUS, &Csmart_parking_guiDlg::OnBnClickedBShowstatus)
END_MESSAGE_MAP()
// Csmart_parking_guiDlg message handlers
BOOL Csmart_parking_guiDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE;
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void Csmart_parking_guiDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialogEx::OnPaint();
}
}
// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR Csmart_parking_guiDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void Csmart_parking_guiDlg::OnBnClickedBOpenConfig()
{
wchar_t szFilters[] = _T("Text Files (*.txt)|*.txt|All Files (*.*)|*.*||");
// Create an Open dialog
CFileDialog fileDlg(TRUE, _T("txt"), _T("*.txt"),
OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, szFilters, this); // Display the file dialog.
// When user clicks OK, fileDlg.DoModal() returns IDOK.
if (fileDlg.DoModal() == IDOK)
{
CString m_strPathname = fileDlg.GetPathName();
CT2CA converter(m_strPathname);
std::string fileToOpen(converter);
// TODO: Open Grid file
open_file(*world, fileToOpen);
//Change the window's title to the opened file's title.
CString fileName = fileDlg.GetFileTitle();
SetWindowText(fileName);
}
}
void Csmart_parking_guiDlg::OnBnClickedBSaveconfig()
{
// TODO: Add your control notification handler code here
// szFilters is a text string that includes two file name filters:
// "*.my" for "MyType Files" and "*.*' for "All Files."
TCHAR szFilters[] = _T("Text Files (*.txt)|*.txt|All Files (*.*)|*.*||");
// Create a Save dialog
CFileDialog fileDlg(FALSE, _T("txt"), _T("*.txt"),
OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, szFilters);
// Display the file dialog. When user clicks OK, fileDlg.DoModal()
// returns IDOK.
if (fileDlg.DoModal() == IDOK)
{
CString pathName = fileDlg.GetPathName();
CT2CA converter(pathName);
std::string fileToWrite(converter);
// Implement opening and reading file in here.
write_file(*world, fileToWrite);
//Change the window's title to the opened file's title.
CString fileName = fileDlg.GetFileTitle();
SetWindowText(fileName);
}
}
void Csmart_parking_guiDlg::OnBnClickedBNextevent()
{
// TODO: Add your control notification handler code here
run_simulation(*world);
m_GridSize = world->getGridSize(); // double
m_TimeDisplay = world->getTime(); // double
// THIS DOESN'T WORK
m_EchoSize.Format(_T("Grid size: %g"), m_GridSize);
m_EchoTime.Format(_T("Time: %g"), m_TimeDisplay);
UpdateData(FALSE);
GetDlgItem(IDC_ST_GRIDSIZE)->InvalidateRect(NULL);
GetDlgItem(IDC_ST_TIME)->InvalidateRect(NULL);
}
void Csmart_parking_guiDlg::OnBnClickedBSimend() // On clicking, simulation jumps to the very end.
{
jump_to_end(*world);
m_GridSize = world->getGridSize();
m_TimeDisplay = world->getTime();
// THIS DOESN'T WORK
m_EchoSize.Format(_T("Grid size: %g"), m_GridSize);
m_EchoTime.Format(_T("Time: %g"), m_TimeDisplay);
UpdateData(FALSE);
GetDlgItem(IDC_ST_GRIDSIZE)->InvalidateRect(NULL);
GetDlgItem(IDC_ST_TIME)->InvalidateRect(NULL);
}
void Csmart_parking_guiDlg::OnBnClickedBNewdest()
{
// TODO: Add your control notification handler code here
Cadd_Destination Dlg;
Dlg.DoModal();
}
void Csmart_parking_guiDlg::OnBnClickedBNewlot()
{
// TODO: Add your control notification handler code here
Cadd_Lot Dlg;
Dlg.DoModal();
}
void Csmart_parking_guiDlg::OnBnClickedBNewdriver() // Opens a dialog to input a new driver. Only works with added destination.
{
if (world->getDestinationCount() != 0) {
Cadd_Driver Dlg;
Dlg.DoModal();
}
}
void Csmart_parking_guiDlg::OnBnClickedBShowstatus()
{
// TODO: Add your control notification handler code here
}
有没有办法解决这个问题,让 double 的值显示在 GUI 中?我已经尝试过此处显示的答案
但数字根本不显示。没有语法错误。如果我使用 %d 并将值替换为整数,则该代码有效,但不适用于 double 值,这是我在初始类(class)中使用的。
最佳答案
我自己解决了这个问题。
事实证明,这个问题更多地与我的 GUI 有关。事实证明,静态文本在 Visual Studio 对话框编辑器(通过资源 View 访问)中设置了固定长度,并且长度太短而无法容纳包含“Grid size:”的字符串和实际数字。 (第一个静态文本最初只能为他们两个保留一个数字)我通过在我的 GUI 中扩展静态文本的宽度来修复它,并解决了这个问题。
关于c++ - MFC C字符串 : double not displaying,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31249632/
除了 Display.getOrientation() 已弃用之外,Display.getRotation() 和 Display.getOrientation() 之间还有什么区别? 是否都返回等于
我的问题 这些方法中有哪一种是专业网页设计师所偏爱的吗? Web 浏览器在绘制网站时是否首选这些方法中的任何一种? 这只是个人喜好吗? 我还缺少其他技巧吗? 注意:以上问题是关于设计多列布局 floa
我的问题 专业网页设计师是否喜欢这些方法? 网页浏览器在绘制网站时是否首选这些方法? 这只是个人喜好吗? 我还缺少其他技术吗? 注意:以上问题与设计多列布局有关 float :左; http://js
我有一些代码返回 MyTrait 类型的特征对象,这样它就可以返回几个不同结构之一。我想为 trait 对象实现 Display trait,这样我就可以打印对象,并将详细信息委托(delegate)
package polymorphism; /* * @author Rahul Tripathi */ public class OverLoadingTest { /** *
我希望 Display.timerExec(int,Runnable)与 Display.asyncExec(Runnable) 大致相同但有指定的延迟。然而,似乎Display.timerExec只
就像标题所暗示的,有什么区别吗?我当时使用的是pygame.display.flip,我在互联网上看到的是,他们使用pygame.display.update而不是使用flip。哪一个更快? 最佳答案
Sample.this.display() 和 this.display() 哪个更好? class Sample{ void display(){ System.out.println("d
当图像的 CSS 属性“显示”已被任何其他 JS 脚本/函数更改时,我想运行一些 JS 代码。有什么方法可以监视该更改并设置回调函数吗? $(this).bind.('propertychange',
在浏览 Google 字体时我注意到第一个过滤器包含这些类别: Serif Sans 衬线 展示 手写 我知道什么是 (Sans)Serif 和 Handwriting 类别(这很明显)但是显示类别过
我想知道是否可以在列标记内渲染自定义 html,这是显示表标记的一部分。 例如,我希望我的专栏里面有一些下拉列表? 使用纯 html,如下所示: ... Volvo Saab Me
display.newImage() 和 display.newImageRect() 有什么区别? 哪个更好用? 最佳答案 display.newImage() 的文档具体提到: NOTE: dis
我正在使用纯 JS 和 flexbox 为我的元素创建网格。 元素的某些部分在页面加载时被显示隐藏:无,但单击按钮后它应该在不显示和阻止之间切换。 可悲的是,这完全破坏了 display: flex
我目前正在参加 HTML/CSS 类(class),这本书推荐我使用.desktop {display:none;}/.mobile {display:inline;} 以及div class="de
这个问题在这里已经有了答案: Css transition from display none to display block, navigation with subnav [duplicat
我理解 style="display: none" 隐藏一个 HTML 元素,而 style="display: block" 显示一个 block 级 HTML 元素。 我看到一些使用 style=
设置控件的样式 display: none 和 display: block 有什么区别? 最佳答案 display 属性定义了某个 HTML 元素应该如何显示。 Display block 和 no
这个问题已经有答案了: Javascript AND operator within assignment (7 个回答) 已关闭 4 年前。 假设我只想在 this.state.display 为
我不确定如何命名这个问题,因为我是 Rust 新手,所以请随意提出修改建议。 我有两个结构。一个是 Job 结构,其中包含一些数字,例如作业需要多长时间等。另一个是 JobSequence,其中包含
我不确定如何命名这个问题,因为我是 Rust 新手,所以请随意提出修改建议。 我有两个结构。一个是 Job 结构,其中包含一些数字,例如作业需要多长时间等。另一个是 JobSequence,其中包含
我是一名优秀的程序员,十分优秀!