Code : Tout sélectionner
;
;************************************************************************
;Titre : freemobilesms_gui.pb
;Auteur : (C) 2019 CAGE
;Date : 2019/03/12
;Version PB : PureBasic 5.70 LTS (Windows - x86)
;Version PB : PureBasic 5.70 LTS (Windows - x64)
;Compiler Options
;Compiler Options : Executable format : Windows
;Compiler Options : Enable moderm theme support (for Windows X and above)
;Compile/Run : Create temporary executable in the source directory
;
;Libairies: aucunes
;
;************************************************************************
;
EnableExplicit
OnErrorGoto(?ErrorHandler)
Global AppName$ = GetFilePart(ProgramFilename(), #PB_FileSystem_NoExtension)
Global AppPath$ = GetPathPart(ProgramFilename())
;;; https://msdn.microsoft.com/en-us/library/windows/desktop/cc144179%28v=vs.85%29.aspx
Global TB_Message = RegisterWindowMessage_("TaskbarCreated")
#homemail$ = "pbcage@free.fr"
#homesite$ = "http://pbcage.free.fr"
#homepage$ = #homesite$ +"/pb/freemobilesms.html"
#homepure$ = "http://www.purebasic.com"
#homefree$ = "https://mobile.free.fr/moncompte/"
#bgcolor = 14474460 ; bgcolor = RGB(220,220,220) $00DCDCDC
#fgcolor = 0 ; fgcolor = RGB(0,0,0)
Global user$, pass$
user$ = "" ; définir votre login en dur si vous le souhaitez
pass$ = "" ; définir votre passw en dur si vous le souhaitez
Global Mutex, Message$
CompilerIf #PB_Compiler_Debugger
;;; We are in the IDE
#WinApp = 999
CompilerElse
#WinApp = 666 ; use by Mutex if needed
If TB_Message
Mutex = CreateMutex_(#Null, #False, AppName$)
If GetLastError_() = #ERROR_ALREADY_EXISTS
;;;
;;; Same Mutex in memory, that same app is running ???
;;;
Define hWnd = FindWindow_("WindowClass_"+Str(#WinApp), #NUL)
If hWnd
;;;
;;; Same Mutex in memory and same ClassName, no doubt, is the same app.
;;;
SendMessage_(hWnd,#WM_SYSCOMMAND, #SC_RESTORE,0)
SetForegroundWindow_(hWnd)
End
EndIf
EndIf
Else
;;; Desktop is not activated, then no TaskBar (TB)
End
EndIf
CompilerEndIf
Enumeration Menus
#MenuApp
#MenuTray
EndEnumeration
Enumeration FormMenu
#MenuAppAbout
#MenuAppFolder
#MenuAppHide
#MenuAppHomefree
#MenuAppHomepage
#MenuAppHomesite
#MenuAppLogin
#MenuAppQuit
#MenuAppShow
EndEnumeration
Enumeration Gadgets
#Gadget
#GadgetBtnSend
#GadgetBtnQuit
#GadgetCont
#GadgetText
#GadgetLogin
#GadgetEditor
#GadgetEnd
#GadgetSB
EndEnumeration
DataSection ; Images
Image_App:
IncludeBinary "freemobilesms.ico"
EndDataSection
Enumeration Images
#Image_App
EndEnumeration
Enumeration Fonts
#Font0
EndEnumeration
Global optMinimize = #True
Global IconApp = CatchImage(#Image_App, ?Image_App)
Global Event, IndexMenu
Global indexGadget, indexGadgetType
Procedure messageBox(request = #False)
If Message$ = #Null$
ProcedureReturn -1
EndIf
Protected flag = #PB_MessageRequester_Ok ;|#MB_ICONINFORMATION
If request
flag = #PB_MessageRequester_YesNo ; |#MB_ICONQUESTION
EndIf
ProcedureReturn MessageRequester(AppName$, Message$, flag | #MB_TOPMOST)
EndProcedure
Procedure initSysTray()
If FindWindow_("Progman", #NUL) <> 0
AddSysTrayIcon(#WinApp, WindowID(#WinApp), IconApp)
SysTrayIconToolTip(#WinApp, AppName$)
EndIf
EndProcedure
Procedure window_Callback(win, msg, wParam, lParam)
Protected Result = #PB_ProcessPureBasicEvents
Select Msg
Case TB_Message ; explorer crash
initSysTray()
EndSelect
ProcedureReturn Result
EndProcedure
Procedure hideAppWindow()
HideWindow(#WinApp, #True)
SetWindowState(#WinApp, #PB_Window_Minimize)
EndProcedure
Procedure showAppWindow()
HideWindow(#WinApp, #False)
SetWindowState(#WinApp, #PB_Window_Normal)
EndProcedure
Procedure appAbout()
Protected confirm
Protected home.s = GetFilePart(#homepure$)
Message$ = AppName$ + #CRLF$ + #CRLF$
Message$ + "Cette application est copyright © 2019 CAGE" + #CRLF$ + #CRLF$
Message$ + "Mes remerciements à l'équipe PureBasic" + #CRLF$ + #CRLF$
message$ + "Souhaitez-vous visiter le site " + #homepure$
confirm = messageBox(#True)
If confirm = #PB_MessageRequester_Yes
RunProgram(#homepure$)
EndIf
EndProcedure
Procedure sendSMS()
Debug "Demande d'envoi du SMS"
Protected msg$ = GetGadgetText(#GadgetEditor)
If (user$="") Or (pass$="") Or (msg$="")
msg$ = " Les champs <user> ou <pass> ou <msg> ne peuvent êtres vides."
StatusBarText(#GadgetSB, 0, msg$, 0)
Debug msg$
ProcedureReturn 0
EndIf
msg$ = URLEncoder(msg$)
Protected urlSMS$ = "https://smsapi.free-mobile.fr/sendmsg?user="+user$+"&pass="+pass$+"&msg="+msg$
If InitNetwork()
Protected agent$ = "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"
Protected host$ = "smsapi.free-mobile.fr"
Protected cache$ = "no-cache"
NewMap Header$()
Header$("Pragma") = cache$
Header$("Cache-Control") = cache$
Header$("Connection") = "keep-alive"
Header$("Host") = host$
Header$("User-Agent") = agent$
Protected HttpRequest = HTTPRequest(#PB_HTTP_Post, urlSMS$, "", 0, Header$())
If HttpRequest
Protected rcode$ = HTTPInfo(HTTPRequest, #PB_HTTP_StatusCode)
Select rcode$
Case "200" : msg$ = " Le SMS a été envoyé sur votre mobile."
Case "400" : msg$ = " Un des paramètres obligatoires est manquant."
Case "402" : msg$ = " Trop de SMS ont étés envoyés en trop peu de temps."
Case "403" : msg$ = " Le service n'est pas activé sur l'espace abonné ou login/clé incorrect"
Case "500" : msg$ = " Erreur côté serveur. Veuillez réessayer ultérieureent."
Default : msg$ = " Erreur inconnue."
EndSelect
FinishHTTP(HTTPRequest)
Else
rcode$ = "0"
msg$ = "Impossible de créer la requête."
EndIf
Else
rcode$ = "0"
msg$ = " Le réseau n'est pas correctement initialisé"
EndIf ;; If InitNetwork()
StatusBarText(#GadgetSB, 0, msg$, 0)
Debug msg$
ProcedureReturn Val(rcode$)
EndProcedure
ExamineDesktops()
#WinAppWidth = 400
#WinAppHeight = 196
Define X = (DesktopWidth(0)-#WinAppWidth)/2
Define Y = (DesktopHeight(0)-#WinAppHeight)/2
Define Flags = #PB_Window_TitleBar|#PB_Window_ScreenCentered|#PB_Window_SystemMenu
If OpenWindow(#WinApp, X, Y, #WinAppWidth, #WinAppHeight, AppName$, Flags)
;;; choix de couleur et de police a faie avant de construire l'interface
SetWindowColor(#WinApp, #bgcolor)
SetWindowCallback(@window_Callback(),#WinApp) ; crash explorer
initSysTray()
If CreatePopupImageMenu(#MenuTray, #PB_Menu_ModernLook)
MenuItem(#MenuAppShow , AppName$ , IconApp)
MenuBar()
MenuItem(#MenuAppAbout ,"Au sujet de l'application")
MenuItem(#MenuAppQuit ,"Fermer l'application")
EndIf
If CreateImageMenu(#MenuApp, WindowID(#WinApp), #PB_Menu_ModernLook)
MenuTitle("Fichier")
MenuItem(#MenuAppFolder , "Ouvrir le dossier de l'application")
MenuBar()
MenuItem(#MenuAppHomesite , "Visiter le site " + #homesite$)
MenuItem(#MenuAppHomepage , "Consulter la page de l'application")
MenuBar()
MenuItem(#MenuAppQuit , "Fermer l'application")
MenuTitle("Options")
MenuItem(#MenuAppLogin , "Saisir vos accès")
MenuTitle("Free")
MenuItem(#MenuAppHomefree , "Espace abonné Freemobile")
MenuTitle("?")
MenuItem(#MenuAppAbout , "Au sujet de l'application")
EndIf
If CreateStatusBar(#GadgetSB, WindowID(#WinApp))
AddStatusBarField(#PB_Ignore)
StatusBarText(#GadgetSB, 0, " Envoyez des notifications par SMS sur votre propre mobile", 0)
EndIf
Define X,Y,W,H,G
X=1:Y=1:W=#WinAppWidth-2:H=150
ContainerGadget(#GadgetCont, X, Y, W, H, #PB_Container_Flat)
X=2:Y=2:H=15:W=#WinAppWidth-8
TextGadget(#GadgetText, X, Y, W, H, "Message a envoyer", #PB_Text_Center)
;
X=2:Y=20:H=100:W=#WinAppWidth-8
EditorGadget(#GadgetEditor, X , Y , W , H, #PB_Editor_WordWrap)
X=2:Y=122:W=120:H=24
ButtonGadget(#GadgetBtnSend, X, Y, W, H, "Envoyer le message")
GadgetToolTip(#GadgetBtnSend, " Cliquez pour envoyer le SMS ")
;
X=#WinAppWidth-W-6:W=120
ButtonGadget(#GadgetBtnQuit, X, Y, W, H, "Fermer l'application")
GadgetToolTip(#GadgetBtnQuit, " Cliquez pour fermer l'application ")
;
X=4+120:Y=123:W=#WinAppWidth-(2*120)-12:H=22
StringGadget(#GadgetLogin, X, Y, W, H, "<login>|<pass>")
SetGadgetAttribute(#GadgetLogin, #PB_String_MaximumLength, 40)
HideGadget(#GadgetLogin, #True)
;
Define G
For G = #Gadget+1 To #GadgetEnd-1
SetGadgetColor(G, #PB_Gadget_BackColor , #bgcolor)
SetGadgetColor(G, #PB_Gadget_FrontColor, RGB(0,0,0))
Next
If LoadFont(#Font0, "Consolas", 9)
SetGadgetFont(#GadgetEditor , FontID(#Font0))
EndIf
Define input$ = #Null$
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Menu
indexMenu = EventMenu()
Select indexMenu
Case #MenuAppFolder
RunProgram(AppPath$,#Null$,AppPath$)
Case #MenuAppHomesite
RunProgram(#homesite$)
Case #MenuAppHomepage
RunProgram(#homepage$)
Case #MenuAppShow
showAppWindow()
Case #MenuAppAbout
appAbout()
Case #MenuAppQuit
Break
Case #MenuAppLogin
user$ = "" : pass$ = ""
SetGadgetText(#GadgetLogin, "Login | Password")
HideGadget(#GadgetLogin, #False)
EndSelect
;;;;;;;;;
;;;;;;;;; Events GADGETS
;;;;;;;;;
;---- Events GADGETS
Case #PB_Event_Gadget
indexGadget = EventGadget()
indexGadgetType = EventType()
Select indexGadget
Case #GadgetBtnQuit
Break
Case #GadgetBtnSend
SetGadgetText(#GadgetLogin, "")
HideGadget(#GadgetLogin, #True)
sendSMS()
Case #GadgetLogin
Select indexGadgetType
Case #PB_EventType_LostFocus,#PB_EventType_Focus,#PB_EventType_Change
Debug "LOGIN"
input$ = Trim(GetGadgetText(#GadgetLogin))
user$ = Trim(StringField(input$,1,"|"))
pass$ = Trim(StringField(input$,2,"|"))
Debug "user:"+user$
Debug "pass:"+pass$
EndSelect
EndSelect
;;;;;
;---- Events SYSTEM SYSTRAY
;;;;;
Case #PB_Event_SysTray
Select EventType()
Case #PB_EventType_RightClick
DisplayPopupMenu(#MenuTray, WindowID(#WinApp))
Case #PB_EventType_LeftClick
If GetWindowState(#WinApp) = #PB_Window_Normal
hideAppWindow()
Else
showAppWindow()
StickyWindow(#WinApp, #True)
EndIf
EndSelect
;;;;;
;;;;; Events system window
;;;;;
;---- Events SYSTEM WINDOW
Case #PB_Event_CloseWindow
hideAppWindow()
Case #PB_Event_MinimizeWindow
If optMinimize
HideWindow(#WinApp, #True)
EndIf
Case #PB_Event_MaximizeWindow
;
Case #PB_Event_RestoreWindow
;
EndSelect
ForEver
EndIf
;---- Events ERROR HANDLER
ErrorHandler:
Define lHwd = FindWindow_("Progman", #NUL)
ShowWindow_(lHwd, 8)
RemoveSysTrayIcon(#WinApp)
ReleaseMutex_(Mutex)
End