I think this seems to work, not sure, check it. (There are several wparam due to the number of ways to minimize the game or similar actions, if someone takes the trouble they can leave only the escenial ones)
local memory = require("memory")
local CDialog, CDXUTDialog = 0, 0
-- Parts of the...