Skip to content

Instantly share code, notes, and snippets.

@sachintha81
Last active November 30, 2023 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sachintha81/9fbf3483cb4bbd14745e5d2e73fa68de to your computer and use it in GitHub Desktop.
Save sachintha81/9fbf3483cb4bbd14745e5d2e73fa68de to your computer and use it in GitHub Desktop.
Set Display Settings to EXTEND mode in Windows 7 using C++
public void main(int argc, char const *argv[])
{
// 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);
// To set to Duplicate:
// SetDisplayConfig(0,NULL,0,NULL,SDC_TOPOLOGY_CLONE|SDC_APPLY);
return 0;
}
@AA-espresso
Copy link

Is there a way to select the display I want to mirror into? "assuming I have more than 1 external display connected".
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment