NETSEND PRO

Share your advanced PureBasic knowledge/code with the community.
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

NETSEND PRO

Post by Num3 »

Code updated for 5.20+

Made this one to send and receive net send messages on NT networks..

The code is a bit swapy, and sometimes, just sometimes it crashes, i haven't located that bug yet... but it runs stable for days !

This code traps the netsend incoming messages, so you get no inconvinient popups in the middle of the screen for everyone to read :twisted: (good for the office) :twisted:

Code: Select all

; PureBasic Visual Designer v3.72
;
; ********** Final Version, no memory leaks, no cpu hogging *********
;
;
Global text.s,kill.l

;- Window Constants
;
#Window_0 = 0

;- Gadget Constants
;
#Gadget_0 = 0
#Gadget_2 = 1
#Gadget_3 = 2
#Gadget_4 = 3
#Gadget_5 = 5
#Gadget_6 = 6

Procedure Open_Window_0()
  If OpenWindow(#Window_0, 268, 328, 482, 140, "NetSend Pro - Freeware",  #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered )
      TextGadget(#Gadget_0, 3, 12, 36, 18, "Para:")
      StringGadget(#Gadget_2, 42, 9, 126, 21,"")
      TextGadget(#Gadget_3, 183, 9, 60, 21, "Mensagem:")
      StringGadget(#Gadget_4, 243, 9, 180, 21, "")
      SendMessage_(GadgetID(#Gadget_4), #EM_LIMITTEXT, 200, 0)
      ButtonGadget(#Gadget_6, 426, 9, 54, 21, "Enviar")
      ListViewGadget(#Gadget_5, 3, 42, 477, 95)     
  EndIf
EndProcedure



Structure info
  handle.l
  process.l
  class$
  name$
EndStructure
;#PROCESS_ALL_ACCESS=$FFF

Global info.info
;Global AllHandle.AllHandle

Procedure.s GetClassName(handle)
  class$=Space(1024)
  GetClassName_(handle,@class$,Len(class$))
  ProcedureReturn Left(class$,Len(class$))
EndProcedure


Procedure.s GetTitle(handle)
  name$=Space(1024)
  GetWindowText_(handle,@name$,Len(name$))
  ProcedureReturn Left(name$,Len(name$))
EndProcedure


Procedure AddInfo(handle)
  process=0
  GetWindowThreadProcessId_(handle,@process)
  class$=GetClassName(handle)
  name$=GetTitle(handle)

  quit=0
  i=0
 
  info\handle=handle
  info\process=process
  info\class$=class$
  info\name$=name$

EndProcedure


Procedure TerminateProcess(processid)
  process=OpenProcess_(#PROCESS_ALL_ACCESS,1,processid)
  If process
    TerminateProcess_(process,0)
    CloseHandle_(process)
  EndIf
EndProcedure


Procedure refreshlist(dummy)
 
 
  handle=GetWindow_(WindowID(#Window_0),#GW_HWNDFIRST)
 
 
  Repeat
    handle=GetWindow_(WindowID(#Window_0),#GW_HWNDFIRST)
   
    AddInfo(handle)
    test.s=info\name$
   
    If Mid(test,1,10)="Messenger "
     
      kill=info\handle
     
      x=GetWindow_(handle,#GW_CHILD)
      If x
        handle=x
      EndIf
     
      AddInfo(handle)
      test.s=info\name$
     
      If Mid(test,1,7)="Message"
        text=test
        AddGadgetItem(#Gadget_5,-1,"<--Recebida: "+text)
      EndIf
     
      x=GetWindow_(handle,#GW_HWNDNEXT)
      If x
        handle=x
      EndIf
     
      AddInfo(handle)
      test.s=info\name$
      If Mid(test,1,7)="Message"
        text=test
        AddGadgetItem(#Gadget_5,-1,"<--Recebida: "+text)
        FlashWindow_(WindowID(0),1)
      EndIf
     
     
    EndIf
   
    If kill<>0
      PostMessage_(kill,#WM_CLOSE,0,0)
      kill=0
    EndIf
   
   
    Delay(5)
  ForEver
EndProcedure


cr.s=Chr(10)+Chr(13)

Buffer.s=Space(256)
nSize.l=256

GetUserName_(@Buffer,@nSize)

ret.s=UCase(Buffer)

Open_Window_0()

SetActiveGadget(#Gadget_2)

tr=CreateThread(@refreshlist(),0)

Repeat
 
 
  Event = WaitWindowEvent()
 
    If IsIconic_(WindowID(0))
      If icon=0
       icon=1
      EndIf
    Else
      If icon=1
        icon=0
        FlashWindow_(WindowID(0),0)
;         w=CountGadgetItems(#Gadget_5)
;         SetGadgetItemState(#Gadget_5,w-1,1)
      EndIf
    EndIf

    GadgetID = EventGadget()
   
    If GadgetID = #Gadget_6
     
      If GetGadgetText(#Gadget_4)<>""
        ShellExecute_(null,null,"net","send "+GetGadgetText(#Gadget_2)+" ["+ret+"] "+ GetGadgetText(#Gadget_4) ,null,#SW_HIDE   )
        SetGadgetText(#Gadget_4,"")
        AddGadgetItem(#Gadget_5,-1,"--> Enviada para: "+GetGadgetText(#Gadget_2))
       
      Else
        MessageRequester("Erro","Não existe mensagem para enviar!",#MB_ICONERROR )
        SetActiveGadget(#Gadget_4)
      EndIf
     
    ElseIf GadgetID =#Gadget_5
     
      If EventType() = #PB_EventType_LeftDoubleClick
        MessageRequester("Mensagem", GetGadgetText(#Gadget_5), #PB_MessageRequester_Ok)
      EndIf
     
    EndIf

 
 
Until Event = #PB_Event_CloseWindow
KillThread(tr)
End
; 
Last edited by Num3 on Thu Nov 25, 2004 4:47 pm, edited 1 time in total.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: NETSEND PRO

Post by PB »

> #PROCESS_ALL_ACCESS=$FFF

Is this declaration correct? The version I've been using (which I've seen on
Visual Basic sites) is rather longer, like so:

Code: Select all

#STANDARD_RIGHTS_REQUIRED=$F0000 : #SYNCHRONIZE=$100000 : #PROCESS_TERMINATE=$1
#PROCESS_ALL_ACCESS=#STANDARD_RIGHTS_REQUIRED|#SYNCHRONIZE|#PROCESS_TERMINATE|$FFF
So which is correct and safe to use?
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

just wondering, could u translate it to englidh?
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

Oh I could.. but no time sorry - its just portuguese if you know spanish its piece of cake else use an online translator?
! Black holes are where God divided by zero !
My little blog!
(Not for the faint hearted!)
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

Ah what the...

"Para:" = "For:"
"Mensagem:" = "Message:"
"Enviar" = "Send"

"<--Recebida: " = "<--Received: "
"Erro" = "Error"
"Não existe mensagem para enviar!" = "Theres No message to send!"
just replace with the translated strings...

if you see any other string I didnt see just say i'll translate it for you its easy as I said spanish is very similar to portuguese.
! Black holes are where God divided by zero !
My little blog!
(Not for the faint hearted!)
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

thanx!!
umm, didnt think spanish translator would work...
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

of course not - But if YOU know spanish then you can understand Portuguese.
Portuguese is Portuguese... for the logical part. But some languages has many things in common....
! Black holes are where God divided by zero !
My little blog!
(Not for the faint hearted!)
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

yeah, i knew they were similar, i just didnt know that if u knew spanish u could most likely understand portuguese....
and as u can probably guess, i dont understand spanish, the closest i know is a bit of italian that im learning...
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

:D Italian rocks... so does Italy! - most creative country in the world. best things comes from there !! you cant say thats not true!
:!:
! Black holes are where God divided by zero !
My little blog!
(Not for the faint hearted!)
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

u speak any dagcrack? (italiano)
getting a bit off topic, i know.... :twisted:
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

yep a little I was supossed to study it but ... on hold for now -- I wasnt getting enough time to learn another language.
! Black holes are where God divided by zero !
My little blog!
(Not for the faint hearted!)
Post Reply