Processing the WM_SIZE Message

Whenever an external event that will affect the painting output occurs, the user must adjust the affected controlling factors. The following example demonstrates changes made while processing the WM_SIZE message.

// This is example assumes, that we have a valid LEAD paint handle and a valid 
// LEAD bitmap handle, and the user has set the bitmap handle in the paint handle 
// ( through the L_PntSetMetrics function ). And also assumes that user has initialized the 
// current horizontal and vertical scrolling position variables 
BITMAPHANDLE g_PaintBitmap ; 
RECT g_rcBitmapView ; 
int g_nHScrollPos ; 
int g_nVScrollPos ; 
L_VOID OnSize ( HWND hWnd, L_UINT nState, L_INT nCx, L_INT nCy ) 
{ 
   SCROLLINFO si ; 
   UNREFERENCED_PARAMETER ( nState ) ; 
    
   if ( g_PaintBitmap.Flags.Allocated ) 
   { 
      si.cbSize = sizeof ( SCROLLINFO ) ; 
      si.fMask  = SIF_ALL ; 
       
      // vertical scroll. 
      GetScrollInfo ( hWnd, SB_VERT, &si ) ; 
       
      si.nMin  = 0 ; 
      si.nMax  = BITMAPHEIGHT ( &g_PaintBitmap ) ; 
      si.nPage = nCy ; 
       
      SetScrollInfo ( hWnd, SB_VERT, &si, TRUE ) ; 
       
      GetScrollInfo ( hWnd, SB_VERT, &si ) ; 
       
      g_nVScrollPos = si.nPos ; 
       
      // horizontal scroll 
      GetScrollInfo ( hWnd, SB_HORZ, &si ) ; 
       
      si.nMin  = 0 ; 
      si.nMax  = BITMAPWIDTH ( &g_PaintBitmap ) ; 
      si.nPage = nCx ; 
       
      SetScrollInfo ( hWnd, SB_HORZ, &si, TRUE ) ; 
       
      GetScrollInfo ( hWnd, SB_HORZ, &si ) ; 
       
      g_nHScrollPos = si.nPos ; 
       
      // set the painting rectangel. 
      SetRect ( &g_rcBitmapView, 0, 0, BITMAPWIDTH ( &g_PaintBitmap ), BITMAPHEIGHT ( &g_PaintBitmap ) ) ; 
       
      OffsetRect ( &g_rcBitmapView, - g_nHScrollPos, - g_nVScrollPos ) ; 
   } 
   else 
   { 
      si.cbSize = sizeof ( SCROLLINFO ) ; 
      si.fMask  = SIF_RANGE ; 
      si.nMin   = 0 ; 
      si.nMax   = 0 ; 
       
      SetScrollInfo ( hWnd, SB_VERT, &si, TRUE ) ; 
      SetScrollInfo ( hWnd, SB_HORZ, &si, TRUE ) ; 
       
      SetRectEmpty ( &g_rcBitmapView ) ; 
   } 
    
   if ( GetFocus ( ) == hWnd ) 
   { 
      PAINTXFORM  PntXForm ; 
      RECT        rcDCRect ; 
       
       
      // set the paint tools DC extents. 
      SetRect ( &rcDCRect, 0, 0, nCx, nCy ) ; 
       
      L_PntSetDCExtents ( pPaint, &rcDCRect ) ; 
       
      // set Painting Transformation. 
      PntXForm.nZoom    = 100 ; 
      PntXForm.nXOffset = - g_rcBitmapView.left ; 
      PntXForm.nYOffset = - g_rcBitmapView.top ; 
       
      L_PntSetTransformation ( g_pPaintHandle, &PntXForm ) ; 
   } 
} 

This example uses the following functions:

L_PntSetDCExtents

L_PntSetTransformation.

The WM_SIZE message indicates that the dimensions of the DC (the window's client area DC) have changed. This DC will be used for future painting. The new dimensions of the DC should be set by calling L_PntSetDCExtents.

The L_PntSetTransformation function is called here to set the toolkit transformation values properly.

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Digital Paint C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.