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);
RunAlgorith开发者_开发知识库m::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!
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.
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 call Invalidate
and let the view to draw itself.
Javier
精彩评论