Do you mind my opening the window?

He narrowly escaped being drowned.
He gave up smoking.
He admitted having stolen the money.
I could not avoid saying so.
I finished writing my composition.
Sam enjoyed swimming in the river.
He stopped smoking.
He suggested going on a picnic.
He postponed making a phone call to his mother.
He put off meeting his friends.
He practiced playing baseball regularly.
Did you consider going abroad someday?
I anticipated seeing him at his office.
He risked getting knocked out.
I can't resist tasting the cake.

(Are they all grammatical? All the verbs in the sentences take only the gerund as an object, right?)

All are correct, yes.

I'd change #2 slightly, though, to "He narrowly escaped drowning."