I have a tool,something like Edit Tool in ArcMap,when I double click on mouse,and it selects a feature (polyline for example) and draw a sketch on it too,but if I change zoom,the sketch disapears because I draw sketch on the scrren.I know if I can draw sketch on into selection cache (bitmap) it will stay till selection changes,so it doesn't disapear with changing zoom. here are the steps i pass to draw the sketch with current situation:

  1. I take cache count into cachecount variable using screen display object
  2. I take a handle to device countext for cacheIndex=cachecount-1
  3. start drawing using 2 parameters in steps 1 and 2 4.vdraw polyline using screen display DrayPolyline
  4. FinishDrawing



//Get handle to memory device context

HDC HandleDC;

short cacheCount;


short cacheIdx=cacheCount-1;


return hr;

//Draw feature here



Because ArcMap has at least 3 caches,1st for feature,2nd for annotation and graphics and 3rd for selection,i supposed the last feature index must be for selection cach,if I choose another index less than this,it doesn't even draw any thing.I checked this number and it always returns 2 for cachecount,I think because I don't have any graphics or annotation on map,it returns 2(at least I wish it is a true consumption).

but unfortunately it draws polyline on the screen because drawn polyline disapears at the first refresh of map. Is there something wrong with these procedure? May you tell me how I can draw a sketch on the selected feature just like Edit Tool in ArcMap?


Cache indexes are generally determined by calling IActiveView.ScreenCacheID.

However, I believe the Edit tool (and most similar tools) does this differently, and that is to hook to the IActiveViewEvents.AfterDraw event. This will allow you to draw your selection (or sketch or whatever you want) just after the feature selection (or any other) drawing phase finishes.

  • ok,thank you very much petr,let me try after draw event and see is the cache index is right index or not,using ScreenCacheID method. – Reza Feb 4 '11 at 10:00
  • That was right,it works well now,Thank you very much petr.The key idea is using afterdraw event,and also using screencacheid method takes the right index for selection cache – Reza Feb 4 '11 at 10:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.