Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting VB Code to VFP to Increase File Icon Size in Windows 1

Status
Not open for further replies.

mydocpro

Technical User
Mar 13, 2016
48
US
Greetings! I've been trying to resize (jpg) "Medium Icons" in Windows Explorer (programmatically) ... and found the VB code below. Do any of you know if VFP-9 can accomplish this, else vb-script or java-script or other idea. I've searched for hours. Utmost thanks/blessings for any thoughts:

'SendMessageTimeout values
Const HWND_BROADCAST = &HFFFF
Const WM_SETTINGCHANGE = &H1A
Const SPI_SETNONCLIENTMETRICS = &H2A
Const SMTO_ABORTIFHUNG = &H2

Declare Integer Function SendMessage Timeout Lib "user32" Alias "SendMessageTimeoutA" (ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long, ByVal fuFlags As Long, ByVal uTimeout As Long, lpdwResult As Long) As Long

Dim icon_size
Dim new_icon_size
Dim result
Dim SysVarReg
Set SysVarReg = WScript.CreateObject("WScript.Shell")
' Get the current icon size.
icon_size = SysVarReg.RegRead ("HKCU\Control Panel\Desktop\WindowMetrics\Shell Icon Size")
' Increase the value by 1.
new_icon_size = CInt(icon_size) + 1
SysVarReg.RegWrite "HKCU\Control Panel\Desktop\WindowMetrics\Shell Icon Size", new_icon_size
' Send HWND_BROADCAST to refresh the icons.
SendMessageTimeout HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETNONCLIENTMETRICS, 0, SMTO_ABORTIFHUNG, 10000, result
' Restore the original value.
SysVarReg.RegWrite "HKCU\Control Panel\Desktop\WindowMetrics\Shell Icon Size", icon_size
' Send HWND_BROADCAST to refresh the icons again.
SendMessageTimeout HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETNONCLIENTMETRICS, 0, SMTO_ABORTIFHUNG, 10000, result
 
Changing things like font standard size, screen resolution, and many things more including icon sizes is acting upon windows system settings each user should have under his control and personal preferences. There are those with eyesight problems wanting big icons, for example. Software acting on such things is regarded impolite to say the least.

I'm just saying this so you think twice about how to solve that problem by other means, eg teaching users to make that setting in Windows, if they really want it. In this case it's really just telling them about a right click and leading them to the menu item for small icons.

I won't translate the whole thing, but there is not much info needed besides DIM being the VB command to declare variables, Const being what we have with #DEFINE and giving you any declaration needed to use Win32 API functions.

Bye, Olaf.
 
Very well, thank you, Olaf. The problem is actually in the VFP webbrowser activeX object (using the Navigate() method) (i.e., Windows Explorer) ... which only initiates "small" and "medium" explorer icons, iirc. (the 2 webbrowser classes, iirc, exist in the VFP solutions directory somewhere)

The physician oft glances to see patient records (xrays and photos) within this excellent VFP webbrower activeX object of their (EHR) form. The "large icon" provides his/her ideal preview of the jpeg within VFP's webbrowser, without having to double click the jpeg file to view it.

Note: There was a time Craig Boyd dealt with this issue of previewing photos using VFP's webbrowser object. (that webbrowser only displays small icons (after issuing the Navigate() method))
Sorry I didn't clarify the scenario.

I've tried (repeatedly) translating the code above but failed, thinking it is not translatable to VFP. I've gone through 'dark-city' loops trying to sign up as a member of But your validating it is translatable should help.

Again, Utmost thanks, Olaf!

Philip
 
Well, changing the registry entry of HKCU\Control Panel\Desktop\WindowMetrics\Shell Icon Size is a system wide change.
I never had a membership in news2news, still all declarations are there, you just need the pure declarations in this case anyway.

As you only want to change this webbrowser control iconsize, you have a property for that.
Add a Button with Click:

Code:
thisform.webbrowsercontrol.Document.IconSize = 96

The three typical sizes are 48,96, and 256.

Bye, Olaf.

 
Resolved: Utmost thanks/blessings, Olaf. Your code is perfect.

(I am duly amazed ... I went hours researching a solution and now very appreciate your property-solution.)

Thanks again,
Philip
 
I found that at Stackoverflow.

Anyway it's not easily discovered, as Intellisense does not go as deep as Document properties at design time. Meaning: While you program your code the browser control has no document loaded, so you'd have to look up in the IE Document Object Model (DOM) and I don't even find IconSize mentioned there.

Bye, Olaf.
 
Thanks Olaf,

I've used o.documentComplete method with your code, quite well, and it allows nice 'odd' sizes from 24 to 256 (as you suggested).

I'm pretty new to the DOM ... so studied it and StackOverflow.com today. I hope to overcome the learning curve if feasible ... without vexing you and others.

For example, It would be nice to be able programmatically sort and filter [*.jpg] or [*.pdf] files to view in Windows Explorer (i.e., the Webbrowser).

