Liberty BASIC Community Forum
« Second Monitor Screen-Blanker, sorta! »

Welcome Guest. Please Login or Register.
Feb 21st, 2018, 11:27am

Rules|Home|Help|Search|Recent Posts|Notification

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Second Monitor Screen-Blanker, sorta!  (Read 592 times)
New Member

member is offline



Gender: Male
Posts: 22
xx Second Monitor Screen-Blanker, sorta!
« Thread started on: Jul 1st, 2017, 11:56am »

Hello, I recently purchased a used, small monitor from a charity store to use as my "second" monitor. I realize that I should have done this a longgggggg time ago.
Anyway, since then and after reading a thread started by Tasp2 about "Open program in a2nd Monitor" I have been toying with an idea. Sure, that was about having the program show on the 2nd monitor, but what if I want to "Blank-out" the 2nd monitor while my super-duper program is on the main one. This is what I came up with. But first.....

Main Influence was:
"Opening Program In A 2nd Monitor", Thanks Tasp2, Stefan Pendl and Brent Thorn.

Last piece of the puzzle for my program. Thanks bluatigro.
"borderles fulscreen"

and now that I have a second monitor, this idea from Mr. Gundel is very handy! Great to view code from 2 sources and/or revisions. "Scripting.. " video.

Here is my idea, don't laugh, I have been really bored!
'- copy/pasted code 06-24-2017
'- went back to thread, AGAIN, to get Stefan Pendl's post, (Reply #7),
'- that Brent Thorn must have modified the "callback function" for.
'- Modification was to focus on second monitor >> see Reply #12 on Thread.
'- I had tried Thorn's "function" with Pendl's REPLY 14 code before and
'- it did not act as I "Guessed" that it would.  "Guessed", mind you!
'- I just need the "bare-bones" code to force/place a prog/window onto 2nd monitor.
'- Reference only: My Main monitor, #1, is to the right of smaller monitor #2.
'- Program user >>> MAY/Probably Will <<< have to change numeric and/or variable values to suit.
'- Works as of 06-30-2017, crudely, but does what I asked of it!
'- NOTICE: I have used/manipulated this code for my purposes only.
'- I make no claim to creation of it or to its value to anyone else!  (cwr aka "BeeTrap")
'- 06-30-2017 working on adding "bluatigro's" code for "escape" method with [Esc] key.
'---- I thank Tasp2 for asking the question, Stefan Pendl and Brent Thorn for their answers and
'----- bluatigro for the final piece of the puzzle, "BeeTrap".

    Global WindowCount                                             '--- window management

    dim MonitorInfo(3,4)                                           '--- copied from Pendl RE # 14, cwr, failed without it, duh!

    Struct MonitorInfo, _
        cbSize           As ULong, _
        rcMonitor.left   As Long, _    As Long, _
        rcMonitor.right  As Long, _
        rcMonitor.bottom As Long, _
        rcWork.left      As Long, _       As Long, _
        rcWork.right     As Long, _
        rcWork.bottom    As Long, _
        dwFlags          As ULong

    '--- get address of callback function                          '--- the "magic"?  Thorn's modification
    Callback lpfnEnumProc, _
        MonitorEnumProc( ULong, ULong, ULong, ULong ), Long

    '--- start enumerating monitors and opening windows
    CallDLL #user32, "EnumDisplayMonitors", _
        _NULL        As ULong, _
        _NULL        As ULong, _
        lpfnEnumProc As ULong, _
        0            As ULong, _
        res          As Long

    BackgroundColor$ = "black"                                     '--- cAsE seNsitIvE!  I tend fo forget that!
    ForegroundColor$ = "black"

    '-- bluatigro -- Code: -- to "stop" program effects.
    graphicbox #m.g , 0,0, MonitorInfo(2,1), MonitorInfo(2,2)      '--- monitor #2 filled with black, on mine at least!
'    graphicbox #m.g , 10, 10, 100, 100                            '--- displays small white-outlined square, then white-filled square

    open "" for window_popup as #m

    print #m, "trapclose [quit]"                                   '--- exit route

    #m.g "setfocus"
    #m.g "when characterInput [key]"

    call SetWindowPos hWnd(#m), 0, _
        MonitorInfo(2,1) + UpperLeftX, _
        MonitorInfo(2,2) + UpperLeftY,_
        WindowWidth, WindowHeight, _SWP_NOZORDER or _SWP_NOSIZE

    print " " : print "  10 second TIMER is Running..........."
    print " " : print "  Please wait for TIMER to expire, or change value."
    print " " : print "  NOTICE: Your program/code could be running here!"

    '--- 10 second sleep "calldll" is from NewsLetter #138
    '---- to all newbies.... look at all of the NewsLetters!
    calldll #kernel32, "Sleep", 10000 as ulong, r as void

    print " " : print " this program has finished its run, you may exit now."
    print " " : print " press the [Esc] key to clear Monitor 2."

    goto [key]


    Key$ = right$( Inkey$ , 1 )
    if Key$ = chr$( _VK_ESCAPE ) then
        close #m                                '--- close the "window_popup" on 2nd monitor
        cls                                     '---- clear mainwindow on main monitor
    end if


 close #m

'--- Brent Thorn ---- Reply #12 on: Sep 23rd, 2006, 5:59pm
Function MonitorEnumProc( hMonitor, hdcMonitor, lprcMonitor, dwData )
    MonitorInfo.cbSize.struct = Len(MonitorInfo.struct)

    CallDLL #user32, "GetMonitorInfoA", _
        hMonitor As ULong, _
        MonitorInfo As Struct, _
        res As Long

    bPrimary = ((MonitorInfo.dwFlags.struct And 1) <> 0)

    If bPrimary Then
        '--- keep looking...
        MonitorEnumProc = 1
        '--- found secondary monitor.                                       '--- could use this info.......
        UpperLeftX   = MonitorInfo.rcWork.left.struct                       '----- we don't get the "array" data in REPLY #12
        UpperLeftY   =                        '------- that was in REPLY # 14!
        WindowWidth  = MonitorInfo.rcWork.right.struct  - MonitorInfo.rcWork.left.struct
        WindowHeight = MonitorInfo.rcWork.bottom.struct -

        MonitorEnumProc = 0
    End If
End Function

'--- replaced the original REPLY # 7 "function" with "sub" from REPLY # 14
'.... function SetWindowPos(hWnd, hWndInsertAfter, PosX, PosY, Width, Height, uFlags)....
sub SetWindowPos hWnd, hWndInsertAfter, PosX, PosY, Width, Height, uFlags   '<<<--- important
    calldll #user32, "SetWindowPos", _
        hWnd            as ulong,_
        hWndInsertAfter as ulong,_
        PosX            as long,_
        PosY            as long,_
        Width           as long,_
        Height          as long,_
        uFlags          as ulong,_
        result          as boolean
end sub

'--- end of code --- 4 or 5 different sources, thanks for the code/idea(s) ---

Added this to thank alincon2001. alincon2001's question in a thread, "Two Monitors" under the "General Board", is what got me started. Thanks to alincon2001 also.
Edit 07-31-2017 -- removed unnecessary "math" in "call SetWindowPos...". Not sure what it was for!
« Last Edit: Jul 31st, 2017, 09:14am by BeeTrap » User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls