Sandundhammika's Blog

{April 23, 2010}   Let’s write a simple program to get screen resolution values

hi today I’m going to demonstrate how to write a simple win32 program using C++

to display screen resolution values using a simple Message Box.

Here is the source code.

#include <windows.h>
#include <tchar.h>

TCHAR  gResultOutBuffer [80];

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int iCmdShow)
 // get the vertical resolution.
 int vert_res = GetSystemMetrics(SM_CYSCREEN);
 // get the horizontal resolution.
 int hori_res = GetSystemMetrics(SM_CXSCREEN);

 // then create use wsprintf to print it to an
 // appropriate buffer.
 wsprintf(gResultOutBuffer,_T("Resolution is : %dx%d \n" ),hori_res,vert_res );

 // Then Create a MessageBox and show it to the user.
 MessageBox(NULL,gResultOutBuffer,_T("screen resolution"),MB_OK);

 return 0;

And here is how you should compile this,

and for more information head to the

–Happy Coding–


Leave a Reply

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

You are commenting using your 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

et cetera
%d bloggers like this: