Recent

Author Topic: MultiMon and Unicode  (Read 1036 times)

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 844
MultiMon and Unicode
« on: September 06, 2020, 01:39:25 pm »
I need EnumDisplayDevicesW from MultiMon. It requires UNICODE definition, that also requires FPC_OS_UNICODE. How can I define it? I tried to define it in project options, but it didn't work. OS is Win64.
Is it healthy for project not to have regular stable releases?
Just for fun: Code::Blocks, GCC 13 and DOS - is it possible?

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: MultiMon and Unicode
« Reply #1 on: September 06, 2020, 04:42:01 pm »
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.  Windows,Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  DISPLAY_DEVICEW  = record
  14.   Cb: DWORD;
  15.   DeviceName:Array[0..31] of WCHAR;//  DeviceName[32];
  16.   DeviceString:array[0..127] of WCHAR; // DeviceString[128];
  17.   StateFlags:DWORD;
  18.   DeviceID:Array[0..127] of WCHAR;//DeviceID[128];
  19.   DeviceKey:Array[0..127] of WCHAR; // DeviceKey[128];
  20. End;
  21.  PDISPLAY_DEVICEW = DISPLAY_DEVICEW;
  22.  
  23.   TForm1 = class(TForm)
  24.     Button1: TButton;
  25.     procedure Button1Click(Sender: TObject);
  26.   private
  27.  
  28.   public
  29.  
  30.   end;
  31.   Function EnumDisplayDevicesW(
  32.     lpDevice:LPWSTR;
  33.     iDevNum:DWORD;
  34.     lpDisplayDevice:Pointer; //DISPLAY_DEVICEW;
  35.     dwFlags:DWORD
  36.   ):WinBool;StdCall External 'user32.dll' name 'EnumDisplayDevicesW';
  37. Const
  38.   EDD_GET_DEVICE_INTERFACE_NAME = 1; //(0x00000001
  39. var
  40.   Form1: TForm1;
  41.  
  42. implementation
  43.  
  44. {$R *.lfm}
  45.  
  46. { TForm1 }
  47.  
  48. procedure TForm1.Button1Click(Sender: TObject);
  49. Var
  50.   V:Display_DEVICEW;
  51. begin
  52.   Fillchar(V, sizeof(V), 0);
  53.   V.cb := Sizeof(V);
  54. {Change parameter nnumbre 2 as the index to the monitor to look at}
  55. { When there are no more monitors it will return false}
  56. If  EnumDisplayDevicesW(Pointer(0), 0, @V, EDD_GET_DEVICE_INTERFACE_NAME) then
  57.  Begin
  58.    caption := V.DeviceName;
  59.  End;
  60. end;
  61.  
  62. end.
  63.  
  64.  

It seems to work, I couldn't find the W version of the record so I changed this one, it seems to work just fine..
The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: MultiMon and Unicode
« Reply #2 on: September 06, 2020, 05:30:01 pm »
I have attached a Project that shows the list with their defines. hope this helps others too..
The only true wisdom is knowing you know nothing

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 844
Re: MultiMon and Unicode
« Reply #3 on: September 06, 2020, 05:41:01 pm »
It's in MultiMon.

Code: Pascal  [Select][+][-]
  1. {$ifdef FPC_OS_UNICODE}
  2.   {$define UNICODE}
  3. {$endif}
  4. ...
  5. {$ifdef UNICODE}
  6.   DISPLAY_DEVICE = DISPLAY_DEVICEW;
  7.   PDISPLAY_DEVICE = PDISPLAY_DEVICEW;
  8.   LPDISPLAY_DEVICE = LPDISPLAY_DEVICEW;
  9.   TDisplayDevice = TDisplayDeviceW;
  10.   PDisplayDevice = PDisplayDeviceW;
  11. {$else}
  12.   DISPLAY_DEVICE = DISPLAY_DEVICEA;
  13.   PDISPLAY_DEVICE = PDISPLAY_DEVICEA;
  14.   LPDISPLAY_DEVICE = LPDISPLAY_DEVICEA;
  15.   TDisplayDevice = TDisplayDeviceA;
  16.   PDisplayDevice = PDisplayDeviceA;
  17. {$endif} // UNICODE  
  18. ...
  19. {$ifdef UNICODE}
  20.     Pointer(g_pfnEnumDisplayDevices)  := GetProcAddress(hUser32, 'EnumDisplayDevicesW');
  21.     if IsPlatformNT then
  22.       Pointer(g_pfnGetMonitorInfo)    := GetProcAddress(hUser32, 'GetMonitorInfoW')
  23.     else
  24.       Pointer(g_pfnGetMonitorInfo)    := GetProcAddress(hUser32, 'GetMonitorInfoA');
  25. {$else}
  26.     Pointer(g_pfnGetMonitorInfo)      := GetProcAddress(hUser32, 'GetMonitorInfoA');
  27.     Pointer(g_pfnEnumDisplayDevices)  := GetProcAddress(hUser32, 'EnumDisplayDevicesA');
  28. {$endif}
  29.  
UNICODE isn't defined for me. And defining it in project options doesn't help. I've implemented my code as is for now, as I hope, that crucial parts of TDisplayDevice can be english only.
Is it healthy for project not to have regular stable releases?
Just for fun: Code::Blocks, GCC 13 and DOS - is it possible?

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: MultiMon and Unicode
« Reply #4 on: September 06, 2020, 05:47:05 pm »
please look at the attached project.

Unicode as in strings is basically WIDESTRING for windows when it comes to doing this sort of stuff..

I can't help it if the UNICODE define isn't defined...

« Last Edit: September 06, 2020, 05:50:44 pm by jamie »
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018