Page 2 of 2 FirstFirst 12
Results 41 to 53 of 53

Thread: Icon loaded from resource DLL gets blurred, but fine if loaded in IDE

  1. #41
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Icon loaded from resource DLL gets blurred, but fine if loaded in IDE

    You seem to be missing the point.

    What if your ICO lacks the specific size required at run time?

    Sure, if a match is found then the matching size gets used. But if the current DPI settings select a size you don't have then scaling must be done. For example at 175% DPI the form small icon size is 28x28. At 250% it is 40x40.

    It isn't practical to include an image for every possible size that may be needed at run time.

  2. #42
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,997

    Re: Icon loaded from resource DLL gets blurred, but fine if loaded in IDE

    Quote Originally Posted by dilettante View Post
    You seem to be missing the point.

    What if your ICO lacks the specific size required at run time?

    Sure, if a match is found then the matching size gets used. But if the current DPI settings select a size you don't have then scaling must be done. For example at 175% DPI the form small icon size is 28x28. At 250% it is 40x40.

    It isn't practical to include an image for every possible size that may be needed at run time.
    I you don't want to make the icons, maybe. But is is better to make the icons, specially the small ones.

  3. #43
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Icon loaded from resource DLL gets blurred, but fine if loaded in IDE

    I'm only saying you normally don't need more than 4 to 6 sizes. The gaps can be filled in by scaling, and the scaling is done better using the new API calls than the old ones left over from Windows 95 that were based on older 16-bit Windows APIs.

  4. #44
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,997

    Re: Icon loaded from resource DLL gets blurred, but fine if loaded in IDE

    Quote Originally Posted by dilettante View Post
    I'm only saying you normally don't need more than 4 to 6 sizes. The gaps can be filled in by scaling, and the scaling is done better using the new API calls than the old ones left over from Windows 95 that were based on older 16-bit Windows APIs.
    Do you mean in quality?
    What I see is that the 20x20 icon gets scaled very well from the 24x24 icon.

    Besides, unless you need the icon only for the form's caption, in the case that the icon is also used for the app icons, you really need to supply several sizes. At least 16x16, 32x32, 48x48 and 256x256 (I don't remember if other one is required). See for example the sizes Google Chrome has.

    In a previous version of my program I noticed that when it was pinned to the taskbar, in a secondary monitor, a 4K TV at 300% DPI, the icon looked too small. Not when the program was running but when it was pinned but not running.
    It was due to the lack of the 48x48 icon size, even when I had the 256x256 one.
    You can see that many programs have this problem, also the VB6 IDE.

  5. #45
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: Icon loaded from resource DLL gets blurred, but fine if loaded in IDE

    Quote Originally Posted by 7edm View Post
    BTW (at Olaf), I don't think it's "out dated" in anyway to use a resource.dll,
    IMO it definitely is (because it is an MS-specific container-file, which requires MS-platform-APIs to "fill-in" and "read out").

    Quote Originally Posted by 7edm View Post
    it's just a way of storing data, text or binary, in a deliverable way
    ...and I think it's very practical to store this outside of the exe rather than in it.
    Exactly.

    But there are many better suited (multi-platform) SingleFile-Formats, to store multiple resources, as e.g. Files like:
    - MultipleResources.db3 (SQLite-DB-File)
    - MultipleResources.zip (a simple Zip-Archive of your Resource-Folder)

    Both with easier ways to "fill- and later read-out" certain resources (e.g. via "normal SQL").

    Olaf

  6. #46

    Thread Starter
    Addicted Member
    Join Date
    Jun 2010
    Posts
    182

    Re: Icon loaded from resource DLL gets blurred, but fine if loaded in IDE

    Quote Originally Posted by dilettante View Post
    Here is an example that probably does everything you want and more. The only snag is that the Form icon will not appear in IDE runs because it has not yet been compiled into a PE file.

    See the ReadMe.txt file.


    I should have changed the Form2 Caption back to "Child form" since I am loading it modally. I got tired of fiddling with moving the modeless Form2 on top of Form1.

    The code might also work with the RES data created using that weird 3rd party tool. But RC.exe comes with VB6 and it is worth learning.
    I run your example and didn't quite get the same result as you
    Name:  aTestLIWS.png
