Home > Windows API > Retrieving graphics objects selected into a DC!

Retrieving graphics objects selected into a DC!

Felt the need to retrieve current brush or pen or palette selected into a DC? Sometime back a friend of mine asked me this question, as an answer I gave him a better solution, but the question was a valid one!

So are there any windows api’s that helps us in the regard? Well the answer is yes, use GetCurrentObject and GetObject in tandem to retrieve details of graphics object selected into a dc.

GetCurrentObject signature

HGDIOBJ GetCurrentObject( HDC hdc, // handle to DC
                          UINT uObjectType // object type
                        );

Lookup MSDN for possible values of uObjectType.

GetObject signature

int GetObject( HGDIOBJ hgdiobj,  // handle to graphics object
               int cbBuffer,     // size of buffer for object information
               LPVOID lpvObject  // buffer for object information
             );

Lookup MSDN for possible values of lpvObject in GetObject. Here is an example of how to use these functions!

// Use GetCurrentObject to get current brush selected in to a DC
HBRUSH hCurrentDCBrush = GetCurrentObject( hDC, OBJ_BRUSH );

// Get brush details
LOGBRUSH lCurrentBrushDetails = { 0 };
GetObject( hCurrentDCBrush, sizeof( lCurrentBrushDetails ), &lCurrentBrushDetails );
Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: