Friday, December 15, 2006


I'm sure you probably have faced a situation where you perform some heavy calculations inside AutoCAD with or without a dialog running. In these cases AutoCAD may look frozen and this may look strange to the user because it may think AutoCAD has really frozen and then the user may try to close it.

Even if you use a progress bar like AutoCAD status bar if you change the current window and get back to AutoCAD it may look frozen in black/white colors.

This occurs because the processor focus all its resources into your heavy loop and does not save enough time to both AutoCAD and your dialog process its own messages. These messages will affect several things like, for instance, the dialog graphics update.

The below function will let AutoCAD do this and you may call it from inside your loop (maybe a FOR or WHILE heavy statements). This way, on each interaction, this function will let AutoCAD process its messages.

void PumpAcadMessages()
// Get AutoCAD application
CWinApp* app = acedGetAcadWinApp();
// Get Main window
CWnd* wnd = app->GetMainWnd();
// dispatch incoming sent messages

MSG msg;
while (::PeekMessage (&msg, wnd->m_hWnd, 0, 0, PM_NOREMOVE))
// if can't pump, break
if (!app->PumpMessage())
LONG lIdle = 0;
// Now it's time to MFC do the work
while (app->OnIdle(lIdle++));

If you also would like to process your dialog messages you just need to change the first two lines and use your dialog's CWnd pointer instead of AutoCAD window's pointer.



Chuck Gabriel said...

If you just use NULL for the hWnd parameter in PeekMessage, it will retrieve messages for any window belonging to the current thread.

Fernando Malard said...

Thanks Chuck!

Anonymous said...

Is possible you can provide a .net version? I got the exactly same problem in my .net project.

Thank you and Merry Christmas

Kean said...


I just posted this info to
, but just in case:

I’d suggest trying the following in .NET…