- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在尝试创建一个 MFC 程序,该程序显示一种涉及对象的动画,对象的位置以图形方式转换为小板上的矩形、椭圆等位置。这是一个 32 位程序。
我的想法是,当用户按下按钮时,他会以特定的时间速率看到模拟。但是,我的代码使其仅在有人不断点击按钮以推进模拟时运行。
当我用另一个按钮做同样的事情时,图形动画通常很流畅。但是,我的窗口屏幕上最终出现了一个 (Not Responding) 提示(在非特定时间),导致图形卡住,直到模拟完成。
如何防止图形窗口卡住?
相关代码:
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();
}
DrawGrid();
}
void Csmart_parking_guiDlg::DrawGrid() {
CRect gridBase;
gridDrawSurface->GetWindowRect(&gridBase);
this->ScreenToClient(&gridBase);
CPoint bottomRight = gridBase.TopLeft();
int rectSize = 400;
bottomRight += CPoint(rectSize, rectSize);
gridBase.BottomRight() = bottomRight;
gridBase.NormalizeRect();
gridDraw->Rectangle(gridBase);
int baseRectWidth = gridBase.Width();
int baseRectHeight = gridBase.Height();
double proportion = (baseRectWidth / world->getGridSize());
// Draw destinations. Set boolean to check if all are drawn yet
CBrush brushDest(RGB(165, 42, 42));
gridBrush = gridDraw->SelectObject(&brushDest);
CPen penBlack;
penBlack.CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
gridPen = gridDraw->SelectObject(&penBlack);
vector <Location> destLoc = world->getDestLocations();
int xCenter;
int yCenter;
for (size_t ii = 0; ii < destLoc.size(); ii++) { // draw brown circle
xCenter = (int)round(gridBase.TopLeft().x + destLoc[ii].x*proportion);
yCenter = (int)round(gridBase.TopLeft().y + destLoc[ii].y*proportion);
gridDraw->Rectangle(xCenter - 4, yCenter-4, xCenter+4, yCenter+4);
}
gridDraw->SelectObject(gridBrush);
destDrawn = true;
// Draw lots.
CBrush brushLot(RGB(35, 62, 148));
gridDraw->SetTextColor(RGB(35, 62, 148));
// gridDraw->SetBkMode(TRANSPARENT);
gridBrush = gridDraw->SelectObject(&brushLot);
vector<Location> lotLoc = world->getLotLocations();
vector<int> lotSpots;
vector<Lot *> allLots = world->getAllLots();
for (size_t ii = 0; ii < allLots.size(); ii++) {
lotSpots.push_back(allLots[ii]->getOpenSpots());
}
for (size_t ii = 0; ii < lotLoc.size(); ii++) { // draw blue circle and number
xCenter = (int)round(gridBase.TopLeft().x + lotLoc[ii].x*proportion);
yCenter = (int)round(gridBase.TopLeft().y + lotLoc[ii].y*proportion);
gridDraw->Ellipse(xCenter-3, yCenter-3, xCenter+3, yCenter+3);
CString echoNum;
echoNum.Format(_T("%d"), lotSpots[ii]);
gridDraw->TextOutW(xCenter + 4, yCenter + 1, echoNum);
}
lotDrawn = true;
gridDraw->SelectObject(gridBrush);
gridDraw->SelectObject(gridPen);
// Draw drivers
vector<Location> driverLoc = world->getDriverLocations(); // get all drivers currently visible on screen
for (size_t ii = 0; ii < driverLoc.size(); ii++) { // draw red dot
xCenter = (int)round(gridBase.TopLeft().x + driverLoc[ii].x*proportion);
yCenter = (int)round(gridBase.TopLeft().y + driverLoc[ii].y*proportion);
gridDraw->Rectangle(xCenter - 1, yCenter - 1, xCenter + 1, yCenter + 1);
}
}
void Csmart_parking_guiDlg::OnBnClickedBSimend() // On clicking, simulation jumps to the very end.
{
while (!world->simulationOver[world->getCurrentIteration()]) {
run_simulation(*world);
m_TimeDisplay = world->getTime(); // double
m_EchoTime.Format(_T("Time: %g"), m_TimeDisplay);
if (!world->simulationOver[world->getCurrentIteration()]) oss << world->getCurrentEvent();
CString c_status(oss.str().c_str());
m_EchoStatus = c_status;
UpdateData(FALSE);
OnPaint();
GetDlgItem(IDC_ST_STATUS)->RedrawWindow();
pEdit->LineScroll(pEdit->GetLineCount());
// theApp.PumpMessage(); // this works but it makes it way too slow
// Sleep(50); // program stops responding at times with a sleep message
}
}
最佳答案
您可以(并且应该)摆脱 while 循环,只需调用 SetTimer 即可开始模拟。然后在每次调用 WM_TIMER 消息处理程序时执行模拟的一个步骤。你永远不应该自己调用 OnPaint。您的计时器可以调用 Invalidate 使 Windows 调用 OnPaint。
关于c++ - MFC 应用程序 : animating graphics cause program to not respond,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31462079/
我想知道如何在 OCaml 中设置文本大小。我尝试了 Graphics.set_text_size,我猜这应该可以解决问题。 但是无论我输入 set_text_size 200 还是 set_text
我想使用mathematica 为我正在写的书绘制图表。我想在mathematica中画一个图,将其保存为图片,然后将其导入到quarkxpress中,最后将其导出为pdf。 我的问题是最好使用哪种格
在顶层加载 Graphics 模块时,我收到一条错误消息“找不到 graphics.cma”。 我使用的是 OS X,而且我很确定我已经正确安装了 OCaml,因为我已经使用了大约一个月了。所以看起来
我知道 DDS 文件的存在,允许在 as/400 上对显示图形进行编程,但是还有其他方法吗? 具体来说,我想要做的是直接操作终端缓冲区,以便能够显示除文本之外的任何其他内容。例如,终端如下所示: 假设
Graphics.Save 与 Graphics.BeginContainer 有何不同? 最佳答案 看看here : The documentation does not differentiate
由于 Gdiplus::Graphics::DrawGraphics(Graphics*, x, y) 不存在,执行此类操作的最佳方法是什么? 例如,创建一个 Graphics 对象,使用各种 Dra
你能看出这有什么问题吗: (define (box d x1 y1 x2 y2) ( (graphics-draw-line d x1 y
我想编写一个 2D 游戏引擎。我遇到的问题(我不使用opengl之类的东西,所以我用cpu渲染)是,我通过graphics.drawImage()只得到7fps;您有任何加快速度的建议或其他替代方案吗
我在某些代码中发现了渲染错误,并找到了解决方法,但我想知道为什么我会得到不同的行为。在旧代码中,背景(有时)会呈现为白色,尽管在调试时 getBackground() 会返回正确的颜色。 旧代码: @
有谁知道是否有办法(也许通过外部API)将图形绘图/转换为多个图形?这个想法是同时保存 PNG 和 PDF(使用 Java IText 库)。 最佳答案 您可以将 Graphics 对象写入(java
我试图了解如何在英特尔芯片组上以 x86 保护模式绘制简单图形。我已经(有点)知道如何使用 VGA 接口(interface)来做到这一点,并且我正在尝试了解如何使用 G35 Express 来做到这
在我的应用程序中,我生成了一个条形码图像,该图像是根据用户使用 OpenFileDialog 上传的文件中的数据生成的。我的目标是允许用户在屏幕上查看条形码数据和图像本身,打印并使他们能够将两者保存为
我是 Java 新手,我只是想得到一些简单的东西,可能类似于 Zelle's graphics对于Python。 最佳答案 Java 类 Graphics和 Graphics2D应该包含 Zelle
如何将 FMX.Graphics.TBitmap 转换为 VCL.Graphics.TBitmap 或 Vcl.Imaging.PngImage.TPngImage? 我的项目中有FMX表单和VCL表
我需要找到用于间距目的的字体大小,发现这很有帮助:https://docs.oracle.com/javase/tutorial/2d/text/measuringtext.html 但是,我不确定如
我有一点奇怪的错误是由一个看似简单的问题引起的。 在我的源代码中,我尝试使用 QQuickPaintedItem 来呈现 QWidget 派生类 (QPushButton) 的整体外观,然后将其绘制到
我正在尝试通过具有以下规范的设备来解决 Android 应用程序崩溃的问题: Device PAP3400DUO 1 Manufacturer — Android version Android 4.
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 9 年前。 Improve this ques
我有这行代码: mBgTransition = (TransitionDrawable) mSwitchBg.getBackground(); 背景曾经是一个常规的可绘制对象, 但现在是 9 个补丁
当我的应用程序在启动时崩溃时尝试实现自适应图标时出现此错误。 我无法想象为什么会收到此错误,因为在下面错误日志中提到的文件(MainActivity 和 BaseActivity)中,我没有使用Ada
我是一名优秀的程序员,十分优秀!