- LONG nDepth;
-
- hpsScreen = ::WinGetScreenPS(HWND_DESKTOP);
- hdcScreen = ::GpiQueryDevice(hpsScreen);
- ::DevQueryCaps(hdcScreen, CAPS_COLOR_PLANES, 1L, &lPlanes);
- ::DevQueryCaps(hdcScreen, CAPS_COLOR_BITCOUNT, 1L, &lBitsPerPixel);
-
- nDepth = (int)(lPlanes * lBitsPerPixel);
- DevCloseDC(hdcScreen);
+ static LONG nDepth = 0;
+
+ // The screen colordepth ain't gonna change. No reason to query
+ // it over and over!
+ if (!nDepth) {
+ hpsScreen = ::WinGetScreenPS(HWND_DESKTOP);
+ hdcScreen = ::GpiQueryDevice(hpsScreen);
+ ::DevQueryCaps(hdcScreen, CAPS_COLOR_PLANES, 1L, &lPlanes);
+ ::DevQueryCaps(hdcScreen, CAPS_COLOR_BITCOUNT, 1L, &lBitsPerPixel);
+
+ nDepth = (int)(lPlanes * lBitsPerPixel);
+ ::DevCloseDC(hdcScreen);
+ ::WinReleasePS(hpsScreen);
+ }