Can you undo after closing and reopening a file?
Yes. Turn on saved history in Paint by Zaweba's Preferences and undo carries on after you reopen a file; snapshots are saved in the .ptx anyway.

Undo can survive closing a file. In Paint by Zaweba, turn on saved history in Preferences > History, and the undo steps are kept with the file, so after you close and reopen it you can still step back through your edits. It's off by default. Snapshots, which capture the whole document at a moment you choose, are saved in the .ptx file whether or not saved history is on.
Most editors throw the undo list away the moment you close a document. That's usually fine, until you realise the next morning that a change you made yesterday has spoiled the picture and there's no way back but to start again.
Turning on saved history
Open Preferences and go to the History section. Turn on saved history. From then on, when you save a .ptx file, its undo steps go with it. Reopen the file later and the History panel shows the earlier steps, ready to undo.
It only works with Paint's own .ptx format, because that's the format that can hold the extra information. A JPEG or PNG is just the final picture.
Saved history can make files bigger, since each step has to be stored. For a big retouching job with hundreds of steps, that can be a lot. That's why it's an option rather than always on.
Snapshots as a lighter alternative
A snapshot is a copy of the whole document at one moment. Click the camera button in the History panel to take one, and click it later to go back. Snapshots are saved in the .ptx by default, so they survive closing the file. Taking one before each big stage of an edit, such as before retouching, before colour grading and before sharpening, gives you a few safe return points without storing every step.
Other history tools worth knowing
Non-Linear History keeps later steps as a branch when you go back and do something different, instead of throwing them away. That lets you try two directions and pick the better one. Toggle Last State (Ctrl+Alt+Z) flips between the current state and the previous one, which is a quick before and after.
Preferences also set the step limit and a memory cap. A scratch disk moves older undo steps out of memory and onto the drive, so a long session on a big file doesn't run out of room.
The best protection is editing that doesn't destroy
Undo is a safety net. A better habit is to work so you rarely need it. Use adjustment layers instead of changing pixels directly, masks instead of erasing, and Layer Art effects that stay live. Then the decision you regret tomorrow is a slider you can move, not a step you have to undo.
Duplicate a layer before painting on it for big changes, and keep the original hidden underneath.
If something went wrong in a crash
Saved history is about files you closed on purpose. If Paint closed unexpectedly, auto-recovery is what helps: changed documents are written to a Recovery folder every few minutes and Paint offers to reopen them.
Paint by Zaweba is free software for Windows that works offline, and all of this history is kept on your own computer.