topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Friday April 19, 2024, 5:07 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Idea : Print Notification  (Read 4628 times)

thankusan

  • Participant
  • Joined in 2007
  • *
  • default avatar
  • Posts: 22
    • View Profile
    • Donate to Member
Idea : Print Notification
« on: November 22, 2007, 09:53 AM »
Discription : A program which make a beep or chime sound when a print command is given on a local printer-shared.  (ie; when a print arrives in the PC to which the printer is connected. Wonder why XP does not have such an option.

thankusan

  • Participant
  • Joined in 2007
  • *
  • default avatar
  • Posts: 22
    • View Profile
    • Donate to Member
Re: Idea : Print Notification
« Reply #1 on: November 23, 2007, 11:55 AM »
To make it simple, program for a sound generation when print command arrives to the pc. Could be an addon in the 'sounds and audio devices' shown on control panel

skrommel

  • Fastest code in the west
  • Developer
  • Joined in 2005
  • ***
  • Posts: 933
    • View Profile
    • 1 Hour Software by skrommel
    • Donate to Member
Re: Idea : Print Notification
« Reply #2 on: February 12, 2008, 03:49 PM »
 :) Try PrintSound!

It plays a sound and displays a traytip when something is printed.
I've set a delay of 10 seconds between prints to prevent multiple alarms for the same print.
Maybe larger jobs require a larger delay.

Skrommel


;PrintSound.ahk
; Plays a sound and displays a traytip when something is printed
;Skrommel @ 2008


delay=10

;Code stolen from SKAN at http://www.autohotkey.com/forum/topic22862.html

#SingleInstance,Force
#Persistent
SetBatchLines,-1
Process,Priority,,High
OnExit,ShutApp

WatchFolder  := A_WinDir "\system32\spool\printers\"
WatchSubDirs := "0"

EventString := "New File,Deleted,Modified,Renamed From,Renamed To"
StringSplit, EventArray, EventString, `,

DllCall("shlwapi\PathAddBackslashA", UInt, &Watchfolder)

CBA_ReadDir := RegisterCallback("ReadDirectoryChanges")

SizeOf_FNI := ( 64KB := 1024 * 64 )
VarSetCapacity( FILE_NOTIFY_INFORMATION, SizeOf_FNI, 0 )
PointerFNI := &FILE_NOTIFY_INFORMATION

hDir := DllCall( "CreateFile", Str  , WatchFolder, UInt, "1", UInt , "7", UInt, 0, UInt, "3", UInt, "1107296256", UInt , 0 )

Loop
{
   nReadLen  := 0
   hThreadId := 0

   hThread   := DllCall( "CreateThread", UInt, 0, UInt, 0, UInt, CBA_ReadDir, UInt, 0, UInt,0, UIntP,hThreadId )
   Loop
   {
      If nReadLen
      {
        PointerFNI := &FILE_NOTIFY_INFORMATION

        Loop
        {
          NextEntry   := NumGet( PointerFNI + 0  )
          Action      := NumGet( PointerFNI + 4  )
          FileNameLen := NumGet( PointerFNI + 8  )
          FileNamePtr :=       ( PointerFNI + 12 )

          Event := EventArray%Action%     

          VarSetCapacity( FileNameANSI, FileNameLen )
          DllCall( "WideCharToMultiByte", UInt,0, UInt,0, UInt,FileNamePtr, UInt, FileNameLen,  Str, FileNameANSI, UInt,FileNameLen, UInt,0, UInt,0 )

          File := WatchFolder . SubStr( FileNameANSI, 1, FileNameLen/2 )

          If Event=New File
          {
            FileGetTime,created,%File%,C
            If (created>prevcreated+delay)
            {
              SoundPlay,*64
              TrayTip,PrintSound,Printing...
              prevcreated:=created
            }
          }

          If !NextEntry
            Break
          Else
            PointerFNI += NextEntry
        }
        Break
      }
      Sleep 1000
   }
   DllCall( "TerminateThread", UInt,hThread, UInt,0 )
   DllCall( "CloseHandle", UInt,hThread )
}
Return

ReadDirectoryChanges()
{
   Global hDir,PointerFNI, Sizeof_FNI, WatchSubdirs, nReadlen
   Return DllCall( "ReadDirectoryChangesW", UInt, hDir, UInt, PointerFNI, UInt, SizeOf_FNI, UInt, WatchSubDirs, UInt, "375", UIntP, nReadLen, UInt, 0, UInt, 0 )
}

ShutApp:
DllCall( "CloseHandle", UInt,hDir )
DllCall( "TerminateThread", UInt,hThread, UInt,0 )
DllCall( "CloseHandle", UInt,hThread )
ExitApp