如何在调试模式下运行时显示主视图 - MFC
我有一个 MFC 项目,当前正在调试模式下运行。
我有这个“运行”按钮,当我单击它时,我的算法就会运行,最终会绘制出东西。
过去,点击运行后,我一直看到主视图。 过了一会儿(不确定是什么改变了它),单击 while 后视图转到后面(Visual Studio 后面)。我能够通过在“运行”开始时使用 Show_Window(SW_SHOW) 来修复它。
现在似乎没有任何效果 - 我也尝试过 OnDraw,并且
`SetWindowPos(&CWnd::wndTop,0, 0, 0, 0,SWP_NOMOVE | SWP_NOSIZE);`
在单击“运行”后我总是将 Visual Studio 置于我的视图之上! (即使没有断点,异常...)
这是我的run函数:
void CMaBakerView::maBakerRun(){
SetWindowPos(&CWnd::wndTop,0, 0, 0, 0,SWP_NOMOVE | SWP_NOSIZE);
CRect ClientRect;
GetClientRect(ClientRect);
CDC* pDC = GetDC();
OnDraw(pDC);
int xMax = ClientRect.right;
int yMax = ClientRect.bottom;
//fillGUIData();
try
{
ShowWindow(SW_SHOW);
RunAlgorithm::run(xMax, yMax);//Here only pure logic is run, i can post the code of it if anyone thinks its relevant
//Other nonimportant code
} catch...
我注意到注释掉RunAlgorithm::run时,不会出现问题,但这可能是因为它是唯一的在函数中实际上需要时间的东西...... 有人可以给我一个方向吗?
我使用的是 Visual Studio 2008,专业版
谢谢!
I have an MFC project that I'm currently running in debug mode.
I have this "run" button, that when i click it my algorithm runs, and eventually things get drawn.
In the past, after clicking run, i kept on seeing the main view.
After a while (not sure what changed it) the view went to the back (behind Visual Studio) after clicking while. I was able to fix it by using Show_Window(SW_SHOW) at the very beginning of "run".
Now nothing seems to be working- I have also tried OnDraw and
`SetWindowPos(&CWnd::wndTop,0, 0, 0, 0,SWP_NOMOVE | SWP_NOSIZE);`
I always get Visual Studio on top of my view after clicking run!!! (even if there are no breakpoints, exceptions...)
Here is my run function:
void CMaBakerView::maBakerRun(){
SetWindowPos(&CWnd::wndTop,0, 0, 0, 0,SWP_NOMOVE | SWP_NOSIZE);
CRect ClientRect;
GetClientRect(ClientRect);
CDC* pDC = GetDC();
OnDraw(pDC);
int xMax = ClientRect.right;
int yMax = ClientRect.bottom;
//fillGUIData();
try
{
ShowWindow(SW_SHOW);
RunAlgorithm::run(xMax, yMax);//Here only pure logic is run, i can post the code of it if anyone thinks its relevant
//Other nonimportant code
} catch...
I have noticed that when commenting out RunAlgorithm::run, the problem does not occur, but it may be due to the fact that it is the only thing that actually takes time in the function...
Can anyone please give me a direction?
I am using Visual Studio 2008, professional edition
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来像是 Visual Studio 或插件的问题,而不是您的程序的问题。
检查一下:调试时 Visual Studio 始终位于最前面
如果没有不起作用,那么您可以尝试使用 SetForegroundWindow 函数。
Sounds like a problem with Visual Studio or an addin, not with your program.
Check this out: Visual Studio always on top when debugging
If it doesn't work, then you can try forcing your window to be the foreground window with the SetForegroundWindow function.
RunAlgorithm::run
需要多长时间?我需要更多信息,但您似乎正在阻塞 UI 线程。如果这是一个很长的操作,您应该创建一个工作线程。如果问题是即使完成 RunAlgorithm::run 后您的视图也没有显示,您可以尝试移动
ShowWindow(SW_SHOW)
;经过代码中的长时间操作。顺便说一句,我认为从这里调用
OnDraw
没有任何意义。如果您希望在长时间操作后绘制视图,您应该调用Invalidate
并让视图自行绘制。哈维尔
How long does
RunAlgorithm::run
takes? I'd need more information but it seems you're blocking the UI thread. If it's a long operation you should create a working thread.If the problem is your view doesn't show up even after finishing RunAlgorithm::run you could try moving the
ShowWindow(SW_SHOW)
; after the long operation in the code.By the way, I don't think calling
OnDraw
from here makes any sense. If you want your view to be drawn after the long operation you should callInvalidate
and let the view to draw itself.Javier