Sina
Sina

Reputation: 41

How to convert a command line string to hwnd in C++?

I want to create a screen saver in C++ using OpenGL. The command line sent to my app for previewing the screen saver in a small window contains a number which is the hwnd of the small monitor window in screen saver control panel applet. how can I convert this string to a valid hwnd?

Upvotes: 4

Views: 3043

Answers (1)

Greg Hewgill
Greg Hewgill

Reputation: 994599

From INFO: Screen Saver Command Line Arguments:

<HWND> is a HWND presented on the command line as an unsigned decimal number.

So, convert the decimal number to an unsigned int and then cast to HWND. For example:

(HWND)atoi(argv[n])

where argv[n] is the argument where the HWND value is found.

Pedant's corner: My use of atoi() can probably be improved, since the number on the command line is unsigned. Feel free.

Upvotes: 5

Related Questions