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

Welcome Guest. Please Login or Register.
Jul 24th, 2017, 7:41pm


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 104 times)
BeeTrap
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 20
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.
http://libertybasic.conforums.com/index.cgi?board=api&action=display&num=1158874325

Last piece of the puzzle for my program. Thanks bluatigro.
"borderles fulscreen"
http://libertybasic.conforums.com/index.cgi?board=tips&action=display&num=1277032314

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.
http://libertybasic.conforums.com/index.cgi?board=software&action=display&num=1498271443

Here is my idea, don't laugh, I have been really bored!
Code:
'- 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, _
        rcMonitor.top    As Long, _
        rcMonitor.right  As Long, _
        rcMonitor.bottom As Long, _
        rcWork.left      As Long, _
        rcWork.top       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 - 10, _
        MonitorInfo(2,2) + UpperLeftY,_
        WindowWidth + 20, WindowHeight + 20, _SWP_NOZORDER or _SWP_NOSIZE

    cls
    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

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

    goto [key]

Wait

[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
    end if

Wait

'-------------
[quit]
 close #m
END
'-------------

'------------------------------------------------------------------
'--- 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
    Else
        '--- found secondary monitor.                                       '--- could use this info.......
        UpperLeftX   = MonitorInfo.rcWork.left.struct                       '----- we don't get the "array" data in REPLY #12
        UpperLeftY   = MonitorInfo.rcWork.top.struct                        '------- that was in REPLY # 14!
        WindowWidth  = MonitorInfo.rcWork.right.struct  - MonitorInfo.rcWork.left.struct
        WindowHeight = MonitorInfo.rcWork.bottom.struct - MonitorInfo.rcWork.top.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.
« Last Edit: Jul 1st, 2017, 1:58pm 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