All pastes #224889 Raw Edit

Unnamed

public text v1 · immutable
#224889 ·published 2006-10-27 17:04 UTC
rendered paste body
#include <windows.h>
#include <stdio.h>
#include <string.h>

// Global variable
HINSTANCE	hInst;
HINSTANCE	mhInst;
HWND		mhWnd;          // handle to own window (initialize in WinMain)
HDC			mhDC;         // device context (initialize in each Paint function calling)

// Function prototypes.

BOOL CALLBACK PrintEnumWindowsProc(HWND hWnd,LPARAM lParam);

void Paint(HWND hWnd);

// Function prototypes.
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int);
LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);

// Application entry point. 

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    MSG msg;
    BOOL bRet;
    WNDCLASS wcx;          // register class
    HWND hWnd;
    UINT uResult;          // SetTimer's return value

    hInst = hInstance;     // Save the application-instance handle.
    // Fill in the window class structure with parameters that describe the main window.

    wcx.style = CS_HREDRAW | CS_VREDRAW;              // redraw if size changes
    wcx.lpfnWndProc = (WNDPROC) MainWndProc;                    // points to window procedure
    wcx.cbClsExtra = 0;                               // no extra class memory
    wcx.cbWndExtra = 0;                               // no extra window memory
    wcx.hInstance = hInstance;                        // handle to instance
    wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION);      // predefined app. icon
    wcx.hCursor = LoadCursor(NULL, IDC_ARROW);                                   // predefined arrow
    wcx.hbrBackground = GetStockObject(WHITE_BRUSH);  // white background brush
    wcx.lpszMenuName =  (LPCSTR) "MainMenu";                   // name of menu resource
    wcx.lpszClassName = (LPCSTR) "MainWClass";                 // name of window class

    // Register the window class.

    if (!RegisterClass(&wcx)) return FALSE;

    // create window of registered class

    hWnd = CreateWindow(
        "MainWClass",        // name of window class
        "LukeW",       // title-bar string
        WS_OVERLAPPEDWINDOW, // top-level window
        50,                  // default horizontal position
        50,                 // default vertical position
        200,                 // default width
        200,                 // default height
        (HWND) NULL,         // no owner window
        (HMENU) NULL,        // use class menu
        hInstance,           // handle to application instance
        (LPVOID) NULL);      // no window-creation data
    if (!hWnd) return FALSE;

    // Show the window and send a WM_PAINT message to the window procedure.
    // Record the current cursor position.

    ShowWindow(hWnd, nCmdShow);
    UpdateWindow(hWnd);

    // loop of message processing

    while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
    {
        if (bRet == -1)
        {
            // handle the error and possibly exit
        }
        else
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }
    return (int) msg.wParam;
}
   LRESULT CALLBACK MainWndProc(
    HWND hWnd,        // handle to window
    UINT uMsg,        // message identifier
    WPARAM wParam,    // first message parameter
    LPARAM lParam)    // second message parameter
{
	
    switch (uMsg)
    {
		case WM_MOVE:
			//SendMessage(hWnd, WM_PAINT, 0, 0);
			return 0;

		case WM_PAINT:
			InvalidateRect(hWnd, NULL, TRUE);
			Paint(hWnd);

			return 0;

		
		case WM_CREATE:
            // Initialize the window.
            return 0;

        case WM_SIZE:
            // Set the size and position of the window.
            return 0;

        case WM_DESTROY:
            // Clean up window-specific data objects.
            PostQuitMessage(0);
            return 0;

        //
        // Process other messages.
        //

        default:
            return DefWindowProc(hWnd, uMsg, wParam, lParam);
    }
   }

// funkce Paint se vola na udalost WM_PAINT

void Paint(HWND hWnd)
{
    PAINTSTRUCT ps;             // information can be used to paint the client area of a window owned by that application  

  mhDC = BeginPaint(hWnd, &ps);     // prepares the specified window for painting (use global variable)

  EnumWindows(&PrintEnumWindowsProc, 0);  // process PrintEnumWindowsProc function to all existed windows

    DeleteDC(mhDC);             // deletes the specified device context
    EndPaint(hWnd, &ps);          // marks the end of painting in the specified window
}


BOOL CALLBACK PrintEnumWindowsProc(
      HWND hWnd,                  // handle to some system window 
      LPARAM lParam               // application-defined value
      )
{
  char text[256];
  char WClassName[256];
  char mWClassName[256];
  RECT act;
  RECT other;

  GetClassName(hWnd, WClassName,  256);       // get class name of some system window
  GetClassName(mhWnd, mWClassName, 256);       // get class name of your own window

  
  

  if ((strcmp(WClassName,mWClassName) == 0) &&    // if names are same (we can suppose it is our application of our class)
    (hWnd != mhWnd))                // and it is not the same application instance
  {

	  GetWindowRect(mhWnd, &act);
	  GetWindowRect(hWnd, &other);
	  MoveToEx(mhDC, (act.right-act.left)/2, (act.bottom-act.top)/2, NULL );
	  LineTo(mhDC, (other.right+other.left)/2 , (other.top+other.bottom)/2 ); 
	  

	  SendMessage(mhWnd, WM_PAINT, 0, 0);    // repaint this window

  }

  return TRUE;
}