Home
Tutorials
Code Snippets
Code Samples
Downloads
Links

The Blog
Our Projects
About
Contact

::Add RageStorm to Favorites!::

The Blog | Our Projects | Guest Book | About | Contact

 
Code Snippet - Applying a Region for a Window
Author:Arkon
Category:Win32API
File Size:~ 1.34 KB
Uploaded at:10-Sep-06 08:42:18 pm
Description:
  Applying a round rectangle region to a normal window (for both clipping/painting).
This is a simple case, you might want to use polygons too.
  
hWnd = CreateWindow(...
RECT rect;
// Notice we don't use GetClientRect,
//this is because we want the Window size and not the Client size.
GetWindowRect(hWnd, &rect);
HRGN hRgn = CreateRoundRectRgn(0, 0, rect.right - rect.left, rect.bottom - rect.top, 20, 20);
// Set the new region
SetWindowRgn(hWnd, hRgn, false);

// Now it's time to draw the new window.
ShowWindow(hWnd, ...)

In the WinProc, we will have to process the WM_SIZING message:

case WM_SIZING:{
static POINT lastPos;
POINT p;
GetCursorPos(&p);
// If it's the same old position, ignore this resizing.
if (memcmp(&p, &lastPos, sizeof(POINT))) {
HRGN hRgn = CreateRoundRectRgn(0, 0, ((PRECT)lParam)->right - ((PRECT)lParam)->left, ((PRECT)lParam)->bottom - ((PRECT)lParam)->top, 20, 20);
SetWindowRgn(hWnd, hRgn, true); // Redraw window.
lastPos = p;
return 1; // We processed the message.
}
lastPos = p;
}return 0; // This time, we didn't.
case WM_SIZE:{
if (wParam != SIZE_MINIMIZED && wParam != SIZE_MAXHIDE) {
RECT rect;
GetWindowRect(hWnd, &rect);
HRGN hRgn = CreateRoundRectRgn(0, 0, rect.right - rect.left, rect.bottom - rect.top, 20, 20);
SetWindowRgn(hWnd, hRgn, true); // Redraw window.
}
}return 0;

// Cleanup: none
// The system knows to delete the region object,
// don't touch it once you called SetWindowRgn.
NOTE:
Comments that will hurt anyone in any way will be deleted.
Don't ask for features, advertise or curse.
If you want to leave a message to the author use the contacts,
if you have any question in relation to your comments please use the forum.
Comments which violate any of these requests will be deleted without further
notice. Use the comment system decently.

Post your comment:
Name:
email:
Comment:
::Top 5 Tutorials::
Embedded Python[117058]
2D Rotated Rectangles Collision Detection[88983]
Keyboard Hook[77324]
UDP[65877]
HTTP Proxy[41214]

::Top 5 Samples::
2D ColDet Rotated Rectangles[11561]
PS2 Mouse Driver[6958]
Wave Format Player[5792]
Reading FAT12[5620]
CodeGuru[5359]


All rights reserved to RageStorm © 2009