aboutsummaryrefslogblamecommitdiff
path: root/xkill/xkill.c
blob: 1ef052773c8b65319833428530be8fac987a1737 (plain) (tree)























































































                                                                              
/* xkill.c
 * Misnamed program which will kill whatever window is clicked on.
 */

#include <windows.h>

HWND me, target;

LRESULT CALLBACK
MainWindowProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
  POINT pt;
  WINDOWPLACEMENT wp;

  switch (uMsg)
    {
    case WM_CREATE:
      SetCapture (me);
      break;
    case WM_NCPAINT:
    case WM_NCACTIVATE: /* prevent painting of nonclient areas */
      return TRUE;
    case WM_LBUTTONDOWN:
      pt.x = LOWORD (lParam);
      pt.y = HIWORD (lParam);

      wp.length = sizeof (WINDOWPLACEMENT);
      wp.flags = 0;
      wp.showCmd = SW_MINIMIZE;
      SetWindowPlacement (me, &wp);

      target = WindowFromPoint (pt);
      if (target == NULL) target = GetDesktopWindow ();
      SendMessage (target, WM_CLOSE, 0, 0);
      SendMessage (target, WM_DESTROY, 0, 0);
      SendMessage (target, WM_QUIT, 0, 0);

      wp.length = sizeof (WINDOWPLACEMENT);
      wp.flags = 0;
      wp.showCmd = SW_MAXIMIZE;
      SetWindowPlacement (me, &wp);

      break;
    case WM_RBUTTONUP:
      PostQuitMessage (0);
      break;
    case WM_DESTROY:
      PostQuitMessage (0);
      break;
    default:
      return DefWindowProc (hWnd, uMsg, wParam, lParam);
    }

  return 0;
}

int WINAPI
WinMain (HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow)
{
  WNDCLASS wc;
  MSG msg;

  ZeroMemory (&wc, sizeof (WNDCLASS));
  wc.lpfnWndProc = MainWindowProc;
  wc.hInstance = hInst;
  wc.hIcon = LoadIcon (hInst, "xkill_icon");
  wc.hCursor = LoadCursor (hInst, "xkill_cursor");
  wc.lpszClassName = "XKILL";

  RegisterClass (&wc);

  me = CreateWindowEx (WS_EX_TRANSPARENT, "XKILL", "XKill", 0,
		       0, -GetSystemMetrics (SM_CYCAPTION),
		       GetSystemMetrics (SM_CXSCREEN),
		       GetSystemMetrics (SM_CYSCREEN)
		       + GetSystemMetrics (SM_CYCAPTION),
		       NULL, NULL, hInst, NULL);

  ShowWindow (me, nCmdShow);

  while (GetMessage (&msg, NULL, 0, 0))
    {
      TranslateMessage (&msg);
      DispatchMessage (&msg);
    }

  return (int)msg.wParam;
}