WinPopUp

User projects written in or related to FreeBASIC.
Post Reply
xbgtc
Posts: 250
Joined: Oct 14, 2007 5:40
Location: Australia

WinPopUp

Post by xbgtc »

WinPopUp is a program for messaging on a LAN using text files.
New Win10 version does 3 computers and should work on any windows.

What the program does:

1. Send/Receive messages between 3 computers on a network.
2. Start up and shutdown the computers (only wired lans for startup).
3. @loop command for testing. Precede message with "@loop" to a computer and that computer will send it back if all is ok.
4. Upon startup shows the status of computers configured in winpopup.cfg.
5. Hitting return with no text will clear messages and minimize program then upon receiving a message will pop back up to show message.
6. Messages are 1 line only (about 86 characters depending on names and what size screen you use. currently 736x400 and 92x25 text).
7. ESC will exit anytime.

WinPopUp.bi

Code: Select all

declare sub check(param as any ptr)
declare sub send(file as string,text as string)
declare sub crack(text as string,user as ubyte)
declare sub start
declare sub shut(which as string)
declare sub shutdown
declare sub centre(text as string,d as ubyte,offset as ubyte)
declare sub endprog(ex as ubyte)
declare sub drawarr(user3 as ubyte,arrow as ubyte)
declare sub drawstr(user3 as ubyte,onoff as string,rnr as string)
WinPopUp.cfg (put this in c:\windows directory and configure as needed)

wpu
Fred
Wilma
Laptop
c:\users\fred
\\Wilma\C Drive\Users\Wilma
\\Laptop\C Drive\Users\Laptop
2
60
c:\windows\system32\shutdown.exe
/s /f /t 0
c:\windows\wakeup.exe
50:e5:49:5f:5a:88 192.168.0.4 255.255.255.0
00-26-5E-5F-B9-2C 192.168.0.7 255.255.255.0
00:25:22:ab:e1:df 192.168.0.2 255.255.255.0

Line 1: The name of the file you look for to determine if program started (there=program started)
Line 2: Your Name
Line 3: Name of second person on other computer
Line 4: Name of third person on other computer
Line 5: Location where your messages placed
Line 6: Working Drive and/or directory of second computer
Line 7: Working Drive and/or directory of third computer
Line 8: Delay in seconds you want to perform checks for message when other computer ON
Line 9: Delay when other computer is off OR when computer is ON but program not running
Line 10: Path of shutdown.exe
Line 11: Shutdown.exe's parameters
Line 12: path of wakeup.exe
Line 13: Wakeup.exe's parameters of second computer
Line 14: " " third computer
Line 15: " " your computer
[MAC ADRESS] 255.255.255.255 255.255.255.255 also works

WakeUp.exe -> https://drive.google.com/open?id=0B4Zze ... XRadktYU0E

WinPopUp.bas

Code: Select all

#include "winpopup.bi" 'these 2 includes were missing!
#include "windows.bi"
screenres 736,400,32
width 92,25
color &hc0c0c0 'normal text brightness

type flagtype 'single bit - 1 is either 1 or 0. 2 can be 0,1,2 or 3 and so forth. if assigned with larger number then will be zero!
    as ubyte mp            'message pointer points to current message always
    as ubyte hp            'history pointer keeps track when reading old messages
    as ubyte ap:1          'arrow pointer position so can be toggled properly 0=user2 1=user3
    as ubyte comp2:1       'computer2 on/off
    as ubyte prog2:1       'program2 running yes/no
    as ubyte comp3:1       'computer3 on/off
    as ubyte prog3:1       'program3 running yes/no
    as ubyte mess:2        'if and who's message is displayed in user2 spot. 0=none 2=user2 3=user3 
    as ubyte mpu:1         'another flag so only pops up after message and not continuosly
    as ubyte term:1        'to terminate check thread
    as ubyte pun:1=1       'print user name yes/no (not used in this version)
    as ubyte col           'where your message text was last printed
    as ubyte win:1         'if window minimized to task bar
    as ubyte sent:1        'if message sent ok
    as any ptr thread
end type

