Recent

Author Topic: Help with special characters and words with tildes  (Read 318 times)

Ecsa

  • New Member
  • *
  • Posts: 13
Help with special characters and words with tildes
« on: December 01, 2022, 09:31:47 pm »
Hello friends, I am using the following code to change the wallpaper in Windows 11 and everything works perfectly as long as the image does not contain special characters such as the letters áéíóú or the letter ñ in its name.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   s: string;
  4. begin
  5.    s := 'c:\windows\athena.bmp';
  6.    SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, PChar(s), 0)
  7. end;


As an example I have an image called "Móntaña.jpg" and when I use the procedure in the registry I check that it appears as follows HKEY_CURRENT_USER\Control Panel\Desktop\Wallpaper that is written as follows: "C:\Desktop\Móntaña.jpg" for which it places a black image and not the wallpaper because the name had the special character.

It's the same when you want to execute a command from the console. I have the same problem, the texts with special characters don't work for me. Can someone help me? I've been having this problem for months and I can't solve it. Thanks in advance.

PascalDragon

  • Hero Member
  • *****
  • Posts: 4874
  • Compiler Developer
Re: Help with special characters and words with tildes
« Reply #1 on: December 01, 2022, 09:38:17 pm »
Try to use SystemParametersInfoW and pass the string as PWideChar. Or ensure that the string is converted from UTF-8 to your system's codepage.

Ecsa

  • New Member
  • *
  • Posts: 13
Re: Help with special characters and words with tildes
« Reply #2 on: December 01, 2022, 09:45:03 pm »
Excuse my ignorance, I made this change and it doesn't work for me  :-[

Code: Pascal  [Select][+][-]
  1. SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, PWideChar(s), 0)

Bart

  • Hero Member
  • *****
  • Posts: 4887
    • Bart en Mariska's Webstek
Re: Help with special characters and words with tildes
« Reply #3 on: December 01, 2022, 09:53:28 pm »
Try (untested):
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   s: string;
  4.   u: UnicodeString;
  5. begin
  6.   s := 'c:\windows\athena.bmp';
  7.   u := s; //implicit conversion, lossless in this case
  8.   //or simply directly do u := s := 'c:\windows\athena.bmp';
  9.    SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, PWChar(u), 0)
  10. end;
  11.  

Bart

KodeZwerg

  • Hero Member
  • *****
  • Posts: 914
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Help with special characters and words with tildes
« Reply #4 on: December 01, 2022, 09:56:10 pm »
If Barts code not work, my was tested.
Code: Pascal  [Select][+][-]
  1. var
  2.   s: WideString;
  3. begin
  4.   s := 'Drive:\Path\Filenama.ext';
  5.   if SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, PWideChar(s), SPIF_SENDCHANGE) then
  6.     ShowMessage('Good')
  7.     else
  8.     ShowMessage('Error');
  9. end.
« Last Edit: Tomorrow at 31:76:97 by KodeZwerg »

Bart

  • Hero Member
  • *****
  • Posts: 4887
    • Bart en Mariska's Webstek
Re: Help with special characters and words with tildes
« Reply #5 on: December 01, 2022, 09:57:44 pm »
If Barts code not work, my was tested.
And since yours works, so would mine  :)

Bart

Ecsa

  • New Member
  • *
  • Posts: 13
Re: Help with special characters and words with tildes
« Reply #6 on: December 01, 2022, 10:08:12 pm »
None of the possible solutions have worked.

KodeZwerg

  • Hero Member
  • *****
  • Posts: 914
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Help with special characters and words with tildes
« Reply #7 on: December 01, 2022, 10:31:19 pm »
None of the possible solutions have worked.
Very very strange....
As you can see on my attachment, I was using your filename with my logo.

And BTW, "Wallpaper" inside of registry is not your actual wallpaper name for custom pictures so you might are mislead by thinking it.
« Last Edit: Tomorrow at 31:76:97 by KodeZwerg »

KodeZwerg

  • Hero Member
  • *****
  • Posts: 914
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Help with special characters and words with tildes
« Reply #8 on: December 01, 2022, 10:42:05 pm »
I attached my project, maybe you did a copy/paste error.
« Last Edit: Tomorrow at 31:76:97 by KodeZwerg »

Ecsa

  • New Member
  • *
  • Posts: 13
Re: Help with special characters and words with tildes
« Reply #9 on: December 02, 2022, 03:25:05 pm »
I attached my project, maybe you did a copy/paste error.

I just checked today and if now it works without problem, thank you very much.

KodeZwerg

  • Hero Member
  • *****
  • Posts: 914
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Help with special characters and words with tildes
« Reply #10 on: December 02, 2022, 03:31:19 pm »
I attached my project, maybe you did a copy/paste error.

I just checked today and if now it works without problem, thank you very much.
I am glad that you made it finally.  :D
(If possible, edit first post subject with a [solved] or something like that)
« Last Edit: Tomorrow at 31:76:97 by KodeZwerg »

 

TinyPortal © 2005-2018