Not to be too negative but there are IMHO way too many cheerleaders in this thread. Too many people are focusing on the gun. The gun would have never come into play if the OP had better situational awareness. Let me illustrate.
First you only need to have your window down at Sonic to order your food and receive your food. There is no reason to leave the window down if security is your #1 concern.
Second if you intend to leave your window down while enjoying your Sonjc choose a spot with good sight lines. Park where someone cannot sneak up on you from a blind spot. Park next to other cars. A robber is less likely to pick the middle car in row of 3 or more. If you cannot do that roll up the window or eat somewhere else.
Third Watch your six etc... And if you see anyone moving toward your vehicle roll up the window. You should have been aware that someone was coming toward your car much earlier than you indicate that you did. The guy walked you did not say he ran. Even at a brisk pace you should have seen him coming.
Having better situational awareness would have at least put a car window between you and your would be perp. Most likely, if he even was a perp not a pan handler, you would not even have had the encounter if your window was up. If one is looking to rob someone in a group you typically choose the easiest target. If I am going to ask someone for money I am going to ask the one with the open window first. The biggest barrier to my success is already down.
Also once you identified the "potential" treat you went for your gun but did not roll up the window? I have to ask why. I also ask why you did not do both? If there was a lapse in my situational awareness that put me in your position I would have dropped my juicy burger in my lap one hand would be rolling up the window the other would be on the gun in my holster but the closed window would give me physical and legal protection to draw if attacked. You had neither in your encounter but we're ready to draw and take a life. I have been carrying for over a decade and have never once put my hand on my carry gun with the intent to draw being imminent. I do everything I can to avoid that moment because I understand all the horrible things that can and will follow if that gun ever clears leather.
I am not trying to be rude. I am sure some here will consider this post that way but I personally believe that the best way to avoid having to use a gun to defend yourself is to not put your self in a situation where you have to defend yourself with a gun. By making smart situational choices like where to sit, where to park, knowing where the emergency exits are, walking in groups, well lit streets, etc... are all defensive weapons you should be deploying everyday instead of your hand on your pistol after being surprised by a man walking toward your open car window. IMHO Yes there will be that 1 in a million+ situation where you did everything right but still had to draw a gun and or shoot someone but you can greatly reduce those long odds by having better situational awareness and maybe not eating at a drive in. LOL