'Which' can only be used when there is an element of restricted choice about the question. For example:
'Which milkshake would you like?' - when the speaker is referring to a menu board;
'Which coat are you going to wear?' - gesturing to a coat rack containing a finite number of coats;
'Which foot is hurting?'
'What' on the other hand is used when the possibilities are limitless.However, it is common practice to substitute 'what' in place of 'which', so you will often find that native-English speakers use 'what' far more often that the more formal sounding 'which'.