type details
    as ubyte app           'arrow pointer pixel start (so keeps arrow 1 character away from names
    as string psf          'Program 'started' file
    as string myname       'My name only
    as string name2        'User2 name only
    as string name3        'User3 name only
    as string me           'My directory
    as string dir2         'Directory where checks are made for user2 and where to look for messages to you
    as string dir3         'Directory where checks are made for user3 and where to look for messages to you
    as string message      'Messages sent for you only
    as string mymessage    'Messages you send 
    as ubyte t             'online time delay
    as ubyte t2            'offline time delay
    as ubyte msc           'holds message start column
    as ubyte msp2           'holds message start pixel for user2
    as ubyte msp3           'holds message start pixel for user3
    as string sp=space(91) 'Blanker
    as string shut         'path of shutdown.exe
    as string spar         'and it's parameters
    as string wake         'path of wakeup.exe
    as string mac2         'and it's parameters which is mac adress of computer2
    as string mac3         'and it's parameters which is mac adress of computer3
    as zstring*90 hist(50) 'holds previous messages to max 50
    as HWND gsw            'graphics screen window
end type

dim shared flag as flagtype
dim shared v as details
screencontrol(2,cast(integer,v.gsw))
screencontrol(100,40,40) 'set window position
screencontrol(101,"WinPopUp") 'set title
v.hist(0)="No Messages"
dim as integer a

open"c:\windows\winpopup.cfg" for input as #1
if err then
    ?" WinPopUp.cfg not found!"
    sleep 1500
    end
else
    input #1,v.psf
    input #1,v.myname
    input #1,v.name2
    input #1,v.name3
    input #1,v.me
    input #1,v.dir2
    input #1,v.dir3
    input #1,v.t
    input #1,v.t2
    input #1,v.shut
    input #1,v.spar
    input #1,v.wake
    input #1,v.mac2 'mac address of other computer
    input #1,v.mac3 'mac address of other computer
    close #1
end if
a=len(v.myname) 'code for name spacing/formatting
if a<len(v.name2)then a=len(v.name2)
if a<len(v.name3)then a=len(v.name3)
v.app=92-a-29 'so arrows always 8 pixels away from names
v.msc=a+4
v.msp2=8*(v.msc-len(v.name2)-3)
v.msp3=8*(v.msc-len(v.name3)-3)
flag.col=v.msc
send v.me+v.psf,"" 'so that other computer knows you're online (program running)
flag.sent=0

?"***************************************"
?"* WinPopUp v3.51 (c) 2019 GT Software *"
?"***************************************"
locate 1,92-len(v.name2)-24
?ucase(v.name2)+"'S COMPUTER:";
locate 3,92-len(v.name3)-24
if v.name3<>"Laptop" then ?ucase(v.name3)+"'S COMPUTER:"; else ?"  LAPTOP COMPUTER:";
locate 2,72
?"PROGRAM:";
locate 4,72
?"PROGRAM:";
locate 25,1
?"ESC to exit               TAB-Messaging    ";chr(30);chr(31);" Prev/Next Message    F1-Start    F12-Shutdown";
locate 6,v.msc-len(v.myname)-2
?v.myname+":";
drawstr 0,"OFF","NOT RUNNING" 'these needed here as in thread only updates when states change
drawstr 1,"OFF","NOT RUNNING"
flag.thread=threadcreate(@check,0)

do
    locate 6,flag.col
    ?chr(219);chr(8);
    a=getkey
    if multikey(&h3b) then start
    if multikey(&h58) then shutdown
    if multikey(&h4b) or multikey(&h4d) then line(0,304)-(736,319),0,bf 'side arrows blank out history messages
    if multikey(&h0f) then 'TAB key for flip 'message to'
        if flag.ap then
            if flag.prog2 then drawarr 0,1
        else
            if flag.prog3 then drawarr 1,1
        end if
    end if
    if multikey(&h48) then 'UP ARROW for newer or later messages
        if flag.hp<flag.mp then flag.hp+=1
        if flag.hp<=flag.mp then
            locate 20,2
            ?v.hist(flag.hp)
        end if
    end if
    if multikey(&h50) then 'DOWN ARROW for older or previous messages
        if flag.hp>1 then flag.hp-=1
        if flag.hp>0 then
            locate 20,2
            ?v.hist(flag.hp)
        end if
    end if
    if a=27 then exit do
    if a<>13 then
        locate 6,flag.col
        if a>19 and a<123 and len(v.mymessage)<91-v.msc then 'no more than 1 line
            ?chr(a);
            flag.col=pos(0)
            v.mymessage=v.mymessage+chr(a)
        end if
        if a=8 then 'if backspace hit
            if flag.col>v.msc then flag.col-=1
            ?" ";chr(8);
            v.mymessage=left(v.mymessage,flag.col-v.msc)
            locate,flag.col
            ?" ";
            locate,flag.col
        end if
    end if
    if a=13 then
        line(v.msc*8-8,80)-(735,127),0,bf 'blank out your message and all others
        line(0,96)-(v.msc*8,127),0,bf 'blank out names of other 2 users
        if v.mymessage<>"" then
            flag.mess=0
            flag.col=v.msc
            if flag.prog2 and flag.ap=0 then send v.me+v.name2+".txt",v.mymessage 'to user2 'start with user2
            if flag.prog3 and flag.ap then send v.me+v.name3+".txt",v.mymessage   'then user3
            if flag.ap=0 and flag.prog2=0 or flag.ap and flag.prog3=0 then 'if selected user offline
                centre"user offline!",1,0
                v.mymessage=""
            else
                if flag.sent then
                    if flag.ap then 'if to user3 then fix name
                        if v.name3="Laptop" then centre"message sent to Laptop!",1,0 else centre"message sent to "+v.name3+"!",1,0
                    else
                        centre"message sent to "+v.name2+"!",1,0 'and if gone to user2
                    end if
                else
                    centre"problem sending message!",1,0
                end if
                v.mymessage=""
                flag.sent=0
            end if
        else
            flag.mpu=0 'always reset this so only new messages will trigger 
            flag.win=1
            showwindow v.gsw,sw_minimize 'if return just hit with no text then minimize
        end if
    end if
loop

endprog 1

