Eye-Saver

Maak aankondigingen en adverteer hier je Liberty BASIC software en Liberty BASIC websites

Eye-Saver

Berichtdoor anthonio » wo maart 25, 2009 11:28 pm

LB'ers,

Ik ben men oude programma's wat aan het bijschaven zodanig dat ik men site weer kan online zetten.
Bij deze het eerste bijgewerkte/vernieuwde programma.
Alle bestanden zitten gezipt.
Het is een .exe bestand maar ik ga de code hierbij direct vrijgeven zodanig dat andere lb'ers ook wat aan hebben.
Heb je vragen/opmerkingen/suggesties dan post je ze maar.

OPMERKING: je hebt het bestand WMLiberty.dll en eyesaver.ico nodig.

Code: Selecteer alles
'Written by anthonio
'Personal use is free, commercial use is forbidden (contact anthonio @ www.libertybasic.nl)

'Dim en structs voor het icoon naar de taskbar te sturen --------------------------------------------------------
dim handle(2)       'array for windows handles
dim param(4)            'need some parameters to be global
dim defDir(1)       'make the default dir available inside subs and functions

global h1
global startpressed
global resultShow

NIM.ADD=0           'windows constant that LB doesn't recognise
NIM.MODIFY=1        '               ditto
NIM.DELETE=2        '               ditto
NIM.SETVERSION=4

NIF.MESSAGE=1       '               ditto
NIF.ICON=2         '               ditto
NIF.TIP=4          '               ditto

param(1)=NIM.DELETE     'make these global
param(2)=NIF.MESSAGE
param(3)=NIM.SETVERSION

struct OSVInfo,_
    OSVInfoSize as long,_
    MajorV as long,_
    MinorV as long,_
    Build as long,_
    PlatformId as long,_
    CSDV$ as char[128]
OSVInfo.OSVInfoSize.struct=len(OSVInfo.struct)

struct iconData,_                   'used to minimize to the "system tray"
    iDSize as long,_                'size of this structure
    hwnd as long,_                  'handle of window that owns the Icon
    uID as ulong,_                  'unique identifier (unique to the owning window)
    uFlags as ulong,_               'flag denotes which struct items are being sent
    uCallbackMessage as ulong,_     'app. defined message that windows will send to the window in this case _WM_USER+1
    hIcon as long,_                 'handle to the Icon to use
    szTip$ as char[64],_            'tooltip for this Icon
    dwState as long,_
    dwStateMask as long,_
    szInfo$ as char[256],_
    unionTimeoutVersion as long,_
    szInfoTitle$ as char[64],_
    dwInfoFlags as long,_
    guidItem as ulong

call getOSVersion
param(4)=OSVInfo.MajorV.struct

iconData.uID.struct=8               'icon identifier unique to this window (not necessarilly unique to the system)
iconData.uCallbackMessage.struct=_WM_USER+1     'window message OS will send to my window when Icon is activated
Tip$="Left or right click to restore"+null$(1)     'tooltip text
iconData.szTip$.struct=Tip$         'load tooltip text into struct
defDir$(1)=DefaultDir$              'need this to load my Icon into memory

'Laden van het programma -----------------------------------------------------------
[Win]
nomainwin
WindowWidth = 175
WindowHeight = 205
UpperLeftX=int((DisplayWidth-WindowWidth)/2)
UpperLeftY=int((DisplayHeight-WindowHeight)/2)
stylebits #main, _WS_SYSMENU, _WS_POPUP, 0, 0
groupbox #main, "", 10, 5, 150, 50
button #main.start, "Start", [Start], UL, 20, 20, 60, 25
button #main.min, "Minimize", [Minimize], UL, 90, 20, 60, 25
groupbox #main, "", 10, 55, 150, 45
statictext #main, "Time remaining:", 25, 75, 80, 15
statictext #main.time, "60 min", 105, 75, 40, 15
groupbox #main, "", 10, 100, 150, 65
statictext #main, "Eye-Saver V1.0", 45, 120, 80, 15
statictext #main, "Copyright ©Andy Software", 20, 140, 125, 15
open "Eye-Saver" for window_popup as #main
#main, "trapclose endProgram"
#main.min, "!disable"
wait

