Results 1 to 4 of 4

Thread: VB6 QUESTION: How to direct GDI+ output onto second monitor?

  1. #1

    Thread Starter
    PowerPoster yereverluvinuncleber's Avatar
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    2,235

    VB6 QUESTION: How to direct GDI+ output onto second monitor?

    Chaps,

    I have a VB6 graphical app using GDI+ that needs the option to output the graphics on a second display.



    I currently can't make it do this as it only displays on the primary monitor.

    By default the GDI app is placed on the primary monitor at a particular pixel position a hundred or so pixels from the left of the display. It works and looks good.

    One of the config. options is to select the second or third monitors if they are attached to the system.

    I have a function that calls EnumDisplayMonitors with a callback function and for the particular monitor in question it does a createDC to get a hardware context for the second monitor. Despite getting that DC and feeding it to GDI+ it does not seem to do anything always placing the GDI+ output on the primary monitor.

    Code:
    Public Sub getDeviceHdc()
        Dim iCount As Long
    
        On Error GoTo getDeviceHdc_Error
    
            specifiedMonitor = Val(rDMonitor) + 1
            EnumDisplayMonitors 0, ByVal 0&, AddressOf hdcEnumProc, iCount 'callback that calls all monitors
    
        On Error GoTo 0
        Exit Sub
    
    getDeviceHdc_Error:
    
         MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure getDeviceHdc of Module Module1"
    End Sub
    
    
    Private Function hdcEnumProc(ByVal hMonitor As Long, ByVal hDCMonitor As Long, uRect As RECT, dwData As Long) As Long
        'Dim hdc As Long
        Dim nDC As Long
    
        dwData = dwData + 1 ' Increment monitor number as we loop through any attached monitors
    
        'get the data from the specified monitor only
        If specifiedMonitor = dwData Then
    '            hdc = GetDC(0) 'get an hDC directly to the screen
    '            hdcScreen = hdc
    
            'Create Device Context Compatible With Screen
            nDC = CreateDC("DISPLAY", vbNullString, vbNullString, ByVal 0&)
            hdcScreen = nDC
    
        End If
    
        hdcEnumProc = 1
    End Function
    GDI+ does its stuff as expected, the following are the extracts from my code where the DC is passed as a variable.

    Code:
        
        ' A handle to the Device Context (HDC) is obtained before output is written and then released after elements have been written.
        ' Get a device context compatible with the screen
        dcMemory = CreateCompatibleDC(hdcScreen)
    
        UpdateLayeredWindow Me.hWnd, hdcScreen, ByVal 0&, apiWindow, dcMemory, apiPoint, 0, funcBlend32bpp, ULW_ALPHA
    In my enumerate devices code I had previously tried GetDC to no avail. Trawling through t'net I have seen rumours that getDC may not be so useful on multi-monitor systems and then found some C++ code using CreateDC that appeared to do what I wanted. Regardless of which API I use the code all runs, no errors, the DC is created but the output is always on the same primary monitor.

    I have played with pixel placement and it just goes off screen.

    Can you please tell me if I am doing something fundamentally wrong or if there is a trick to it all that I am missing?

    Running Windows 7 64bit on a Dell E6410 laptop with a second monitor plugged into the VGA port.

    Awaiting with anticipation as I am really stuck on this one.

    PS. Apologies for being absent for so long and just asking for help as soon as I turn up again, family issues have kept me away from all coding and all other pleasurable activities.
    Last edited by yereverluvinuncleber; Sep 23rd, 2020 at 07:55 PM.

  2. #2
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    Re: VB6 QUESTION: How to direct GDI+ output onto second monitor?

    the DC is created but the output is always on the same primary monitor
    I'm very confused with your message.

    The GDI+ will draw something on a form, and the form can be in one monitor or another.

  3. #3

    Thread Starter
    PowerPoster yereverluvinuncleber's Avatar
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    2,235

    Re: VB6 QUESTION: How to direct GDI+ output onto second monitor?

    As always, as soon as you ask the question and someone answers with a response like that, it gets your brain going and you realise the one thing that you have been missing all along is the one thing you haven't been thinking about.

    Eduardo, thanks for your answer and because of it I am back on track again.

    Why is it all programmers stay up too late, stare at the screen for too long and can't see the solution in front of their own face?

  4. #4
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    Re: VB6 QUESTION: How to direct GDI+ output onto second monitor?

    Sometimes is good to take a break, even to watch a movie or do something else for a while.

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