Thursday, April 19, 2007

Client rectangle size and Meta files

GetClientRect()
function for determining the dimensions of the client area. There's nothing really wrong with this function, but it's a bit inefficient to call it every time you need to use this information. A much better method for determining the size of a window's client is to process the WM_SIZE message within your window procedure. Windows sends a WM_SIZE message to a window procedure whenever the size of the window changes. The lParam variable passed to the window procedure contains the width of the client area in the low word and the height in the high word. To save these dimensions, you'll want to define two static variables in your window procedure:


static int cxClient, cyClient ;

Like cxChar and cyChar, these variables are defined as static because they are set while processing one message and used while processing another message. You handle the WM_SIZE method like so:


case WM_SIZE:
cxClient = LOWORD (lParam) ;
cyClient = HIWORD (lParam) ;
return 0 ;



How can we use meta files in VC++ SDK programming :

Old Meta file usage :
-----------------------------

1.
HDC hdcMeta;
HMETAFILE hmf;

hdcMeta = CreateMetaFile (NULL);
MoveToEx (hdcMeta, 0, 0, NULL) ;
LineTo (hdcMeta, 100, 100) ;
hmf = CloseMetaFile(hdcMeta);


2. For Displaying Meta file :
--------------------------------------

PlayMetaFile(hdc, hmf);


Enhanced Meta files :
----------------------------------

static HENHMETAFILE hemf ;
HDC hdc, hdcEMF ;

hdcEMF = CreateEnhMetaFile (NULL, NULL, NULL, NULL) ; or

hdcEMF = CreateEnhMetaFile (NULL, TEXT ("emf2.emf"), NULL,
TEXT ("EMF2\0EMF Demo #2\0")) ;



Rectangle (hdcEMF, 100, 100, 200, 200) ;

hemf = CloseEnhMetaFile (hdcEMF) ;


Displaying Meta File :
------------------------------

GetClientRect (hwnd, &rect) ;

rect.left = rect.right / 4 ;
rect.right = 3 * rect.right / 4 ;
rect.top = rect.bottom / 4 ;
rect.bottom = 3 * rect.bottom / 4 ;

PlayEnhMetaFile (hdc, hemf, &rect) ;

No comments: