We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,721 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

How to set Display Settings to EXTEND mode in Windows 7 using C++?

In my C++ Win32 program I want to set the current Display Settings to "Extend" mode. I Googled and found out that SetDisplayConfig() is the way to go forward in Windows 7 (I'm on Windows 7) but now I am kind of stuck how to proceed as the MSDN explanation (link here) is pretty confusing. I am very much new to C++ and API programming so I am finding it difficult to understand this.

I would highly appreciate some code sample and an explanation. Thanks in advance!

2
Contributors
2
Replies
1 Year
Discussion Span
9 Months Ago
Last Updated
3
Views
Question
Answered
sachintha81
Junior Poster in Training
97 posts since Apr 2008
Reputation Points: 35
Solved Threads: 1
Skill Endorsements: 0

Okay so I figured out the answer.

To identify the current configuration:

UINT32 PathArraySize = 0;
UINT32 ModeArraySize = 0;
DISPLAYCONFIG_PATH_INFO* PathArray;
DISPLAYCONFIG_MODE_INFO* ModeArray;
DISPLAYCONFIG_TOPOLOGY_ID CurrentTopology;

GetDisplayConfigBufferSizes(QDC_ALL_PATHS, &PathArraySize, &ModeArraySize);
	
PathArray =   (DISPLAYCONFIG_PATH_INFO*)malloc(PathArraySize * sizeof(DISPLAYCONFIG_PATH_INFO));
memset(PathArray, 0, PathArraySize * sizeof(DISPLAYCONFIG_PATH_INFO));

ModeArray =   (DISPLAYCONFIG_MODE_INFO*)malloc(ModeArraySize * sizeof(DISPLAYCONFIG_MODE_INFO));
memset(ModeArray, 0, ModeArraySize * sizeof(DISPLAYCONFIG_MODE_INFO));

LONG ret = QueryDisplayConfig(QDC_DATABASE_CURRENT,&PathArraySize, PathArray, &ModeArraySize, ModeArray, &CurrentTopology);
// Above CurrentTopology variable will aquire the current display setting (ie Extend, Duplicate etc)

free(PathArray);
free(ModeArray);

To set the required display setting (Extend, Duplicate etc):

SetDisplayConfig(0,NULL,0,NULL,SDC_TOPOLOGY_EXTEND|SDC_APPLY);

or

SetDisplayConfig(0,NULL,0,NULL,SDC_TOPOLOGY_CLONE|SDC_APPLY);
sachintha81
Junior Poster in Training
97 posts since Apr 2008
Reputation Points: 35
Solved Threads: 1
Skill Endorsements: 0
Question Self-Answered as of 1 Year Ago

hi,
this code is setting some time build-in display as primary and soem time external display as primary. suppose if i want to specify which display want to be primary how can i do that ?

sriv
Newbie Poster
1 post since Aug 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0598 seconds using 2.7MB