Again, utmost thanks/blessings for your pearls and for helping so many of us aspiring programmers. I will continue to study.

Philip
 
Well, the DOM is more about the typical HTML document, perhaps also XML, but not the IE special modes for directories.

And you'd have lots to study, if you study StackOverflow, you could also say you want to study tek-tips, you'll never get top the end of it...

If you want more control about the inner workings of a directrory preview you better program your own with a grid and image controls. It'd be a lot of work, though. You're in the compromise situation, you use something, that gives you a lot from a single line of browser.navigate2(dir), but to gain more control, you need overcomplicated code to send windows messages to that control to do things. I fear there won't be properties for every need.

Bye, Olaf.
 
Thanks Olaf, I chose a 'sifted' DOS command vs. the DOM nightmare (and other languages) to filter ('hidden' attribute):

RUN /N7 ATTRIB +H "c:\dpw_archive\*.pdf" /S

The wild-card avoids 100's of recursion lines (i.e. using ADIR() + SetFileAttributes(@cFilename,FILE_ATTRIBUTE_HIDDEN) ... etc. (
...(the DOS seems about 'as fast' anyway as other API calls (I may be wrong) ))

Again utmost thanks and blessings, Olaf for encouraging me through this.
Philip Traynor, DPM

Addendum:

1) Added the "/S" to the RUN command (above) to recurse all subdirectories. It takes about 8 seconds to hide files (several thousand) using the attributes filter.

2) Also added CurrentViewMode of the DOM:
Thisform.webbrowser.Document.CurrentViewMode = 3 &&3 works well and hides text
Thisform.webbrowser.Document.IconSize = 170 &&157 &&24,48,96,256
 
Overall it makes me wonder, if it wouldn't be much simpler to call GETPICT("jpg") after CD into the directory of your choice.
You're back to defining the viewmode and IconSize then, but it covers only showing file types of your choice.

It now depends what's more important. I still think any user should be able to set view mode and icon size at least after being shown how to. Hiding files to filter what you still see is a bit off the track.

Bye, Olaf.

 
Olaf:

The GetPict("jpg") (medium icon) function would invoke redundant clicking, etc.? --> decreased productivity. If it comes to that, we'd simply skip the DOS filter aspect ...

Currently, things seem exciting for this particular physician. We've also menu'd the <Document.CurrentViewMode = 3> so users can decrease iconsize to listview (in 'o.docuemntcomplete' method) as well.

Currently, the webbrowser object (with pictorial thumbnails (Xrays, photos, ultrasounds, wounds, etc.) is strategically beside the progress note (memo field) ...
We've re-tested your document.iconsize solution plus the DOS filtering (<3 seconds): as one simple global menu switch: Fortunately, this spares the physician lost-time and fumbling (for patient photos, etc.) ... (as he juggles critical note routines and patient interaction):
...
Case Bar()=5
Release pIconSizeOK && default thumbnail icons
Run /N7 Attrib -H "c:\dpw_archive\*.pdf" /S
Run /N7 Attrib -H "c:\dpw_archive\*.txt" /S
Run /N7 Attrib -H "c:\dpw_archive\*.doc" /S
Run /N7 Attrib -H "c:\dpw_archive\*.docx" /S
Run /N7 Attrib -H "c:\dpw_archive\*.xls" /S
Run /N7 Attrib -H "c:\dpw_archive\*.xlsx" /S
Case Bar()=6
Public pIconSizeOK && Allow: document.iconsize = 170
Run /N7 Attrib +H "c:\dpw_archive\*.pdf" /S
Run /N7 Attrib +H "c:\dpw_archive\*.txt" /S
Run /N7 Attrib +H "c:\dpw_archive\*.doc" /S
Run /N7 Attrib +H "c:\dpw_archive\*.docx" /S
Run /N7 Attrib +H "c:\dpw_archive\*.xls" /S
Run /N7 Attrib +H "c:\dpw_archive\*.xlsx" /S

Hypothetically, it could eventually recursively "ADIR()" with 'NEWS32' (instead of DOS) (to help avoid clashes with admins (... who hardly access the pdfs anyway)).
Unfortunately, EHRs have oft been 'quirky'. They remain far from bullet-proof. Not all physicians can survive EHRs. Small practices require efficiency at the expense of quirkiness.
Utmost thanks/blessings for your continued compassionate wisdom in this matter, Olaf!
 
If this is all about best performance, a solution creating your own image preview would be best.

Also if this is about a current patient, the pictures could be put into a "recent" dir and not interfere with everything else not mattering at the moment. At least, you could sort files by type in different folders. This is all data and you should be able to organize this in the best way. If you say there has to be a compromise to get at files without the software simply in Windows Explorer, then you don't need to make that compromise anyway, you can copy files and store them double, once for manual browsing and once for best fit to your software.

You're dealing with a very detail level, when there are many possibilities on a higher level. A typical sign of being routine-blinded.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top