The scratch window

Raymond Chen

Sometimes you need a quick and dirty window and you don’t want to go through all the hassle of registering a class for it. For example, you might need a window to do a brief snippet of DDE, or you just need a window to own a message box.

To save yourself the trouble of registering a class for every single weenie thing you might need a window for, you can get lazy and register a single “scratch window” class and simply subclass it on an as-needed basis.

ATOM RegisterScratchWindowClass(void)
  WNDCLASS wc = {
        0,                              // style
        DefWindowProc,                  // lpfnWndProc
        0,                              // cbClsExtra
        0,                              // cbWndExtra
        g_hinst,                        // this file's HINSTANCE
        NULL,                           // hIcon
        LoadCursor(NULL, IDC_ARROW),    // hCursor
        (HBRUSH)(COLOR_BTNFACE+1),      // hbrBackground
        NULL,                           // lpszMenuName
        TEXT("Scratch"),                // lpszClassName
  return RegisterClass(&wc);
CreateScratchWindow(HWND hwndParent, WNDPROC wp)
  HWND hwnd;
  hwnd = CreateWindow(TEXT("Scratch"), NULL,
                      hwndParent ? WS_CHILD : WS_OVERLAPPED,
	              0, 0, 0, 0, hwndParent, NULL, NULL, NULL);
  if (hwnd) {
    SubclassWindow(hwnd, wp);
  return hwnd;

Now if you need a quick one-off window, you can just create a scratch window instead of creating a custom window class just to handle that specific task.

We’ll see the scratch window in action soon.


Discussion is closed.

Feedback usabilla icon