Views: 283
Size:  44.8 KB

    Another thing I noticed is that your code
    Code:
    Private Sub IfIdeRunApplyCC6ActCtx()
        'Path to the maifest within our Project folder:
        Const CC6_MANIFEST_PATH As String = "\Resources\Application.manifest"
        Dim Success As Boolean
        Dim ACTCTX As ACTCTX
    
        If GetModuleHandle(StrPtr("vb6.exe")) <> WIN32_NULL Then
            'Running in the IDE:
            Success = GetCurrentActCtx(hActCtx) <> WIN32_FALSE
            If Not Success Or hActCtx = WIN32_NULL Then
                'vb6.exe has no manifest, use ours:
                With ACTCTX
                    .cbSize = LenB(ACTCTX)
                    .lpSource = StrPtr(App.Path & CC6_MANIFEST_PATH)
                End With
                hActCtx = CreateActCtx(ACTCTX)
                ActivateActCtx hActCtx, ActCtxCookie
            ElseIf hActCtx <> WIN32_NULL Then
                ReleaseActCtx hActCtx
            End If
            'These just load the libraries:
            IsUserAnAdmin
            InitCommonControls
        End If
    End Sub
    came to the conclusion that my vb6.exe isn't manifested, which is strange as I have indeed manifested it. The call
    Code:
    Success = GetCurrentActCtx(hActCtx) <> WIN32_FALSE
    sets Success to 'True' but hActCtx comes back as 0

    This makes me wonder if there is something wrong with the manifest I use for vb6.exe, pasted below
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
      <assemblyIdentity
        version="6.00.9782.0"
        processorArchitecture="X86"
        name="Visual Basic"
        type="win32"
        />
      <description>Microsoft Corporation VB6</description>
        <dependency>
            <dependentAssembly>
                <assemblyIdentity
                    type="win32"
                    name="Microsoft.Windows.Common-Controls"
                    version="6.0.0.0"
                    processorArchitecture="X86"
                    publicKeyToken="6595b64144ccf1df"
                    language="*"
                 />
            </dependentAssembly>
        </dependency>
        <dependency>
            <dependentAssembly>
                <assemblyIdentity
                    type="win32"
                    name="Microsoft.Windows.GdiPlus"
                    version="1.1.0.0"
                    processorArchitecture="X86"
                    publicKeyToken="6595b64144ccf1df"
                    language="*"
                 />
            </dependentAssembly>
        </dependency>
    <!-- Identify the application as DPI-aware: Vista and above -->
      <asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
          <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
            <dpiAware>true</dpiAware>
          </asmv3:windowsSettings>
      </asmv3:application>
    </assembly>
    M$ vs. VB6 = The biggest betrayal and strategic mistake of the century!?

  7. #47
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Icon loaded from resource DLL gets blurred, but fine if loaded in IDE

    Quote Originally Posted by 7edm View Post
    I run your example and didn't quite get the same result as you
    Runs in the IDE will not use the "capsule" icon because (as already stated) there is no compiled-in icon resource yet, you are not running a compiled EXE. The RES file cannot be used directly.

    Quote Originally Posted by 7edm View Post
    Another thing I noticed is that your code...

    came to the conclusion that my vb6.exe isn't manifested, which is strange as I have indeed manifested it. The call
    Code:
    Success = GetCurrentActCtx(hActCtx) <> WIN32_FALSE
    sets Success to 'True' but hActCtx comes back as 0
    Then you have no valid manifest applied to VB6.exe, it should be as simple as that. As the docs say:

    This function can return a null handle if no activation contexts have been activated by this thread. This is not an error.
    Quote Originally Posted by 7edm View Post
    This makes me wonder if there is something wrong with the manifest I use for vb6.exe, pasted below
    Lots of problems with that manifest. Illegal assemblyIdentity.name (should not have spaces):

    name

    Uniquely names the application or assembly. Use the following format for the name: Organization.Division.Name. For example Microsoft.Windows.mysampleApp. Required.
    Missing a "Longhorn-aware" entry (completed trustInfo section):

    Adding trustInfo isn't essential, but it is highly recommended, even when your app doesn't need any particular UAC-related behavior. In particular, if you don't add trustInfo at all, then 32-bit x86 versions of your app will be subject to UAC file virtualization, which allows writes to administrator-privileged folders like the Windows system folders to succeed when they would otherwise fail, but redirects them to a user-specific "VirtualStore" folder.
    I'm not sure what happened but it sounds like something did. Maybe you are running a virtualized copy of VB6.exe with no manifest, or maybe your manifest was only applied to a virtualized copy and you are running the real copy with no manifest.

    I doubt the spaces in "name" caused a failure... or VB6.exe should die with a SxS failure exception when run.

    How did you get such a broken manifest anyway? How did you apply it to VB6?

  8. #48
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Icon loaded from resource DLL gets blurred, but fine if loaded in IDE

    I started researching the problem.

    Your VB6.exe manifest may well be fine. That testing code does not seem to do what I had expected, so that problem is mine. Working on it.

  9. #49
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Icon loaded from resource DLL gets blurred, but fine if loaded in IDE

    Sadly it looks like the thread's initial activation context actually is "number 0" or NULL. So, manifest or not, a NULL comes back from GetCurrentActCtx() calls until you have pushed a new context onto the stack.

    Here is the corrected Module1.bas, which always applies the Project's manifest on IDE runs, whether VB6.exe has one or not:

    Code:
    Option Explicit
    
    'NOTE: Since we embed the manifest as a resource, most of this code doesn't
    '      have to run in the compiled program.  It is only here for IDE runs.
    
    Private Const WIN32_NULL As Long = 0
    
    Private Declare Function ActivateActCtx Lib "Kernel32" ( _
        ByVal hActCtx As Long, _
        ByRef Cookie As Long) As Long
    
    Private Type ACTCTX 'ACTCTXW
        cbSize As Long
        dwFlags As Long
        lpSource As Long
        wProcessorArchitecture As Integer
        wLangId As Integer
        lpAssemblyDirectory As Long
        lpResourceName As Long
        lpApplicationName As Long
        hModule As Long
    End Type
    
    Private Declare Function CreateActCtx Lib "Kernel32" Alias "CreateActCtxW" ( _
        ByRef ACTCTX As ACTCTX) As Long
    
    Private Enum DEACTIVATE_ACTCTX_FLAGS
        DEACTIVATE_ACTCTX_FLAG_NORMAL = 0
        DEACTIVATE_ACTCTX_FLAG_FORCE_EARLY_DEACTIVATION = 1
    End Enum
    
    Private Declare Function DeactivateActCtx Lib "Kernel32" ( _
        ByVal dwFlags As DEACTIVATE_ACTCTX_FLAGS, _
        ByVal Cookie As Long) As Long
    
    Private Declare Function GetModuleHandle Lib "Kernel32" Alias "GetModuleHandleW" ( _
        ByVal pModuleName As Long) As Long
    
    Private Declare Function InitCommonControls Lib "Comctl32" () As Long
       
    Private Declare Function IsUserAnAdmin Lib "Shell32" () As Long
    
    Private Declare Sub ReleaseActCtx Lib "Kernel32" (ByVal hActCtx As Long)
    
    Private hActCtx As Long
    Private ActCtxCookie As Long
    
    Private Sub IfIdeRunApplyCC6ActCtx()
        'Path to the maifest within our Project folder:
        Const CC6_MANIFEST_PATH As String = "\Resources\Application.manifest"
        Dim ACTCTX As ACTCTX
    
        If GetModuleHandle(StrPtr("vb6.exe")) <> WIN32_NULL Then
            'Running in the IDE, apply our manifest:
            With ACTCTX
                .cbSize = LenB(ACTCTX)
                .lpSource = StrPtr(App.Path & CC6_MANIFEST_PATH)
            End With
            hActCtx = CreateActCtx(ACTCTX)
            ActivateActCtx hActCtx, ActCtxCookie
        End If
        'These just load the libraries:
        IsUserAnAdmin
        InitCommonControls
    End Sub
    
    Private Sub RemoveCurrentActCtx()
        If ActCtxCookie <> WIN32_NULL Then
            DeactivateActCtx DEACTIVATE_ACTCTX_FLAG_NORMAL, ActCtxCookie
            ReleaseActCtx hActCtx
        End If
    End Sub
    
    Private Sub Main()
        IfIdeRunApplyCC6ActCtx
        Form1.Show
        RemoveCurrentActCtx
    End Sub
    Note the lines in red defining where the Project's .manifest file is.

  10. #50
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Icon loaded from resource DLL gets blurred, but fine if loaded in IDE

    Ok after more fiddling this one just sets Form icons from the resources of a PE file (DLL, EXE, OCX, etc.). For example a resource DLL as requested.

    As long as VB6.exe and your compiled programs both have a CC6 manifest you shouldn't need Module1. Er, well aside from forcing library loading early and in the correct sequence for Shell32.dll and Comctl32.dll at least.

    Remember, often when you use version 6 of Comctl32.dll without doing this you can experience mysterious spontaneous crashes. That issue might be gone in Windows 10 (at least I haven't seen it) but the calls don't hurt. You could also just call LoadLibrary() on those libraries in the correct sequence instead as well.


    This run was at 200% DPI, which picks larger Form icon sizes than at 100%. The manifest used declares DPI Awareness.

    Name:  sshot.png
Views: 217
Size:  4.0 KB

    Here those larger "small icons" were originally drawn by Microsoft with more of a 3-D look than those retrieved at 100%. And if the icon source does not have exactly the image size needed this code still does a proper scaledown from the next larger available size. This gives better quality in such cases.
    Attached Files Attached Files

  11. #51

    Thread Starter
    Addicted Member
    Join Date
    Jun 2010
    Posts
    182

    Re: Icon loaded from resource DLL gets blurred, but fine if loaded in IDE

    Thanks a lot dilettante, I will try this out as well. After making the change above to the other project I was able to run it successfully, except for that it didn't show a form icon in IDE, but did so when compiled to exe. Not sure yet if your latest one does the trick to show the form icon in IDE or not, but I cannot for my life believe that wouldn't be possible, even if it's not crucial as long as it show in the executable.

    As for manifest, you asked earlier how I apply it to vb6.exe? I put it in a .rc file as a XML resource and then link it to vb6.exe, the same way as I do with my own executable - using Resource Builder (a similar tool to Resource Hacker, but maybe a bit more styled and possibly more advanced).

    For the record, I paste below the manifest I use for my executable, as you mentined something about "trustInfo" and "Longhorn" and at least I do have the former there, if it's correct and can I add this infor to vb6.exe manifest to make it "safer"?
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <assembly xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0">
      <assemblyIdentity
        version="6.6.0.0"
        processorArchitecture="X86"
        name="Astrocalc"
        type="win32"
        />
      <description></description>
        <dependency>
            <dependentAssembly>
                <assemblyIdentity
                    type="win32"
                    name="Microsoft.Windows.Common-Controls"
                    version="6.0.0.0"
                    processorArchitecture="X86"
                    publicKeyToken="6595b64144ccf1df"
                    language="*"
                 />
            </dependentAssembly>
        </dependency>
    <!-- Identify the application security requirements: Vista and above -->
      <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
          <security>
            <requestedPrivileges>
              <requestedExecutionLevel
                level="asInvoker"
                uiAccess="false"
                />
            </requestedPrivileges>
          </security>
      </trustInfo>
    <!-- Identify the application as DPI-aware: Vista and above -->
      <asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
          <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
            <dpiAware>true</dpiAware>
          </asmv3:windowsSettings>
      </asmv3:application>
    </assembly>
    M$ vs. VB6 = The biggest betrayal and strategic mistake of the century!?

  12. #52
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Icon loaded from resource DLL gets blurred, but fine if loaded in IDE

    Quote Originally Posted by 7edm View Post
    Thanks a lot dilettante, I will try this out as well. After making the change above to the other project I was able to run it successfully, except for that it didn't show a form icon in IDE, but did so when compiled to exe. Not sure yet if your latest one does the trick to show the form icon in IDE or not, but I cannot for my life believe that wouldn't be possible, even if it's not crucial as long as it show in the executable.
    As long as the icon is loaded from a compiled PE file (like a DLL) then you should see the icon when you run your program within the IDE.

    But during IDE runs your program doesn't have any actual resources for icon APIs to load from. There is only the .RES file, which is not known or usable by Windows APIs like LoadIcon, LoadImage, etc. That's a problem for all resource-reading APIs during VB6 IDE runs.

    VB6 has some hacks to simulate resources based on a .RES file before compilation. For IDE runs, these hacks redirect certain operations to winkle data out of the .RES file. In the compiled EXE these hacks redirect to look in the resources instead. Windows icon APIs don't know anything about those private hacks, so they fail in IDE runs.
    Last edited by dilettante; Mar 2nd, 2021 at 12:28 PM.

  13. #53
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Icon loaded from resource DLL gets blurred, but fine if loaded in IDE

    Quote Originally Posted by 7edm View Post
    As for manifest, you asked earlier how I apply it to vb6.exe?
    I had asked, but a while back I realized this was a red herring.

    Your manifest is probably just fine, though the version you just posted lacks a proper strong name. "Astrocalc" could clash with other programs, which is why it should really be something more like "Joe.Blow.Software.Asctrocalc" less likely to match somebody else's manifests.

    The assemblyIdentity is used by Windows to create a key used in the activation context cache. The manifest is not compiled every program run unless the creation timestamp changes, assemblyIdentity changes (e.g. the version in it), or if it is not found when the cache-lookup is done.

    Without a unique key Windows may well apply some other program's activation context to your run.


    The comments are a little dicey. For example trustInfo does more than specify UAC settings (not "security" though I can see how some might get confused) requirements. It also marks your program as "non-legacy" which impacts how Windows applies appcompat shims.
    Last edited by dilettante; Mar 2nd, 2021 at 12:43 PM.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width