sub check(param as any ptr)
    dim as ubyte t
    dim as uinteger t1=timer
    do
        if chdir(v.dir2) then 'if computer on 0=on -1(+) off
            if flag.comp2 then
                drawstr 0,"OFF","NOT RUNNING" 'just update when status changes
                if flag.ap=0 then
                    if flag.prog3 then drawarr 1,1 else drawarr 1,0 'for shutdown get rid of user2 arrow and put at user3
                end if
            end if
            flag.comp2=0
            flag.prog2=0
        else
            if flag.comp2=0 then drawstr 0,"ON ",""'just update when status changes
            flag.comp2=1
            if open(v.dir2+v.psf for input as #2)=0 then 'check for program running still (wpu file)
                close #2 'always use different filenumber in threads
                if flag.prog2=0 then 'just update when status changes
                    if flag.prog3=0 then drawarr 0,1 'only draw arrow if user3 offline
                    drawstr 0,"ON ","RUNNING    " 'added 'ON ' here to fix shutdown
                end if
                flag.prog2=1
            else
                if flag.prog2 then 'just update when status changes
                    if flag.ap=0 then
                        drawarr 1,0 '1 as opposite when just clearing arrow but get rid of arrow if there too!
                        if flag.prog3 then drawarr 1,1 'shift arrow to other user
                    end if
                    drawstr 0,"","NOT RUNNING"
                end if
                flag.prog2=0
            end if
        end if
        if chdir(v.dir3) then 'if computer on 0=on -1(+) off
            if flag.comp3 then
                drawstr 1,"OFF","NOT RUNNING"'just update when status changes
                if flag.ap then
                    if flag.prog2 then drawarr 0,1 else drawarr 0,0 'for shutdown get rid of user3 arrow and put at user2
                end if
            end if
            flag.comp3=0
            flag.prog3=0
        else
            if flag.comp3=0 then drawstr 1,"ON ","" 'just update when status changes
            flag.comp3=1
            if open(v.dir3+v.psf for input as #2)=0 then 'check for program running still (wpu file) 
                close #2
                if flag.prog3=0 then 'just update when status changes
                    if flag.prog2=0 then drawarr 1,1 'only draw arrow if user2 offline
                    drawstr 1,"ON ","RUNNING    " 'added 'ON ' here to fix shutdown
                end if
                flag.prog3=1
            else
                if flag.prog3 then 'just update when status changes
                    if flag.ap then
                        drawarr 0,0 '0 as opposite when just clearing arrow but get rid of arrow if there too!
                        if flag.prog2 then drawarr 0,1 'shift arrow to other user
                    end if
                    drawstr 1,"","NOT RUNNING"
                end if
                flag.prog3=0
            end if
        end if
        if flag.prog2 and open(v.dir2+v.myname+".txt" for input as #2)=0 then 'if program running and file there for me read message
            t1=timer
            line input #2,v.message
            close #2
            kill v.dir2+v.myname+".txt" 'once read delete message
            if left(v.message,1)<>"@" then
                drawarr 0,1 'shift arrow to user2
                v.message=v.name2+": "+v.message+left(v.sp,92-v.msc-len(v.message)) 'pad out with spaces so clears last message
                if flag.mess=3 then 'if the user2 spot taken by user3 then put message at user3 spot
                    line(v.msc*8-8,112)-(735,127),0,bf 'blank out message first
                    draw string(v.msp2,112),v.message,&hc0c0c0
                else
                    line(v.msc*8-8,96)-(735,111),0,bf
                    draw string(v.msp2,96),v.message,&hc0c0c0
                    flag.mess=2
                    flag.mpu=1
                end if
                flag.ap=0
                flag.mp+=1 'update message pointer which always points to lasrt message (50 max per session)
                flag.hp=flag.mp 'so when using arrows for the first time they will work properly
                v.hist(flag.mp)=v.message
            else
                crack v.message,0 'if message is control codes then crack it (0=user2)
            end if
        end if
        if flag.prog3 and open(v.dir3+v.myname+".txt" for input as #2)=0 then 'if program running and file there read message
            t1=timer
            line input #2,v.message
            close #2
            kill v.dir3+v.myname+".txt" 'once read delete message
            if left(v.message,1)<>"@" then
                drawarr 1,1 'shift arrow to user3
                v.message=v.name3+": "+v.message+left(v.sp,92-v.msc-len(v.message)) 'pad out with spaces so clears last message
                if flag.mess=2 then 'if the user2 spot taken by user2 then put message at user3 spot
                    line(v.msc*8-8,112)-(735,127),0,bf 'blank out message first
                    draw string(v.msp3,112),v.message,&hc0c0c0
                else
                    line(v.msc*8-8,96)-(735,111),0,bf
                    draw string(v.msp3,96),v.message,&hc0c0c0
                    flag.mess=3
                    flag.mpu=1
                end if
                flag.ap=1
                flag.mp+=1
                flag.hp=flag.mp 'so when using arrows for the first time they will work properly
                v.hist(flag.mp)=v.message
            else
                crack v.message,1 'if message is control codes then crack it (1=user3)
            end if
        end if
        if flag.win and flag.mpu then 'pop up for any message if on task bar
            flag.win=0
            flag.mpu=0
            showwindow v.gsw,sw_restore
            SetForegroundWindow(v.gsw) 'need this for window to get focus in Win10
        end if
        if flag.comp2 or flag.comp3 then t=v.t else t=v.t2 'if no computer on change delay to t2 which is 60sec atm
        if t=v.t and timer-t1>300 then t=v.t2/2 'switch to half of max when not messaging and only check again when it's shorter
        for i as integer=1 to t*10 'has to be like this so terminates quickly in long sleeps
            if flag.term then exit sub
            sleep_ 100
        next
    loop
end sub

sub endprog(ex as ubyte)
    cls
    centre"Please wait..",0,0
    flag.term=1
    threadwait(flag.thread)
    kill v.me+v.psf 'get rid of file so other computers know program not running
    if ex=1 then exit sub
    if ex=2 then run("c:\windows\wpud.exe") 'for updating program but not used
end sub

sub centre(text as string,d as ubyte,offset as ubyte)
    if text<>"" then 'if null then just blanks out last text after 'd' secs
        dim as ubyte a
        a=46-(len(text)/2)
        locate 12+offset,a
        if d=255 then ?text; else ?ucase(text); 'don't print uppercase for history messages
        locate 6,flag.col
        if d=0 then exit sub 'for when you need it to stay there for a response or history messages
    end if
    if d=1 then sleep len(text)*60,1 else sleep d*500,1 'sleep text length or half the value in seconds
    locate 12+offset,1
    ?v.sp;
    locate 6,flag.col
end sub

sub start
    if flag.comp2 and flag.comp3 then
        centre "all computers are on!!",1,0
        exit sub
    end if
    dim as integer a
    while len(inkey):wend
    if flag.comp2=0 and flag.comp3=0 then
        centre"Whose computer you want to switch on? ",0,0
        centre"[1] "+v.name2,0,1 'so aligns left
        if v.name3="Laptop" then centre"[2] Laptop",0,2 else centre"[2] "+v.name3,0,2
        centre"Choose One: ",0,4
        locate 16,52,0
        ?chr(219);
        a=getkey
        if a<49 or a>50 then
            a=0 'just get out if bad input
        else
            locate 16,52,0
            ?chr(a);chr(219);
            sleep 500
        end if
        centre"",0,0 'just clears all the above text
        centre"",0,1
        centre"",0,2
        centre"",0,4
        if a=0 then exit sub 'leave here if bad input as needs to clear lines
    end if
    If flag.comp3 or a=49 then 'if starting comp2 (as comp3 already on and comp2 selected))
        exec(v.wake,v.mac2)
        centre"starting "+v.name2+"'s computer..",6,0
    end if
    If flag.comp2 or a=50 then 'if starting comp3 (as comp2 already on and comp3 selected))
        exec(v.wake,v.mac3)
        if v.name3="Laptop" then centre"starting the Laptop..",6,0 else centre"starting "+v.name3+"'s computer..",6,0
    end if
end sub

sub shutdown
    if flag.comp2=0 and flag.comp3=0 then
        centre"computers are already shut down!",1,0
        exit sub
    end if
    if flag.prog2=0 and flag.prog3=0 then
        centre"can't shutdown as no computers running WinPopUp!",1,0
        exit sub
    end if
    dim as integer a
    while len(inkey):wend
    if flag.prog2 and flag.prog3 then
        centre"Whose computer you want to switch off?",0,0
        centre"[1] "+v.name2,0,1
        centre"[2] "+v.name3,0,2
        centre"Choose One:",0,4
        locate 16,52
        ?chr(219);
        a=getkey
        if a<49 or a>50 then
            a=0 'just get out if bad input
        else
            locate 16,52
            ?chr(a);chr(219);
            sleep 500
        end if
        centre"",0,0
        centre"",0,1
        centre"",0,2
        centre"",0,4
        if a=0 then exit sub 'leave here if bad input as needs to clear lines
        if a=49 then shut v.name2 else shut v.name3
    else
        shut "any"
    end if
    locate 6,flag.col
end sub

sub shut (which as string)
    dim as integer a
    if which="any" then
        if flag.prog2 then which=v.name2 else which=v.name3
    end if
    if which="Laptop" then
        centre"are you sure you want to shutdown the Laptop? y/n",0,0
    else
        centre"are you sure you want to shutdown "+which+"'s computer? y/n",0,0
    end if
    a=getkey
    if a=121 or a=89 then
        send v.me+which+".txt","@shutdown"
        centre"",0,0
        if which="Laptop" then centre"shutting down the Laptop..",6,0 else centre"shutting down "+which+"'s computer..",6,0
    else
        centre"",0,0
        centre"Shutdown Cancelled!",1,0
    end if
end sub    

sub crack(text as string,user as ubyte)
    if left(text,5)="@loop" then
        text=right(text,len(text)-5)
        if user then send v.me+v.name3+".txt",text else send v.me+v.name2+".txt",text '0=user2 1=user3
    end if
    if text="@shutdown" then
        kill v.me+v.psf 'get rid of file now so will show program 'off' before shows computer 'off' so works better
        for i as ubyte=5 to 1 step -1
            line(0,192)-(735,207),0,bf
            sleep_ 500
            draw string(272,192),"SHUTTING DOWN COMPUTER "+str(i),&he0e0e0
            sleep_ 500
        next
        run(v.shut,v.spar)
    end if
end sub

sub send(file as string,text as string)
    if open(file for output as #1)=0 then
        if text<>"" then print #1,text
        close #1
        flag.sent=1
        flag.mess=0
    end if
end sub

sub drawarr(user3 as ubyte,arrow as ubyte)
    if user3 then
        line(v.app*8,0)-(v.app*8+24,15),0,bf 'clear arrow at user2
        if arrow then
            draw string(v.app*8,32),"-->",&h00c000 'put arrow at user3
            flag.ap=1
        end if
    else
        line(v.app*8,32)-(v.app*8+24,47),0,bf 'clear arrow at user3
        if arrow then
            draw string(v.app*8,0),"-->",&h00c000 'put arrow at user2
            flag.ap=0
        end if
    end if
end sub

sub drawstr(user3 as ubyte,onoff as string,rnr as string)
    if user3 then
        if onoff<>"" then
            line(644,32)-(668,47),0,bf
            if onoff="OFF" then draw string(644,32),onoff,&hc00000 else draw string(644,32),onoff,&h00c000
        end if
        if rnr<>"" then
            line(644,48)-(732,63),0,bf 'needed here as when shutdown doesn't pick up
            if rnr="NOT RUNNING" then draw string(644,48),rnr,&hc00000 else draw string(644,48),rnr,&h00c000
        end if
    else
        if onoff<>"" then
            line(644,0)-(668,15),0,bf
            if onoff="OFF" then draw string(644,0),onoff,&hc00000 else draw string(644,0),onoff,&h00c000
        end if
        if rnr<>"" then
            line(644,16)-(732,31),0,bf 'needed here as when shutdown doesn't pick up
            if rnr="NOT RUNNING" then draw string(644,16),rnr,&hc00000 else draw string(644,16),rnr,&h00c000
        end if
    end if
end sub
Last edited by xbgtc on Aug 11, 2021 0:30, edited 18 times in total.
Merick
Posts: 1038
Joined: May 28, 2007 1:52

Re: WinPopUp MyWay

Post by Merick »

Instead of hard-coding the filenames into the program, why not read them from a config file? That way, you only have to compile one version of the code, but the config file would have the filenames listed in a different order for each user.
xbgtc
Posts: 250
Joined: Oct 14, 2007 5:40
Location: Australia

Re: WinPopUp MyWay

Post by xbgtc »

ahh yes that would be better
xbgtc
Posts: 250
Joined: Oct 14, 2007 5:40
Location: Australia

Re: WinPopUp MyWay

Post by xbgtc »

UPDATE

Fix status so works properly now.
Added a few extras
xbgtc
Posts: 250
Joined: Oct 14, 2007 5:40
Location: Australia

Re: WinPopUp

Post by xbgtc »

Program totally re-written with better code.
xbgtc
Posts: 250
Joined: Oct 14, 2007 5:40
Location: Australia

Re: WinPopUp

Post by xbgtc »

see next
Last edited by xbgtc on Mar 23, 2019 12:29, edited 1 time in total.
xbgtc
Posts: 250
Joined: Oct 14, 2007 5:40
Location: Australia

Re: WinPopUp

Post by xbgtc »

UPDATE:

New Win10 version totally re-written and uses a thread for computer checking/reporting.
Does 3 computers.
Saves messages. UP/DOWN arrows for messages and LEFT/RIGHT blanks.
TAB to switch user to message to (if both present).
Has loop back test for testing message sending/receiving.
Post Reply