Use Windows API from C# to set primary monitor

前端 未结 4 1801
予麋鹿
予麋鹿 2020-12-15 12:18

I\'m trying to use the Windows API to set the primary monitor. It doesn\'t seem to work - my screen just flicks and nothing happens.

    public const int DM_         


        
4条回答
  •  青春惊慌失措
    2020-12-15 12:45

    According to the documentation for ChangeDisplaySettingsEx, "the dmSize member must be initialized to the size, in bytes, of the DEVMODE structure." Furthermore, the EnumDisplaySettings documentation states, "Before calling EnumDisplaySettings, set the dmSize member to sizeof(DEVMODE), and set the dmDriverExtra member to indicate the size, in bytes, of the additional space available to receive private driver data". I don't see this happening in the code sample given in the question; that's one reason why it may be failing.

    Additionally, you might have errors in the definitions of the DEVMODE and DISPLAY_DEVICE structs, which were not included in the question. Roger Lipscombe's suggestion to get it working from C/C++ first is an excellent way to rule out this type of problem.

    Finally, check the return value from ChangeDisplaySettingsEx and see if that gives a clue as to why it might be failing.

提交回复
热议问题