I would say that locking the door behind you might or might not be a smart and effective thing to do, depending on the circumstances of being ordered out of the car. Sometimes if it is cold or raining or something, the cop will order you out and have you sit in his car while he checks your papers. In this case, it would be fine to lock your car... it would be more of a precaution than anything.
However, I have been pulled over several times with guns in plain view in my car, which makes some cops jumpy. In these situations, the cop ordered me out of the car very sternly with his hand on his gun, and told me to keep my hands where he could see them. As soon as I was out, he would handcuff me, take me to the back of the car, and search me. He would usually then seize the gun without permission, search it to find the s/n, and radio it in to dispatch.
In this situation, if you tried to roll up your window and lock your doors as you were getting out, the cop would probably order you to stop. When a cop is this jumpy and has his hand on his gun, it might not be the smartest thing to do things other than what he is telling you to do, or to disobey any of his orders. But even if you did lock the car, the next thing he is going to do is to handcuff you and pat you down. If he is already bound and determined to search your car without his permission, his next move would just be to take your keys out of your pocket and unlock it himself. At this point, you resist him at your own risk. In this situation, it seems like locking the car would not be likely to prevent a search from taking place, and would only serve to enrage the cop, who is probably already pumping a lot of adrenaline.
Also, locking the car really has no legal significance... it just puts up a practical barrier that might make it so much of a PITA to execute a search that the cop doesn't do it. It also might make a cop think better of executing an illegal search. But the Supreme Court cases on the motor vehicle exigency and the Terry line of cases do not make any distinction about whether the vehicle is locked or not. If the cops have a legal justification to search the car, they can do so whether it is locked or not. If you refuse to unlock it, they can gain entry with whatever means are available to them.
Incidentally, searches based on the mere presence of a weapon are unconstitutional. In a state where the ownership and transportation of weapons is perfectly legal, the presence of a weapon does not constitute reasonable suspicion or probable cause of a crime being committed. Also, to conduct a search/seizure under the Terry line of cases, the cop must have reasonable suspicion, based on specific and articulable facts, that the suspect is both ARMED and DANGEROUS. Obviously the "armed" part is met, since you have a weapon sitting there within your immediate reach, but the "dangerous" part requires a lot more than just an average joe on a traffic stop. The cop would need something else, such as the fact that you are a known gang member, or if you look like you are casing a joint for a robbery, or match the description of a fugitive, or if you just tried to elude the cop, or if you were acting very irately.
Apparently it is a common practice for cops to seize and search guns without the owner's permission on traffic stops though. I don't know if they are teaching them that this is OK in police academy or what, but it seems like some lawsuits are in order to get this practice stopped. I think next time a cop seizes my property and searches it in such a manner, I will file a lawsuit. I am a lawyer, so who better?