1. While he extended his hand, he smiled brightly.

2. While he was extending his hand, he was smiling brightly.
(Are both okay?)

3. When he extended his hand, he smiled brightly.
4. When he was extending his hand, he was smiling brightly.
(Can we use 'when' instead of 'while'? What is the difference between them?)

All four sentences are fine. Look up he words "when" and "while". In the contexts you have used them, they mean the same, but look them up.

https://www.merriam-webster.com/dictionary/dictionary

1. "While he extended his hand, he smiled brightly." and 2. "While he was extending his hand, he was smiling brightly." are both grammatically correct and convey a similar meaning, with a slight difference in emphasis. In both sentences, the action of extending the hand and smiling brightly are happening simultaneously.

3. "When he extended his hand, he smiled brightly." and 4. "When he was extending his hand, he was smiling brightly." are also both grammatically correct and convey a similar meaning. The difference here lies in the conjunction used. "When" suggests a cause-and-effect relationship, implying that the action of extending his hand directly triggers the action of smiling brightly.

On the other hand, "While" suggests a simultaneous occurrence of two actions happening at the same time. It implies that both actions are happening concurrently rather than one causing the other.

Ultimately, the choice between "when" and "while" depends on the specific context and the intended meaning the writer wants to convey.