windows的桌面扩展功能,可以使用第2个显示器,在delphi中,如何编程开启和关闭windows的桌面扩展功能?我有个VBS脚本,可以通过模拟点击的方法实现,那么,在delphi中,如何实现呢?可以通过修改注册表实现吗?
  VBS脚本如下:
Option Explicit 
Dim WshShell, Dummy, SplashOn Error Resume Next Set WshShell = WScript.CreateObject("WScript.Shell") 'Main
Call DoIt
WScript.QuitSub DoIt
wshshell.Run("%systemroot%\system32\control.exe desk.cpl,@0,3")' Give Display Properties time to load
WScript.Sleep 1000 
WshShell.SendKeys "2"
WScript.Sleep 10 
WshShell.SendKeys "%E"
WScript.Sleep 500 
WshShell.SendKeys "%A"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"WshShell.SendKeys "{ENTER}"
End Sub 'DoIt

解决方案 »

  1.   

    用DELPHI也可以实现的
    unit DisplayStruct;interface
    uses
      Windows;
    type
       TEZDevMode = packed record
        dmDeviceName: array[0..CCHDEVICENAME - 1] of AnsiChar;
        dmSpecVersion: Word;
        dmDriverVersion: Word;
        dmSize: Word;
        dmDriverExtra: Word;
        dmFields: DWORD;
        dmPosition:TPoint;
        dmDisplayOrientation:DWORD;
        dmDisplayFixedOutput:DWORD;
        dmColor: SHORT;
        dmDuplex: SHORT;
        dmYResolution: SHORT;
        dmTTOption: SHORT;
        dmCollate: SHORT;
        dmFormName: array[0..CCHFORMNAME - 1] of AnsiChar;
        dmLogPixels: Word;
        dmBitsPerPel: DWORD;
        dmPelsWidth: DWORD;
        dmPelsHeight: DWORD;
        dmDisplayFlags: DWORD;
        dmDisplayFrequency: DWORD;
        dmICMMethod: DWORD;
        dmICMIntent: DWORD;
        dmMediaType: DWORD;
        dmDitherType: DWORD;
        dmICCManufacturer: DWORD;
        dmICCModel: DWORD;
        dmPanningWidth: DWORD;
        dmPanningHeight: DWORD;
      end;
       procedure TFormEzConfig.cmb_ScreenNumChange(Sender: TObject);
    var
      DisplayDevice: TDisplayDevice;
      Dm: TEZDevMode;
      DevM: PDevMode;
      hr: integer;
    begin
      inherited;
      DisplayDevice.cb := SizeOf(TDisplayDevice);
      if EnumDisplayDevices(nil, cmb_ScreenNum.ItemIndex, DisplayDevice, 0) then    if (DisplayDevice.StateFlags and DISPLAY_DEVICE_PRIMARY_DEVICE) = 0 then
        begin
          if ((DisplayDevice.StateFlags and DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) = 0) then
          begin
            FillChar(Dm, sizeof(TEZDevMode), #0);
            dm.dmSize := SizeOf(TEZDevMode);
            dm.dmPosition.X := Screen.Monitors[0].Width;
            dm.dmFields := DM_POSITION;
            hr := ChangeDisplaySettingsEx(DisplayDevice.DeviceName, DevMode(Dm), 0, CDS_NORESET or CDS_UPDATEREGISTRY, nil);
            DevM := nil;
            hr := ChangeDisplaySettings(DevM^, CDS_RESET);
            if hr <> DISP_CHANGE_SUCCESSFUL then
            begin
              MessageBox(handle, '对不起无法启用您选择的显视设备,请确保相应的显视设备与显示器的' + #13#10 + '正常连接后再启用',
                '友情提示', MB_OK or MB_ICONWARNING);
              TComboBox(Sender).ItemIndex := 0;
            end;
          end; // A second call to ChangeDisplay
        end;
    end;implementationend.
      

  2.   

    simb 的方法不错,我试验了.
      

  3.   

    PASCAL代码的,在DELPHI2009中不能通过,显示DevMode(Dm),位置的类型不匹配,怎么办?
      

  4.   

    to 3楼:
    这是由于Delphi2009对Unicode的支持而产生的变动。
    只要把AnsiChar改成WideChar就行了
    像这样:
    type
       TEZDevMode = packed record
        dmDeviceName: array[0..CCHDEVICENAME - 1] of WideChar;
        dmSpecVersion: Word;
        dmDriverVersion: Word;
        dmSize: Word;
        dmDriverExtra: Word;
        dmFields: DWORD;
        dmPosition:TPoint;
        dmDisplayOrientation:DWORD;
        dmDisplayFixedOutput:DWORD;
        dmColor: SHORT;
        dmDuplex: SHORT;
        dmYResolution: SHORT;
        dmTTOption: SHORT;
        dmCollate: SHORT;
        dmFormName: array[0..CCHFORMNAME - 1] of WideChar;
        dmLogPixels: Word;
        dmBitsPerPel: DWORD;
        dmPelsWidth: DWORD;
        dmPelsHeight: DWORD;
        dmDisplayFlags: DWORD;
        dmDisplayFrequency: DWORD;
        dmICMMethod: DWORD;
        dmICMIntent: DWORD;
        dmMediaType: DWORD;
        dmDitherType: DWORD;
        dmICCManufacturer: DWORD;
        dmICCModel: DWORD;
        dmPanningWidth: DWORD;
        dmPanningHeight: DWORD;
      end;