Results 1 to 6 of 6

Thread: [VB6] Select the CC6 Assembly in IDE Runs

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    [VB6] Select the CC6 Assembly in IDE Runs

    Sometimes people will take the tacky and somewhat problematic step of applying a Common Controls 6.0 manifest to VB6.exe. This seems to be about trying to test CC6 features within IDE runs.

    Instead of that you can simply use the Activation Context API to select CC6 within IDE runs where you want this action to occur.

    Here we have a "CC6" manifest for the IDE located within the Project folder and make use of it within Sub Main( ):

    Code:
    Option Explicit
    
    Private Declare Function ActivateActCtx Lib "kernel32" ( _
        ByVal hActCtx As Long, _
        ByRef Cookie As Long) As Long
    
    Private Type 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 CreateActCtxW Lib "kernel32" (ByRef ACTCTXW As ACTCTXW) As Long
    
    Private Declare Function DeactivateActCtx Lib "kernel32" ( _
        ByVal dwFlags As Long, _
        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 Sub InitCommonControlsVB()
        Const CC6_MANIFEST As String = "\CC6.manifest"
        Dim ACTCTXW As ACTCTXW
        Dim ActCtxCookie As Long
    
        If GetModuleHandle(StrPtr("vb6.exe")) <> 0 Then
            With ACTCTXW
                .cbSize = LenB(ACTCTXW)
                .lpSource = StrPtr(App.Path & CC6_MANIFEST)
            End With
            ActivateActCtx CreateActCtxW(ACTCTXW), ActCtxCookie
            IsUserAnAdmin
            InitCommonControls
            DeactivateActCtx 0, ActCtxCookie
        Else
            IsUserAnAdmin
            InitCommonControls
        End If
    End Sub
    
    Private Sub Main()
        InitCommonControlsVB
        Form1.Show
    End Sub

    Name:  sshot IDE.png
Views: 682
Size:  2.1 KB

    IDE Run


    Name:  sshot EXE.png
Views: 616
Size:  1.7 KB

    Compiled EXE Run (reverts to the default CC5 assembly)


    This allows you to load the CC6 assembly for IDE runs.

    If you want to do this in runs of the compiled EXE you would embed a full-featured manifest into it as a resource with ID = #1 and Type = #24. Such run-time manifests have no effect during IDE runs.

    Voila. No need to hack up VB6.exe and risk the consequences for all programs. You'd only use this logic for cases where you want to do IDE testing with CC6 selected.
    Attached Files Attached Files

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: [VB6] Select the CC6 Assembly in IDE Runs

    Ok, this has quit working.

    I need to do a bit more fiddling to figure out why it worked before and now has quit after re-running the IDE once again.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: [VB6] Select the CC6 Assembly in IDE Runs

    So much for trying to be clever. This clearly needs more work.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: [VB6] Select the CC6 Assembly in IDE Runs

    This version seems reliable without crashing the IDE, replace Module1.bas:

    Code:
    Option Explicit
    
    Private Declare Function ActivateActCtx Lib "kernel32" ( _
        ByVal hActCtx As Long, _
        ByRef Cookie As Long) As Long
    
    Private Type 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 CreateActCtxW Lib "kernel32" (ByRef ACTCTXW As ACTCTXW) As Long
    
    Private Declare Function DeactivateActCtx Lib "kernel32" ( _
        ByVal dwFlags As Long, _
        ByVal Cookie As Long) As Long
    
    Private Declare Function GetCurrentActCtx Lib "kernel32" (ByRef hActCtx 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 ActCtxCookie As Long
    
    Private Sub InitCommonControlsVB()
        Const CC6_MANIFEST As String = "\CC6.manifest"
        Dim Success As Boolean
        Dim hActCtx As Long
        Dim ACTCTXW As ACTCTXW
    
        If GetModuleHandle(StrPtr("vb6.exe")) <> 0 Then
            Success = GetCurrentActCtx(hActCtx) <> 0
            If Not Success Or hActCtx = 0 Then
                With ACTCTXW
                    .cbSize = LenB(ACTCTXW)
                    .lpSource = StrPtr(App.Path & CC6_MANIFEST)
                End With
                ActivateActCtx CreateActCtxW(ACTCTXW), ActCtxCookie
            End If
            IsUserAnAdmin
            InitCommonControls
        Else
            IsUserAnAdmin
            InitCommonControls
        End If
    End Sub
    
    Private Sub Main()
        InitCommonControlsVB
        Form1.Show
        If ActCtxCookie <> 0 Then DeactivateActCtx 0, ActCtxCookie
    End Sub
    Something strange is going on with the timing of the creation of the default instance of Form1.


    This attachment adds a Form2, which gets shown by clicking the button on Form1.
    Attached Files Attached Files
    Last edited by dilettante; Dec 24th, 2018 at 02:14 AM.

  5. #5
    Member
    Join Date
    Aug 2016
    Posts
    50

    Re: [VB6] Select the CC6 Assembly in IDE Runs

    Hello,
    Is you put a Option Control inside a Frame Option, the Option Control is black.

    The Example:
    Name:  vb6.png
Views: 445
Size:  13.8 KB

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: [VB6] Select the CC6 Assembly in IDE Runs

    I'm not sure anyone is seeing that problem in the post-XP world. It doesn't occur on Windows 10.

    The old hack for that was to always place such controls within a PictureBox.

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