1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
#include <windows.h>
#include "createapp.h"
using namespace nsCtApp;
/* Declare Windows procedure */
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain (HINSTANCE hInstance,HINSTANCE hPrev,LPSTR lpszArgument,int nWinState)
{
CreateApp Window(hInstance,WndProc); /* Create window & point to procedure. */
Window.Center(); /* Center the window on the desktop. */
HWND hWnd = Window.Present(); /* Store the handle and present the window. */
/* Create the regions to experiment with. */
HRGN Region1 = CreateRectRgn(0,0,100,100);
HRGN Region2 = CreateRectRgn(50,50,150,150);
HRGN CRegion1 = CreateRectRgn(0,0,0,0);
HRGN CRegion2 = CreateRectRgn(0,0,0,0);
/* Combine Region1 & Region2 & store result in CRegion. */
CombineRgn(CRegion1,Region1,Region2,RGN_AND);
CombineRgn(CRegion2,Region1,Region2,RGN_DIFF);
/* Create red & blue brushes. */
HBRUSH hbRedBrush = CreateSolidBrush(RGB(255,0,0));
HBRUSH hbBlueBrush = CreateSolidBrush(RGB(0,0,255));
/* Start the message loop. */
while (true)
{
if (!Window.MessagePump(1))
{ /* If the window must close, get confirmation. */
LPCSTR lpszMessage = "Are you sure you want to quit?";
int iMB = MessageBox(hWnd,lpszMessage,"Message",MB_YESNO|MB_ICONINFORMATION);
if (iMB == IDYES) break; /* Quit the loop if yes is selected. */
}
/* Display the combined region. */
FillRgn(Window.DC(),CRegion1,hbRedBrush);
FillRgn(Window.DC(),CRegion2,hbBlueBrush);
}
/* Delete created objects. */
DeleteObject(hbBlueBrush);
DeleteObject(hbRedBrush);
DeleteObject(CRegion2);
DeleteObject(CRegion1);
DeleteObject(Region2);
DeleteObject(Region1);
return 0;
}
LRESULT CALLBACK WndProc /* Window Procedure */
(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch (Message)
{
case WM_SYSCOMMAND:
/* If window must close, post a WM_QUIT message & veto the quit. */
if ((wParam & 0xFFF0) == SC_CLOSE) { PostQuitMessage(0); return 0; }
default:
return DefWindowProc(hWnd,Message,wParam,lParam);
}
return 0;
}
|