Click here to Skip to main content
15,881,769 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on a win32 based application. When Iclick on a button, the command prompt is opened using WinExec, but when I move the command window than I feel that drawing is not done on my application.

What I do is:
case WM_ERASEBKGND:
        InvalidateRect(hwnd,NULL,TRUE);
        break;

It is working fine at my end but when I test it on Windows CE machine than the problem remains the same.

FYI this application works as a shell there.
Instead of using WinExec i used CreateProcess
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
TCHAR  wchCmdPath[MAX_PATH];
memset(wchCmdPath,_T('\0'),MAX_PATH);
GetSystemDirectory(wchCmdPath,MAX_PATH);
wcscat(wchCmdPath,_T("\\cmd.exe"));
// Start the child process.
 if( !CreateProcess( NULL,   // No module name (use command line)
     wchCmdPath,        // Command line
     NULL,           // Process handle not inheritable
     NULL,           // Thread handle not inheritable
     FALSE,          // Set handle inheritance to FALSE
     0,              // No creation flags
     NULL,           // Use parent's environment block
     NULL,           // Use parent's starting directory
     &si,            // Pointer to STARTUPINFO structure
     &pi )           // Pointer to PROCESS_INFORMATION structure
 )
 {
    return;
 }
 CloseHandle( pi.hProcess );
 CloseHandle( pi.hThread );



Thanks in advance.

Hi Richard,
Thanks for ur reply.
All drawing is done in WM_PAINT. Application have 6 buttons when click on buttons image is displayed on Picture control. Picture control is dynamically created.
If picture is large than scrolling is enabled.
on WM_PAINT all painting is done.
For button there is a class that load the image and paint the button.
EnglishBtn.LoadFromRec(IDB_BITMAP_SR);// Image in button is loaded from resource
EnglishBtn.Paint();// Paint button.
I write the code of InvalidateRect when
1) Button is clicked and image is displayed.
2) User scroll the picture.
Everything working fine when i click on button, scroll the image etc. But when i execute the command prompt and move quickly than that portion displayed gray.
Now please tell me where i am wrong :(
Thanks again. - Shilpi Boosar 7 hrs ago
Posted
Updated 16-Dec-10 2:15am
v4
Comments
[no name] 15-Dec-10 2:58am    
I do not think you should use InvalidateRect while processing WM_ERASEBKGND.
ShilpiP 15-Dec-10 4:57am    
Yae i know but i dont find another solution than i implement this code. Do you have any solution ??
Richard MacCutchan 16-Dec-10 8:18am    
I cannot see anything wrong with what you describe above, but it may be there is still something in your code that is not responding properly when the repaint needs to be done. You probably need to add some debug code to see exactly what happens when you start the command prompt.

You should use MFC or WTL framework (WTL is the nearest of raw Win32) , typically you will waste more time trying to solve this problem(s) than learning the ABC of any one of these.
 
Share this answer
 
Try to use CreateProcess(..) function
or call the WinExec(..) function in a secondary thread :)

(I would remove the WM_ERASEBKGND case... :) )
 
Share this answer
 
Comments
ShilpiP 15-Dec-10 4:59am    
I remove the code WM_ERASEBKGNG and use CreateProcess but problem remains the same. Please check the edited code.
Eugen Podsypalnikov 15-Dec-10 6:41am    
Please check the redrawing
under the overlapping by a normal cmd-window shown by ist own (not a child) process... :)

(I would remove also the last two lines 'CloseHandle(..)' :) )
You should only use InvalidateRect() when some of the content of your application has changed and you need to repaint it. When you get a WM_ERASEBKGND[^] the invalidate has already occurred, and you should take action as required. The actual repaint of your window should happen in response to a WM_PAINT; you may want to check you are responding correctly there.
 
Share this answer
 
Comments
ShilpiP 16-Dec-10 0:35am    
Hi Richard,
Thanks for ur reply.
All drawing is done in WM_PAINT. Application have 6 buttons when click on buttons image is displayed on Picture control. Picture control is dynamically created.
If picture is large than scrolling is enabled.
on WM_PAINT all painting is done.
For button there is a class that load the image and paint the button.
EnglishBtn.LoadFromRec(IDB_BITMAP_SR);// Image in button is loaded from resource
EnglishBtn.Paint();// Paint button.
I write the code of InvalidateRect when
1) Button is clicked and image is displayed.
2) User scroll the picture.
Everything working fine when i click on button, scroll the image etc. But when i execute the command prompt and move quickly than that portion displayed gray.
Now please tell me where i am wrong :(
Thanks again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900