Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recovering window title using TProcess sometimes gives incorrect value. #408

Closed
ghost opened this issue Jun 2, 2017 · 5 comments
Closed

Comments

@ghost
Copy link

ghost commented Jun 2, 2017

See: https://villavu.com/forum/showthread.php?t=117585&p=1386995#post1386995

Some titles are complete, some are truncated at the first non-alphabetical, non-alphanumeric, or non-word character.

@ghost
Copy link
Author

ghost commented Jun 2, 2017

Per discussion in the thread the likely culprit is UTF-16 values inside of a Pascal string.

The concerns farther down in #338 are relevant to this bug report - the best way to handle Unicode support on Windows is to use UTF-8 internally and then convert it to UTF-16 when using OS facilities. If there is any way to put this in a unit that would be ideal, but this is something that needs to be done every place where Windows text API is used.

@ghost
Copy link
Author

ghost commented Jun 6, 2017

The forum post contains an outline for the code to convert between Unicode encodings.

@ghost
Copy link
Author

ghost commented Jun 6, 2017

Per LCL documentation TProcess uses the system codepage on Windows, meaning it is UTF-16. The result needs to be converted to UTF-8 for display with WinCPToUTF8 (the UnicodeString functions may or may not work) or TProcessUTF8 of the unit utf8process needs to be used. There may also be changes that need to be made to the project as a whole, see #338.

I'm wary of using types with UTF8 in the name as I'm not sure they will continue to exist, but for now they might be necessary.

@slackydev
Copy link
Contributor

slackydev commented Jun 12, 2017

Window title + TProcess, something is very off here... TProcess is class meant to be used to execute an "external" process, for example to run "ls" in the terminal, or to execute a python script from Simba. It has nothing to do with what happens in the referenced villavu-thread.

The villavu thread you are referring to talks about TSysProc not TProcess. TSysProc is just a simple datastructure @JohnPeel made when he added the GetProcesses function to Simba, and it is part of what needs to be tweaked.

See the original commit: 58faccf


Finally, now that that's cleared up, from what I gather; the following 3 changes are needed:

  1. Change Title field in TSysProc to WideString.
  2. Change it also for the lape export
  3. And finally replace this line with something along the lines of:
    SetLength(ProcArr[I].Title, GetWindowTextW(Handle, PWideChar(ProcArr[I].Title), Length(ProcArr[I].Title)));

Done, that's it, nothing more to it.

@ghost
Copy link
Author

ghost commented Jun 12, 2017

Yeah I kind of wonder what I was thinking. If nobody commits the change I will see if I can make one that doesn't use WideString.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants