4

I am using DevExpress skins. I implemented a switch to disable skins manually. I need this basically because of a Terminal server (I need to have a flat look to save on connection bandwith).

Anyway, the manual switch isn't good because the user must continously use it when using the application locally or remotely. Of course only a user who cares about look.

I would like to leave the manual switch but to add also another automatic switch that checks the Windows settings for performance (I don't know how to tell this in English, anyway, I mean that setting for performance that lets any version of Windows look, like Windows '98). I would like (if it is possible) to have a unique function that works on every Windows version (2K, XP, Vista, 7, and the server counterparts).

Please note I am not interested in merely knowing whether my system is running in RDP, but whether the performance settings are set for high image quality or not.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
UnDiUdin
  • 14,924
  • 39
  • 151
  • 249

4 Answers4

2

You can use my JwaWinsta unit which is in the Delphi Jedi Apilib.

More specifically you can use WinStationQueryInformationW with the WinStationClient info class which returns a WINSTATIONCLIENT structure.

In this structure is the WinStationClientFlags member which is a bitfield that can contain any mask of the following constant:

  TS_PERF_DISABLE_NOTHING = $0;
  TS_PERF_DISABLE_WALLPAPER = $1;
  TS_PERF_DISABLE_FULLWINDOWDRAG = $2;
  TS_PERF_DISABLE_MENUANIMATIONS = $4;
  TS_PERF_DISABLE_THEMING = $8;
  TS_PERF_ENABLE_ENHANCED_GRAPHICS = $10;
  TS_PERF_DISABLE_CURSOR_SHADOW = $20;
  TS_PERF_DISABLE_CURSORSETTINGS = $40;
  TS_PERF_ENABLE_FONT_SMOOTHING= $80;
  TS_PERF_ENABLE_DESKTOP_COMPOSITION = $100;
  TS_PERF_DEFAULT_NONPERFCLIENT_SETTING = $40000000;
  TS_PERF_RESERVED1 = $80000000;

Further more this structure also returns the ColorDepth member.

Remko
  • 7,214
  • 2
  • 32
  • 52
1

Use the SM_REMOTESESSION System Metric to determine if your program is running over RDP.

This OldNewThing post has much more information.

glob
  • 2,960
  • 17
  • 21
0

Hi You can use WTSEnumerateSessions api to check if the user is running in rdp mode.

var pSessionInfo: PWTS_SESSION_INFOW;
SessionInfo: WTS_SESSION_INFO;
SessionCount: Cardinal;
i: Integer;
begin
  try
    Result := -1;
    if WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE, 0, 1, pSessionInfo, SessionCount) then
      begin
        SessionInfo := pSessionInfo^;
        for i := 0 to SessionCount - 1 do
          begin
            if SessionInfo.State = WTSActive then
              begin
                if Pos('rdp', LowerCase(SessionInfo.pWinStationName)) <> 0 then
                  ShowMessage('this is rdp');
              end;
            pSessionInfo := PWTS_SESSION_INFOW(Pointer(Integer(pSessionInfo) + SizeOf(WTS_SESSION_INFOW)));
            SessionInfo := pSessionInfo^;
          end;
      end;
  finally
    WTSFreeMemory(PSessionInfo);
  end;

Hope this answers your question. BTW delphi doesn't have an import for WTSEnumerateSessions, so you will have to import it by hand, or download a Jwa library. The function is decalred in JwaWtsApi32.pas

Davita
  • 8,928
  • 14
  • 67
  • 119
  • But this (correct me if I am wrong) tells me if the applciation is running in terminal server or in local machine, right? What If I just want to read the current machine settigns? I could also set my windows 7 machine to be optimized for performance, so in this case I would like to disable the skins even if I am not on remote desktop. – UnDiUdin Dec 02 '10 at 12:09
  • You are right, I misunderstood your question, sorry. The problem you have is not about delphi, but about winapi. Maybe you should post a new question with appropriate tags and you will get the answer. – Davita Dec 02 '10 at 12:56
  • the tags of my question are already about win api. Anyway as you suggest I will change the title including WinApi explicitly – UnDiUdin Dec 02 '10 at 13:02
  • There's no need for a new question. You merely misunderstood it, Davita. And @User, I would advise *against* checking whether Windows is optimized for performance. If it's optimized for performance, but the user still has themes enabled, then your program should continue showing its themes as well. – Rob Kennedy Dec 02 '10 at 13:53
  • ok thanks. @Davita: honestly I should have just posted the question (and not say why i need it, because i noticed this created confusion, I wanted to be helpful by explaining the real world case but i noticed it just confused people) - @Rob yes you are right, anyway I ended up just checking color depth, because in rdp the main problem is color depth, and so when it is 8 bit (that means "extreme condition") I auto remove skins. – UnDiUdin Dec 03 '10 at 09:17
  • For what it's worth this is the wrong way to detect a remote session, @glob has identified the canonical way to do so – David Heffernan Dec 03 '10 at 09:41
  • ok anyway I now understand that the GetDeviceCap returns the value used indipendelty from rdp or normal session. So i could also rename the questino but since now the solution has been found it is not worth... – UnDiUdin Dec 03 '10 at 13:07
0
// returns the color bit depth (8, 16, 32, ....) on the machine
// note: it works also for rdp (it returns the color bit depth of
// the current session, not some default settings on the server)
function GetBitColorDepth: integer;
var
  DC: THandle;    // display context
begin
  DC := GetDC(HWND(nil));
  Result := GetDeviceCaps(DC, BITSPIXEL);
  ReleaseDC(HWND(nil), DC);
end;
UnDiUdin
  • 14,924
  • 39
  • 151
  • 249
  • I am just wondering what happens if the color depth changes, eg when you reconnect to an existing session. This doesn't seem to be the best way to do it. – Remko Dec 03 '10 at 16:03
  • it is for sure not perfect. the case you mention will not be handled. Only at next application start. – UnDiUdin Dec 06 '10 at 14:45