For many windows you can do the following to see what code is executed when pressing buttons. Rightclick somewhere in the respective GUI and choose 'View' -> 'Explore Structure'. This will open the tree view of that window, where you should be able to find the relevant part of the GUI and see its attached code.


Many of the functions there probably won't be necessary when you add a component via code (like the undo management, setting the object as selected and repainting the window). The relevant parts here are line 3, where the drawsurrogate node of the object is referenced and line 11 where an object is created inside of it.