+ }
+}
+
+void
+deselect_palette (FRAME_PTR f, HDC hdc)
+{
+ if (f->output_data.w32->old_palette)
+ SelectPalette (hdc, f->output_data.w32->old_palette, FALSE);
+}
+
+/* Get a DC for frame and select palette for drawing; force an update of
+ all frames if palette's mapping changes. */
+HDC
+get_frame_dc (FRAME_PTR f)
+{
+ HDC hdc;
+
+ if (f->output_method != output_w32)
+ abort ();
+
+ enter_crit ();
+
+ hdc = GetDC (f->output_data.w32->window_desc);
+
+ /* If this gets called during startup before the frame is valid,
+ there is a chance of corrupting random data or crashing. */
+ if (hdc)
+ select_palette (f, hdc);
+
+ return hdc;
+}
+
+int
+release_frame_dc (FRAME_PTR f, HDC hdc)
+{
+ int ret;
+
+ deselect_palette (f, hdc);
+ ret = ReleaseDC (f->output_data.w32->window_desc, hdc);
+
+ leave_crit ();
+
+ return ret;