Is it possible to create a C ++ preprocessor macro based on the result of a function?
For example, I would like to dynamically save the height of the screen in the macro definition of the preprocessor:
#define SCREEN_HEIGHT GetSystemMetrics(SM_CYVIRTUALSCREEN)
Then I want to use the result to set values based on the height of the screen:
#if SCREEN_HEIGHT < 1200
#define TOP_COORD 200
#define BOTTOM_COORD 500
#define LEFT_COORD 0
#define RIGHT_COORD 1280
#else
#define TOP_COORD 1100
#define BOTTOM_COORD 1400
#define LEFT_COORD 0
#define RIGHT_COORD 1280
#endif
This does not work, since SCREEN_HEIGHT does not seem to be detected correctly.
Is there a better way to do this? Is it possible? I want to be able to get this screen height information in the header file, if possible, as this is part of a large piece of legacy code.
source
share