I have a Dell G5 5587 with an NVIDIA and Intel video cards. It have an HDMI port where I plugged an external monitor.
Now the trick is, that the HDMI port seems to be shorcircuited to the NVIDIA card instead of passing through the Intel one, so when I close the monitor lid, the Intel card thinks that the last monitor attached to it have disconnected (which is weird as it should just disable it, and not disconnect!) and just disables itself nearly totally. The desktop then jumps totally from a dual monitor setup to a single one, and only NVIDIA manages the only monitor "left".
When the lid is opened, it reenables back itself and reconnects back the monitor. It seems like the system receives a "monitor connected" event, and it automatically reenables it.
I haven't found a way to stop this disconnect/reconnect event on lid open/close, as it seems to be (sadly) managed by the Intel Graphics driver itself. Why do I think so - because when replacing the Intel driver by a Generic Videoadapter Driver, this behaviour stops (although the integrated monitor doesn't switch off at all when the lid is closed, which isn't good too!).
This may be related to the DisplayPort specification (which was specifically patched for the NVIDIA cards, but wasn't for Intel ones) which indeed states that on the monitor disable it should be disconnected from the system.
Now, back to your exact problem, which is easier to workaround than mine.
Setting the monitors to "extend desktop" to both monitors, and then setting the external one as the "primary monitor" seems to persist the desktop on lid open/close on the external monitor. You still receive the "monitor connected" event, but because the internal monitor isn't treated as a primary one, it doesn't change your desktop, windows, etc, just automatically extends to it, and we don't really care about that, do we? =)
But in the unlucky case that it doesn't help, you have a similar 2 graphics card setup with the external monitor being hardwired to the NVIDIA card and you doesn't care about the Intel card at all, you can either switch the Intel Graphics off at all (this will disable the internal monitor as well) or replace its driver with a "Basic Videodriver" (with all the drawbacks as described above), and with this setup them as you see fit.