home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / pcmag / vol13n05.zip / TMTOGG.ZIP / TMTOGGLE.C < prev    next >
C/C++ Source or Header  |  1993-11-05  |  3KB  |  99 lines

  1. /*
  2.  *  TMToggle toggles the topmost/non-topmost style of other windows.
  3.  */
  4.  
  5. #include <windows.h>
  6.  
  7. long FAR PASCAL WndProc (HWND, WORD, WORD, LONG);
  8.  
  9. /*
  10.  *  Function WinMain.
  11.  */
  12.  
  13. int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  14.                     LPSTR lpszCmdLine, int nCmdShow)
  15. {
  16.     static char szAppName[] = "TMToggle";
  17.     WNDCLASS wndclass;
  18.     HWND hwnd;
  19.     RECT rect;
  20.     MSG msg;
  21.  
  22.     if (!hPrevInstance) {
  23.         wndclass.style = 0;
  24.         wndclass.lpfnWndProc = (WNDPROC) WndProc;
  25.         wndclass.cbClsExtra = 0;
  26.         wndclass.cbWndExtra = 0;
  27.         wndclass.hInstance = hInstance;
  28.         wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
  29.         wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
  30.         wndclass.hbrBackground = COLOR_WINDOW + 1;
  31.         wndclass.lpszMenuName = NULL;
  32.         wndclass.lpszClassName = szAppName;
  33.  
  34.         RegisterClass (&wndclass);
  35.     }
  36.  
  37.     SetRect (&rect, 0, 0, 144, 88);
  38.     AdjustWindowRect (&rect, WS_OVERLAPPEDWINDOW, FALSE);
  39.  
  40.     hwnd = CreateWindow (szAppName, szAppName, WS_OVERLAPPEDWINDOW,
  41.         CW_USEDEFAULT, CW_USEDEFAULT, rect.right - rect.left, rect.bottom -
  42.         rect.top, HWND_DESKTOP, NULL, hInstance, NULL);
  43.  
  44.     ShowWindow (hwnd, nCmdShow);
  45.     UpdateWindow (hwnd);
  46.  
  47.     while (GetMessage (&msg, NULL, 0, 0))
  48.         DispatchMessage (&msg);
  49.  
  50.     return msg.wParam;
  51. }
  52.  
  53. /*
  54.  *  WndProc processes messages to the TMToggle window.
  55.  */
  56.  
  57. long FAR PASCAL WndProc (HWND hwnd, WORD message, WORD wParam, LONG lParam)
  58. {
  59.     POINT point;
  60.     static nAction;
  61.     static BOOL bSearching = FALSE;
  62.  
  63.     switch (message) {
  64.  
  65.     case WM_CREATE:
  66.         CreateWindow ("button", "Topmost", WS_CHILD | WS_VISIBLE, 8, 8,
  67.             128, 32, hwnd, 100, ((LPCREATESTRUCT) lParam)->hInstance, NULL);  
  68.         CreateWindow ("button", "Non-Topmost", WS_CHILD | WS_VISIBLE, 8, 48,
  69.             128, 32, hwnd, 101, ((LPCREATESTRUCT) lParam)->hInstance, NULL);  
  70.         return 0;
  71.  
  72.     case WM_COMMAND:
  73.         if ((wParam == 100) || (wParam == 101)) {
  74.             ShowWindow (hwnd, SW_MINIMIZE);
  75.             bSearching = TRUE;
  76.             nAction = wParam - 100;
  77.             SetCapture (hwnd);
  78.             return 0;
  79.         }
  80.         break;
  81.  
  82.     case WM_LBUTTONDOWN:
  83.         if (bSearching) {
  84.             bSearching = FALSE;
  85.             ReleaseCapture ();
  86.  
  87.             point.x = (int) LOWORD (lParam);
  88.             point.y = (int) HIWORD (lParam); 
  89.             ClientToScreen (hwnd, &point);
  90.  
  91.             SetWindowPos (WindowFromPoint (point), nAction ? HWND_NOTOPMOST :
  92.                 HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
  93.             return 0;
  94.         }
  95.         break;
  96.     }
  97.     return DefWindowProc (hwnd, message, wParam, lParam);
  98. }
  99.