NO

Author Topic: Last Update for FindFile  (Read 21852 times)

JohnF

  • Guest
Last Update for FindFile
« on: May 10, 2016, 08:51:06 AM »
This is probably the last update of FindFile. Mostly trivial changes but worth doing - I've not updated my web site yet.

Code: [Select]
================================
10th May 2016. Version 3.2 (JF)
================================
Removed ButtEx64W.lib & ButtEx32W.lib and included ButtonEx.c for both the
32bit and 64bit projects.

There is only one .RC file now for both the 32bit and 64bit versions of FindFile.
"FindFileUni.rc"

Added a Mutex so that only one instance of FindFile can be run at any
one time. See wWinMain().

The total bytes listed are summed and displayed in the status bar after
the scan has finished, this can also be used to show the bytes used on a
drive, partition or in a folder.

In many cases used the macro ARRSIZE(s) to pass size of buffer to a
Windows API instead of a hardcoded number.

Ctrl+C in header window for clipboard copy, see SubClassTextBoxProc(). Select
text with mouse then Ctrl+C will copy the text to the clipboard.

Changed SHRecycleBin() (Shell.c) to send folders to the Recycle Bin as
well as files.

A new Dutch translation has been added to the resource strings by
Siekmanski, and Grincheux has done a better French translation.

Two Dialog message boxes always displayed in English - fixed.

Added ToolTip to the WebSite button on the About Dialogbox explaining what
one will find there.

Removed the icon from the Search button.

Left in the LFCR's for 'View Search Results' in header window, the text
looks better.

Added icons from applications on the Context 'Send To' menu strip.

===================================

EDIT: The attachment has been updated with the version on my web site. 19 May 2016

John
« Last Edit: June 02, 2016, 02:12:00 PM by JohnF »

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: Last Update for FindFile
« Reply #1 on: May 10, 2016, 09:12:41 AM »
Hello John,
good job.  :)
But... my OS is in english, language is set to italian and... Findfile starts in german  :o :'(
Maybe it is worth another slight update?  ;)
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

JohnF

  • Guest
Re: Last Update for FindFile
« Reply #2 on: May 10, 2016, 09:34:47 AM »
Hello John,
good job.  :)
But... my OS is in english, language is set to italian and... Findfile starts in german  :o :'(
Maybe it is worth another slight update?  ;)

Hmm, not sure what the cause is, it should just take what the OS gives it. Why you would get German I don't know.

Edit: I don't do anything about the language Frankie, the OS does all the work. It is selecting German strings from the resource - but why?

John

« Last Edit: May 10, 2016, 10:03:48 AM by JohnF »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Last Update for FindFile
« Reply #3 on: May 10, 2016, 10:06:21 AM »
Thank's John!

frankie:
What language ID's you get?
Code: [Select]
#define UNICODE
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

int __cdecl DisplayThreadLocale(void)
{
wchar_t szTmp[512];

LCID lcidt = GetThreadLocale();
LCID lcids = GetSystemDefaultLCID();
LCID lcidu = GetUserDefaultLCID();
wsprintf(szTmp,
L"ThreadLocale  0x%04X\nSystemDefaultLCID  0x%04X\nUserDefaultLCID 0x%04X",
lcidt, lcids, lcidu);
MessageBox(0, szTmp, L"DefaultLCID", MB_OK);
return 0;
}

void __cdecl WinMainCRTStartup(void)
{
DisplayThreadLocale();
ExitProcess(0);
}
May the source be with you

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: Last Update for FindFile
« Reply #4 on: May 10, 2016, 11:43:20 AM »
Hello Timo,
I get Italian LCID=0x410 (see image).
John maybe that if the local is not found the default goes to german and not english as it should do.
I'll make a check as I have time. Cheers.  :)
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

JohnF

  • Guest
Re: Last Update for FindFile
« Reply #5 on: May 10, 2016, 12:07:38 PM »
John maybe that if the local is not found the default goes to german and not english as it should do.
I'll make a check as I have time. Cheers.  :)

Ok.

As you say it should default to english.