'Tijd starten en minimaliseren naar de taskbar ---------------------------------------------------
[Start]
starttime = time$("seconds")   'set the starttime
#main.min, "!enable"
#main.start, "!disable"        'disablen van de startknop
startpressed = 1    'nodig voor het correct kunnen afsluiten van het programma
h1=hwnd(#main)                             'get the handle to our window
handle(1)=h1
call showWindow h1,0                    'we hide the screen

hIcon=loadIcon()                        'call our function to load the Icon
handle(2)=hIcon                         'make this handle global
uFlags=NIF.MESSAGE or NIF.ICON or NIF.TIP   'set our flags
iconAdded=minToTaskbar(h1,uFlags,hIcon,NIM.ADD)     'this adds the Icon to the taskbar

open "WMLiberty.dll" for dll as #wmlib                          'message handler

wmMessage=_WM_USER+1
callback iconNotice,iconMessage(long,long,long,long),long          'callback for icon message notice

calldll #wmlib, "SetWMHandler",_        'set up WMLiberty.dll to trap and relay this message
        h1 As long,_                    'handle to the program window
        wmMessage As long,_             'message to intercept
        iconNotice As long,_            'address of callback in memory
        0 As long,_                     'value to send dll to indicate successful handling of message
        ret As long                     'dll returns this value to indicate successful setup

[Loop]
timer 0
scan
endtime = time$("seconds")  'bijwerken van de tijd
totaltime = endtime - starttime
minutes = int(totaltime/60)
minutes = 60 - minutes
#main.time, minutes; " min"
if minutes = 0 then
    notice "Rest time" + chr$(13) + "It's time to give" + chr$(13) + "your eyes some rest."
        if startpressed = 1 then
        startpressed = 0
        hwnd=handle(1)
        flags=param(2)
        hIcon=handle(2)
        message=param(1)
        rIcon=minToTaskbar(hwnd,flags,hIcon,message)    'remove Icon from taskbar
        call unloadIcon hIcon                           'free memory storing Icon
        close #wmlib                        'closing the dll or we get an error
        end if
    close #main                          'I found that you have to close the window before
    goto [Win]
end if
goto [Loop]

[Minimize]
call showWindow h1,0                    'we hide the screen

hIcon=loadIcon()                        'call our function to load the Icon
handle(2)=hIcon                         'make this handle global
uFlags=NIF.MESSAGE or NIF.ICON or NIF.TIP   'set our flags
iconAdded=minToTaskbar(h1,uFlags,hIcon,NIM.ADD)     'this adds the Icon to the taskbar

wmMessage=_WM_USER+1
callback iconNotice,iconMessage(long,long,long,long),long          'callback for icon message notice
goto [Loop]
wait

'Functions --------------------------------------------------------------------------------------
sub endProgram handle$
    if startpressed = 1 then
        startpressed = 0
        hwnd=handle(1)
        flags=param(2)
        hIcon=handle(2)
        message=param(1)
        rIcon=minToTaskbar(hwnd,flags,hIcon,message)    'remove Icon from taskbar
        call unloadIcon hIcon                           'free memory storing Icon
        close #wmlib                        'closing the dll or we get an error
    end if
    close #handle$                          'I found that you have to close the window before
    end
end sub

sub showWindow hwnd,nCmdShow            'this is where we hide our splash screen
    calldll #user32, "ShowWindow",_
        hwnd as Long,_                  'handle of window to recieve message
        nCmdShow as Long,_              'message to send
        resultShow as Long
end sub


function minToTaskbar(hwnd,uFlags,hIcon,dwMessage)
    if param(4)<5 then
        iconData.iDSize.struct=88
    else
        message95=param(3)
        iconData.iDSize.struct=428
        calldll #shell32,"Shell_NotifyIconA",_          'here we tell the taskbar to behave
            message95 as long,_                         'like a Win95 taskbar
            iconData as struct,_                        '
            result as long                              '
    end if                                              'if you have more than one Icon for a window then all of your struct
    iconData.hwnd.struct=hwnd                           'elements should be passed to this function then loaded into the
    iconData.uFlags.struct=uFlags                       'structure here. because your tooltip could be different for each one
    iconData.hIcon.struct=hIcon                         'the unique id has to be different for each one, etc.
    calldll #shell32,"Shell_NotifyIconA",_              'add the Icon to the taskbar
        dwMessage as long,_                             'value for 'ADD, MODIFY, or DELETE
        iconData as struct,_                            'pointer to the struct we just loaded
        minToTaskbar as long                            'return value, nonzero denotes success
end function

function loadIcon()
    fuLoad=_LR_DEFAULTSIZE or _LR_LOADFROMFILE or _LR_LOADTRANSPARENT       'flags for image information
    if right$(defDir$(1),1)="\" then
        iconName$=defDir$(1)+"eyesaver.ico"
    else
        iconName$=defDir$(1)+"\eyesaver.ico"
    end if
    calldll #user32,"LoadImageA",_              'load our Icon into memory so that we can use it
        0 as long,_                             'if you load the icon from a bmp, ico, or similar file this must be 0
        iconName$ as ptr,_                      'fully qualified path and filename for the icon
        _IMAGE_ICON as long,_                   'let the call know that we are loading an icon file
        0 as long,_                             'xExtent desired  **0 because I used the defaultsize flag
        0 as long,_                             'yExtent desired  **0 because I used the defaultsize flag
        fuLoad as long,_                        'image information flags
        loadIcon as long                        'return value, nonzero for success
end function

function iconMessage(hwnd,uMsg,wParam,lParam)   'icon message handler--lParam hold the mouse message from the icon
    select case lParam              'wParam holds the icon identifier (in case you have more than one icon)
        case _WM_LBUTTONDOWN        'don't do anything unless they let the button up while the cursor is over our icon
            isOk=0
        case _WM_LBUTTONUP          'tell them how to use the prog if they left click
            call restorewindow
            isOk=0
        case _WM_RBUTTONDOWN        'don't do anything unless they let the button up while the cursor is over our icon
            isOk=0
        case _WM_RBUTTONUP
            call restorewindow           'haven't been able to get the popup menu to work here yet
            isOk=0
        case else
            isOk=99                 'let the dll know that we don't do anything with _WM_MOUSEMOVE etc.
    end select
    iconMessage=isOk        'return a value to the dll to indicate if the message was handled
end function

sub restorewindow               'just to show that left clicking the icon works
    call showWindow h1,5                    'we show the screen
        hwnd=handle(1)
        flags=param(2)
        hIcon=handle(2)
        message=param(1)
        rIcon=minToTaskbar(hwnd,flags,hIcon,message)    'remove Icon from taskbar
        call unloadIcon hIcon                           'free memory storing Icon
end sub

sub unloadIcon hIcon
    calldll #user32,"DestroyIcon",_
        hIcon as long,_
        ret as long
end sub

sub getOSVersion
    calldll #kernel32,"GetVersionExA",_
        OSVInfo as struct,_
        result as long
    if result=0 then
        notice "Critical ERROR!!"+chr$(13)+"Unable to Continue!"
        end
    end if
end sub

Bijlagen
eye-saver.zip
(2.18 MiB) 186 keer gedownload
Dual boot: Ubuntu 8.04 - WIndows XP SP2 (via VMware) - Windows Vista 32bit - Toshiba L40 - Dual Core @ 1,76GHz - 1GB RAM - 120GB HDD - VDSL Connection
Avatar gebruiker
anthonio
 
Berichten: 281
Geregistreerd: zo mei 20, 2007 9:58 pm

Re: Eye-Saver

Berichtdoor anthonio » za apr 04, 2009 2:46 pm

Ik heb nog wat kleine aanpassingen gedaan aan het Eye-Saver programma.
Wat is nieuw in Versie 1.1
- Minimize knop verwijderd
- Als je minimaliseerd verdwijnt het programma naar de system tray
- Info knop toegevoegd

Programma zit in de bijlage.
Zoals altijd zijn suggesties/bug meldingen/commentaar altijd welkom.

groeten.
Bijlagen
EyeSaver1.1.zip
(1.25 MiB) 196 keer gedownload
Dual boot: Ubuntu 8.04 - WIndows XP SP2 (via VMware) - Windows Vista 32bit - Toshiba L40 - Dual Core @ 1,76GHz - 1GB RAM - 120GB HDD - VDSL Connection
Avatar gebruiker
anthonio
 
Berichten: 281
Geregistreerd: zo mei 20, 2007 9:58 pm


Keer terug naar Aankondigingen, Software en Websites

Wie is er online

Gebruikers op dit forum: Geen geregistreerde gebruikers. en 1 gast

cron