John


Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: Last Update for FindFile
« Reply #6 on: May 10, 2016, 01:05:15 PM »
John I think that the default language should be english.
Anyway the problem is that when a resource is not found for the current LCID the OS defaults to the lower resource LCI. In our case it is the german, 0x0407, which is less than the british english, 0x0809.
The solution is to define language and sublanguage of all common resource, actually defined respectively as LANG_ENGLISH and SUBLANG_ENGLISH_UK, as neutral: LANG_NEUTRAL and SUBLANG_NEUTRAL, which value is 0x0 for both.
In this way any LCID not found will default to neutral that is in english.
You'll find attached an emended version of resources file "FindFileUni.rc".
You can make tests by setting undefined languages like spanish or italian:
Code: [Select]
int APIENTRY wWinMain(HINSTANCE hinst, HINSTANCE hinstPrev, wchar_t * lpCmdLine, int nCmdShow)
{
/* These calls to SetLanguage() are only for testing purposes.
Normally the Locale is set automatically for your locale by the OS.
For completeness this also needs to be done for the other thread in
Private_FindFile()
    */

SetLanguage(0x040a); // Spanish (Spain)
//SetLanguage(0x0410); // Italian (Italy)
//SetLanguage(0x0809); // English (UK)
//SetLanguage(0x040c); // French
//SetLanguage(0x0407); // German (Standard)
//SetLanguage(0x0416); // Portuguese (Brazil)
//SetLanguage(0x040b); // Finnish
//SetLanguage(0x0419); // Rusian
//SetLanguage(0x0413); // Dutch
« Last Edit: May 10, 2016, 01:11:39 PM by frankie »
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

JohnF

  • Guest
Re: Last Update for FindFile
« Reply #7 on: May 10, 2016, 01:18:49 PM »
This can't be right, having LANG_NEUTRAL and SUBLANG_NEUTRAL results in not being able to set any other of those languages you have seen in wWinMain()

   //SetLanguage(0x040c); // French
   //SetLanguage(0x0407); // German (Standard)
   //SetLanguage(0x0416); // Portuguese (Brazil)
   //SetLanguage(0x040b); // Finnish
   //SetLanguage(0x0419); // Rusian
   //SetLanguage(0x0413); // Dutch

John

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: Last Update for FindFile
« Reply #8 on: May 10, 2016, 01:27:29 PM »
I didn't checked...  :(
Let me check again...
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

JohnF

  • Guest
Re: Last Update for FindFile
« Reply #9 on: May 10, 2016, 02:07:49 PM »
Frankie can you set english in wWinMain when my original RC file is used?

If so I could make a check for the other languages and set english if none of them is found.

However which to use?

GetThreadLocale();
GetSystemDefaultLCID();
GetUserDefaultLCID();

On my system the ThreadLocale is 'english us' the others are 'english uk'.

John

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: Last Update for FindFile
« Reply #10 on: May 10, 2016, 02:54:42 PM »
John,
According to this MS doc resource loading should use the value from GetThreadLocale();.
But according the same doc:
Quote
If the FindResource and FindResourceEx functions do not find any resources that match the language ID's primary language, they search for resources tagged as "language-neutral." This language ID is useful for resource elements such as icons or cursors that are identical for all languages. If a bitmap or an icon will differ for some languages, you can define one language-neutral bitmap as the default and specify language IDs for as many other customized bitmaps as required. For example, bidirectional applications might require bitmaps with right-to-left directionality. Because the FindResource and FindResourceEx functions always search for specific language IDs first, they will always find a bitmap tagged with that language ID before they find one tagged as language-neutral. The search algorithm they follow is summarized in the following list:
  • Primary language/sublanguage
  • Primary language
  • Language-neutral
  • English (skipped if primary language is English)
  • Any
It should have worked.

Check for language isn't very elegant anyway, but seems the only one to work:
Code: [Select]
int APIENTRY wWinMain(HINSTANCE hinst, HINSTANCE hinstPrev, wchar_t * lpCmdLine, int nCmdShow)
{
/* These calls to SetLanguage() are only for testing purposes.
Normally the Locale is set automatically for your locale by the OS.
For completeness this also needs to be done for the other thread in
Private_FindFile()
    */

//SetLanguage(0x040a); // Spanish (Spain)
//SetLanguage(0x0410); // Italian (Italy)
//SetLanguage(0x0809); // English (UK)
//SetLanguage(0x040c); // French
//SetLanguage(0x0407); // German (Standard)
//SetLanguage(0x0416); // Portuguese (Brazil)
//SetLanguage(0x040b); // Finnish
//SetLanguage(0x0419); // Rusian
//SetLanguage(0x0413); // Dutch

//Set english as default language for those not supported
switch(GetThreadLocale())
{
case (0x0809): // English (UK)
case (0x040c): // French
case (0x0407): // German (Standard)
case (0x0416): // Portuguese (Brazil)
case (0x040b): // Finnish
case (0x0419): // Rusian
case (0x0413): // Dutch
break;
default:
SetThreadLocale(MAKELCID(0x0809, SORT_DEFAULT));
}

// This needs to be here for the MsgBox() call that requires ButtonEx stuff.
InitButtonEx();
      ....
« Last Edit: May 10, 2016, 02:58:51 PM by frankie »
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

JohnF

  • Guest
Re: Last Update for FindFile
« Reply #11 on: May 10, 2016, 03:28:48 PM »
Yes not good - thanks for all your help, I've included the check.

I have updated the original attachment.

EDIT: And in case anyone needs to know the check and setting has to be done in wWinMain() and also in another thread - Private_FindFile() which is in Find.c

John
« Last Edit: May 10, 2016, 04:02:08 PM by JohnF »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Last Update for FindFile
« Reply #12 on: May 11, 2016, 09:11:29 AM »
Simplified test project to check how this works :-\
Code: [Select]
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
void SetLanguage(LANGID lid);
void __cdecl WinMainCRTStartup(void)
{
TCHAR szTmp[256];
//SetLanguage(0x0410); // Italian (Italy)
SetLanguage(0x040c); // French
LoadString(GetModuleHandle(NULL), 10001, szTmp, sizeof(szTmp)/sizeof(szTmp[0]));
MessageBox(0,szTmp,0,MB_OK);

ExitProcess(0);
}
void SetLanguage(LANGID lid)
{
typedef LANGID (WINAPI *fnPtr) (LANGID wReserved);

if ((GetVersion() & 0x00FF) > 5) {// Vista =>
LANGID lid2;
fnPtr pSetThreadUILanguage  = (fnPtr)GetProcAddress(
GetModuleHandle(TEXT("kernel32.dll")), "SetThreadUILanguage");
if (pSetThreadUILanguage)
// lid2 should equal lid
lid2 = (*pSetThreadUILanguage)(lid);
} else {
SetThreadLocale(MAKELCID(lid, SORT_DEFAULT));
}
}
Code: [Select]
#include <windows.h>
LANGUAGE LANG_ENGLISH,SUBLANG_ENGLISH_US
STRINGTABLE { 10001, "English US" }
LANGUAGE LANG_GERMAN,SUBLANG_GERMAN
STRINGTABLE { 10001, "German" }
LANGUAGE LANG_FRENCH,SUBLANG_FRENCH
STRINGTABLE { 10001, "French" }
Code: [Select]
#include <windows.h>
LANGUAGE LANG_NEUTRAL,SUBLANG_NEUTRAL
STRINGTABLE { 10001, "Neutral" }
For Windows 10:
if there is NEUTRAL language, it is chosen
otherwise ENGLISH
« Last Edit: May 12, 2016, 07:53:22 AM by TimoVJL »
May the source be with you

JohnF

  • Guest
Re: Last Update for FindFile
« Reply #13 on: May 11, 2016, 11:44:52 AM »
What happens with FindFile if you take out the Finnish strings - also not have Frankie's code that sets English anyway? switch/case stuff.

John

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Last Update for FindFile
« Reply #14 on: May 11, 2016, 12:12:35 PM »
I see english texts in Windows 10
But German text in English version Windows 7.
« Last Edit: May 11, 2016, 12:32:49 PM by TimoVJL »
May the source be with you