;usefull dialog boxes ripped off from other people ;first, the timed messagebox function ;*************************************************************************** ; Program: Yet another timed messagebox sample ; Source: http://support.microsoft.com/?scid=181934 ; PB version by: netmaestro ; Date: March 21, 2007 ; Applies to: Anyone who likes timed message boxes ; Disclaimer: Hardly any animals were harmed during the creation of ; this software. (one who whined got his feelings hurt) ;*************************************************************************** #MessageBox_Timeout = -1 Global g_hwndTimedOwner Global g_bTimedOut Procedure MessageBoxTimer(hwnd, uiMsg, idEvent, dwTime) g_bTimedOut = #True If g_hwndTimedOwner EnableWindow_(g_hwndTimedOwner, #True) EndIf PostQuitMessage_(0) EndProcedure Procedure TimedMessageBox(hwndOwner, pszMessage.s, pszTitle.s, flags, dwTimeout) Protected idTimer.l, iResult.l g_hwndTimedOwner = #Null g_bTimedOut = #False If hwndOwner And IsWindowEnabled_(hwndOwner) g_hwndTimedOwner = hwndOwner EndIf idTimer.l = SetTimer_(#Null, 0, dwTimeout, @MessageBoxTimer()) iResult.l = MessageBox_(hwndOwner, pszMessage, pszTitle, flags) KillTimer_(#Null, idTimer) If g_bTimedOut PeekMessage_(@msg.MSG, #Null, #WM_QUIT, #WM_QUIT, #PM_REMOVE) iResult = #MessageBox_Timeout EndIf ProcedureReturn iResult EndProcedure ; and a find/replace dialog box from oneText text editor 20070304 ; Copyright (c)2007, Stig h. Johansen and Utopiomania.com Procedure findReplace(id,Sflag) ;ID is the #GadgetID for the rich edit control gadet ;S$ = lastsearch string checked for ;R$ = last replace string checked for ;Sflag = 0 for new check or replace ; 1 for continue search ; 2 for continue replace Static S$ Static R$ flags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered win = OpenWindow(#PB_Any, 0, 0, 400, 145, "Find/Replace", flags) If win StickyWindow(win, #True) If CreateGadgetList(WindowID(win)) ;draw the find icon img1 = CreateImage(#PB_Any, 22, 22) If StartDrawing(ImageOutput(img1)) Box(0, 0, 24, 24, GetSysColor_(15)) ;icon index 176, 55 ExtractIconEx_("shell32.dll", 176, 0, @icon, 1) If icon DrawImage(icon, 0, 0, 21, 21) DestroyIcon_(icon) EndIf StopDrawing() EndIf If 1 ImageGadget(#PB_Any, 10, 15, 0, 0, ImageID(img1)) TextGadget(#PB_Any, 40, 20, 75, 22, "Find:") Else TextGadget(#PB_Any, 10, 20, 75, 22, "Find What:") EndIf str1 = StringGadget(#PB_Any, 100, 15, 200, 21, S$) TextGadget(#PB_Any, 10, 50, 75, 22, "Replace With:") str2 = StringGadget(#PB_Any, 100, 45, 200, 21, R$) btn1 = ButtonGadget(#PB_Any, 310, 15, 80, 22, "Find Next", #PB_Button_Default) DisableGadget(btn1, #True) btn2 = ButtonGadget(#PB_Any, 310, 45, 80, 22, "Replace") DisableGadget(btn2, #True) btn3 = ButtonGadget(#PB_Any, 310, 80, 80, 22, "Replace all") DisableGadget(btn3, #True) btn4 = ButtonGadget(#PB_Any, 310, 110, 80, 22, "Cancel") chk1 = CheckBoxGadget(#PB_Any, 10, 80, 120, 22, "Match Case") chk2 = CheckBoxGadget(#PB_Any, 10, 112, 120, 22, "Whole Words only") chk3 = CheckBoxGadget(#PB_Any, 140, 112, 160, 22, "Search From Top") If SFlag=0 ;get any selected text in the richedit SendMessage_(GadgetID(id), #EM_EXGETSEL, 0, @text.FINDTEXT\chrg) If (text\chrg\cpMin <> text\chrg\cpMax) ;selected text range found, check it's length len = text\chrg\cpMax - text\chrg\cpMin If len < 128 Debug len char.c *txt = AllocateMemory((len + 1) * SizeOf(char)) ;get the selected text SendMessage_(GadgetID(id), #EM_GETSELTEXT, 0, *txt) SetGadgetText(str1, PeekS(*txt)) FreeMemory(*txt) ;focus the replace input field SetActiveGadget(str2) ;enable the buttons DisableGadget(btn1, #False) DisableGadget(btn2, #False) DisableGadget(btn3, #False) EndIf Else ;focus the findstring input field SetActiveGadget(str1) EndIf ;no text found yet: pos = -1 Else ;set up buttons to continue operations DisableGadget(btn1, #False) find.s = GetGadgetText(str1) text.FINDTEXT\lpstrText = @find ;get current position or selected range in the text SendMessage_(GadgetID(id), #EM_EXGETSEL, 0, @text\chrg) If (text\chrg\cpMin <> text\chrg\cpMax) ;selected text range found, search from the end of it text\chrg\cpMin = text\chrg\cpMax EndIf If GetGadgetState(chk3) ;reset, search from the top SetGadgetState(chk3, 0) text\chrg\cpMin = 0 EndIf ;search to the end of the text: text\chrg\cpMax = -1 ;set the search flags flg = 0 flg | #FR_DOWN If GetGadgetState(chk1) flg | #FR_MATCHCASE EndIf If GetGadgetState(chk2) flg | #FR_WHOLEWORD EndIf pos = SendMessage_(GadgetID(id), #EM_FINDTEXT, flg, @text) If pos <> -1 ;found, select the text range SendMessage_(GadgetID(id), #EM_SETSEL, pos, pos + Len(find)) Else msg.s = "Cannot find " + find + Chr(13) + Chr(10) msg + "Search again from the top ?" flags = #MB_ICONQUESTION | #MB_YESNOCANCEL Select MessageRequester("Find/Replace", msg, flags) Case #IDYES ;first position in the text SendMessage_(GadgetID(id), #EM_SETSEL, 0, 0) text\chrg\cpMin = 0 ;search to the end of the text: text\chrg\cpMax = -1 pos = SendMessage_(GadgetID(id), #EM_FINDTEXT, flg, @text) If pos <> -1 ;found, select the text range SendMessage_(GadgetID(id), #EM_SETSEL, pos, pos + Len(find)) Else msg.s = "Cannot find " + find flags = #MB_ICONINFORMATION | #MB_OK MessageRequester("Find/Replace", msg, flags) EndIf SetActiveGadget(id) EndSelect EndIf If SFlag>1 DisableGadget(btn2, #False) DisableGadget(btn3, #False) EndIf EndIf ;default search flag flg | #FR_DOWN Repeat event = WaitWindowEvent() If EventWindow() = win Select event Case #PB_Event_Gadget Select EventGadget() Case str1 ;find string GadgetToolTip(str1, GetGadgetText(str1)) If Len(GetGadgetText(str1)) DisableGadget(btn1, #False) DisableGadget(btn2, #False) DisableGadget(btn3, #False) S$=GetGadgetText(str1) Else DisableGadget(btn1, #True) DisableGadget(btn2, #True) DisableGadget(btn3, #True) EndIf Case str2 ;replace string GadgetToolTip(str2, GetGadgetText(str2)) R$=GetGadgetText(str2) Case btn1 ;find button find.s = GetGadgetText(str1) text.FINDTEXT\lpstrText = @find ;get current position or selected range in the text SendMessage_(GadgetID(id), #EM_EXGETSEL, 0, @text\chrg) If (text\chrg\cpMin <> text\chrg\cpMax) ;selected text range found, search from the end of it text\chrg\cpMin = text\chrg\cpMax EndIf If GetGadgetState(chk3) ;reset, search from the top SetGadgetState(chk3, 0) text\chrg\cpMin = 0 EndIf ;search to the end of the text: text\chrg\cpMax = -1 ;set the search flags flg = 0 flg | #FR_DOWN If GetGadgetState(chk1) flg | #FR_MATCHCASE EndIf If GetGadgetState(chk2) flg | #FR_WHOLEWORD EndIf pos = SendMessage_(GadgetID(id), #EM_FINDTEXT, flg, @text) If pos <> -1 ;found, select the text range SendMessage_(GadgetID(id), #EM_SETSEL, pos, pos + Len(find)) Else msg.s = "Cannot find " + find + Chr(13) + Chr(10) msg + "Search again from the top ?" flags = #MB_ICONQUESTION | #MB_YESNOCANCEL Select MessageRequester("Find/Replace", msg, flags) Case #IDYES ;first position in the text SendMessage_(GadgetID(id), #EM_SETSEL, 0, 0) text\chrg\cpMin = 0 ;search to the end of the text: text\chrg\cpMax = -1 pos = SendMessage_(GadgetID(id), #EM_FINDTEXT, flg, @text) If pos <> -1 ;found, select the text range SendMessage_(GadgetID(id), #EM_SETSEL, pos, pos + Len(find)) Else msg.s = "Cannot find " + find flags = #MB_ICONINFORMATION | #MB_OKCANCEL Select MessageRequester("Find/Replace", msg, flags) Case #IDCANCEL Break EndSelect EndIf SetActiveGadget(id) Case #IDCANCEL Break EndSelect EndIf Case btn2 ;replace button ;get selected range in the text SendMessage_(GadgetID(id), #EM_EXGETSEL, 0, @text\chrg) If (text\chrg\cpMin <> text\chrg\cpMax) ;found selected text range repl.s = GetGadgetText(str2) If text\chrg\cpMax - text\chrg\cpMin = Len(GetGadgetText(str1)) ;same length as the find string, replace it SendMessage_(GadgetID(id), #EM_REPLACESEL, 1, @repl) ;advance the current position text\chrg\cpMin + Len(repl) EndIf Else ;no selection made yet, search from the current position text\chrg\cpMin = text\chrg\cpMax EndIf If GetGadgetState(chk3) ;reset, search from the top SetGadgetState(chk3, 0) text\chrg\cpMin = 0 EndIf ;search to the end of the text: text\chrg\cpMax = -1 find.s = GetGadgetText(str1) text\lpstrText = @find ;set the search flags flg = 0 flg | #FR_DOWN If GetGadgetState(chk1) flg | #FR_MATCHCASE EndIf If GetGadgetState(chk2) flg | #FR_WHOLEWORD EndIf pos = SendMessage_(GadgetID(id), #EM_FINDTEXT, flg, @text) If pos <> -1 ;found, select the text range SendMessage_(GadgetID(id), #EM_SETSEL, pos, pos + Len(find)) Else msg.s = "Cannot find " + find + Chr(13) + Chr(10) msg + "Search again from the top ?" flags = #MB_ICONQUESTION | #MB_YESNOCANCEL Select MessageRequester("Find/Replace", msg, flags) Case #IDYES ;first position in the text SendMessage_(GadgetID(id), #EM_SETSEL, 0, 0) text\chrg\cpMin = 0 ;search to the end of the text: text\chrg\cpMax = -1 pos = SendMessage_(GadgetID(id), #EM_FINDTEXT, flg, @text) If pos <> -1 ;found, select the text range SendMessage_(GadgetID(id), #EM_SETSEL, pos, pos + Len(find)) Else msg.s = "Cannot find " + find flags = #MB_ICONINFORMATION | #MB_OKCANCEL Select MessageRequester("Find/Replace", msg, flags) Case #IDCANCEL Break EndSelect EndIf Case #IDCANCEL Break EndSelect EndIf Case btn3 ;replace all button Repeat ;get selected range in the text SendMessage_(GadgetID(id), #EM_EXGETSEL, 0, @text\chrg) If (text\chrg\cpMin <> text\chrg\cpMax) ;found selected text range repl.s = GetGadgetText(str2) If text\chrg\cpMax - text\chrg\cpMin = Len(GetGadgetText(str1)) ;same length as the find string, replace it SendMessage_(GadgetID(id), #EM_REPLACESEL, 1, @repl) ;advance the current position text\chrg\cpMin + Len(repl) EndIf Else ;no selection made yet, search from the current position text\chrg\cpMin = text\chrg\cpMax EndIf If GetGadgetState(chk3) ;reset, search from the top SetGadgetState(chk3, 0) text\chrg\cpMin = 0 EndIf ;search to the end of the text: text\chrg\cpMax = -1 find.s = GetGadgetText(str1) text\lpstrText = @find ;set the search flags flg = 0 flg | #FR_DOWN If GetGadgetState(chk1) flg | #FR_MATCHCASE EndIf If GetGadgetState(chk2) flg | #FR_WHOLEWORD EndIf pos = SendMessage_(GadgetID(id), #EM_FINDTEXT, flg, @text) If pos <> -1 ;found, select the text range SendMessage_(GadgetID(id), #EM_SETSEL, pos, pos + Len(find)) EndIf Until pos = -1 msg.s = "Cannot find " + find + Chr(13) + Chr(10) msg + "Search again from the top ?" flags = #MB_ICONQUESTION | #MB_YESNOCANCEL Select MessageRequester("Find/Replace", msg, flags) Case #IDYES ;first position in the text SendMessage_(GadgetID(id), #EM_SETSEL, 0, 0) text\chrg\cpMin = 0 ;search to the end of the text: text\chrg\cpMax = -1 pos = SendMessage_(GadgetID(id), #EM_FINDTEXT, flg, @text) If pos <> -1 ;found, select the text range SendMessage_(GadgetID(id), #EM_SETSEL, pos, pos + Len(find)) Else msg.s = "Cannot find " + find flags = #MB_ICONINFORMATION | #MB_OKCANCEL Select MessageRequester("Find/Replace", msg, flags) Case #IDCANCEL Break EndSelect EndIf Case #IDCANCEL Break EndSelect Case btn4 ;cancel button Break EndSelect Case #PB_Event_CloseWindow Break EndSelect EndIf ForEver EndIf CloseWindow(win) EndIf EndProcedure Procedure.s toolsDatePicker(parent) ;parent is then #WindowID of the main window ;the return value is the date string from date.s = GetGadgetText(#DATE1) flags = #PB_Window_ScreenCentered | #PB_Window_SystemMenu win = OpenWindow(#PB_Any, 0, 0, 300, 220, "Date Picker", flags) If win EnableWindow_(WindowID(parent), #False) StickyWindow(win, #True) ResizeWindow(win, #PB_Ignore, WindowY(win) - 50, #PB_Ignore, #PB_Ignore) CreateGadgetList(WindowID(win)) Date1=DateGadget(#PB_Any, 0, 0, 300, 24) btn1 = ButtonGadget(#PB_Any, 120, 185, 80, 24, "Insert") btn2 = ButtonGadget(#PB_Any, 210, 185, 80, 24, "Cancel" ) Repeat event = WaitWindowEvent() Select event Case #PB_Event_Gadget Select EventGadget() Case btn1 date.s = GetGadgetText(DATE1) exit = #True Case btn2 date.s = "" exit = #True EndSelect Case #PB_Event_CloseWindow exit = #True EndSelect Until exit CloseWindow(win) EndIf EnableWindow_(WindowID(parent), #True) SetActiveWindow(parent) ProcedureReturn date EndProcedure Procedure about(parent, text.s) ;field delimiter nf.s = Chr(8) ;fields about.s = StringField(text, 1, nf) name.s = StringField(text, 2, nf) corp.s = StringField(text, 3, nf) txt.s = StringField(text, 4, nf) url.s = StringField(text, 5, nf) lnk.s = StringField(text, 6, nf) flags = #PB_Window_ScreenCentered | #PB_Window_SystemMenu win = OpenWindow(#PB_Any, 0, 0, 420, 325, name, flags) If win EnableWindow_(WindowID(parent), #False) StickyWindow(win, #True) ResizeWindow(win, #PB_Ignore, WindowY(win) - 50, #PB_Ignore, #PB_Ignore) If CreateGadgetList(WindowID(win)) img1 = CreateImage(#PB_Any, 420, 70) fnt1 = LoadFont(#PB_Any, "", 10) fnt2 = LoadFont(#PB_Any, "", 16) If StartDrawing(ImageOutput(img1)) DrawingMode(#PB_2DDrawing_Transparent) ;header background gradient For x = 0 To 419 LineXY(x, 0, x, 60, RGB(x / 2.5, x / 2.5, 255)) LineXY(x, 60, x, 70, RGB(225- x / 5, 225 - x / 5, 255)) Next x ;header icon ;res.s = "shell32.dll" ;ndx = 130 res.s = ProgramFilename() ndx = 0 ExtractIconEx_(res, ndx, 0, @icon, 1) If icon DrawImage(icon, 10, 5, 48, 48) DestroyIcon_(icon) Else ExtractIconEx_("shell32.dll", 130, 0, @icon, 1) If icon DrawImage(icon, 10, 5, 48, 48) DestroyIcon_(icon) EndIf EndIf ;header about field If fnt1 DrawingFont(FontID(fnt1)) EndIf DrawText(70, 10, about, RGB(255, 255, 255)) ;header program name field If fnt2 DrawingFont(FontID(fnt2)) EndIf DrawText(70, 28, name, RGB(255, 255, 255)) ;header company name field If fnt1 DrawingFont(FontID(fnt1)) EndIf DrawText(400 - TextWidth(corp), 35, corp, RGB(255, 255, 255)) StopDrawing() EndIf ImageGadget(#PB_Any, 0, 0, 0, 0, ImageID(img1)) ;text icon img2 = CreateImage(#PB_Any, 32, 32) If StartDrawing(ImageOutput(img2)) Box(0, 0, 32, 32, GetSysColor_(15)) ;res.s = "shell32.dll" ;ndx = 166 ;ndx = 55 res.s = ProgramFilename() ndx = 0 ExtractIconEx_(res, ndx, 0, @icon, 1) If icon DrawImage(icon, 0, 0, 32, 32) DestroyIcon_(icon) Else ExtractIconEx_("shell32.dll", 55, 0, @icon, 1) If icon DrawImage(icon, 0, 0, 32, 32) DestroyIcon_(icon) EndIf EndIf StopDrawing() EndIf ImageGadget(#PB_Any, 20, 100, 0, 0, ImageID(img2)) ;text TextGadget(#PB_Any, 70, 100, 330, 145, txt) ;divider line img3 = CreateImage(#PB_Any, 410, 2) If StartDrawing(ImageOutput(img3)) Line(0, 0, 420, 0, RGB(160, 160, 160)) Line(0, 1, 420, 0, RGB(255, 255, 255)) StopDrawing() EndIf ImageGadget(#PB_Any, 10, 260, 0, 0, ImageID(img3)) ;online link If Len(url) lnk1 = HyperLinkGadget(#PB_Any, 20, 275, 200, 24, url, RGB(0, 0, 255), #PB_HyperLink_Underline) SetGadgetColor(lnk1, #PB_Gadget_FrontColor, RGB(0, 0, 255)) EndIf ;ok button btn1 = ButtonGadget(#PB_Any, 330, 288, 80, 24, "OK", #PB_Button_Default) SetActiveGadget(btn1) EndIf Repeat event = WaitWindowEvent() Select event Case #PB_Event_Gadget Select EventGadget() Case lnk1 RunProgram(lnk) exit = #True Case btn1 exit = #True EndSelect Case #PB_Event_CloseWindow exit = #True EndSelect Until exit CloseWindow(win) EndIf EnableWindow_(WindowID(parent), #True) SetActiveWindow(parent) EndProcedure Procedure TestAbout(parent) ;next field nf.s = Chr(8) ;next line nl.s = Chr(13) + Chr(10) AppName.s=GetFilePart(ProgramFilename()) ;about field txt.s = "About " + nf ;program name field txt + "'" + AppName + "'" + nf ;company field txt + "www.utopiomania.com" + nf ;main text field txt + "'" + AppName + "', a simple text editor" + nl + nl txt + "Ver. 1.0, date 20070302" + nl txt + "" + nl + nl txt + nl + "Copyright (c)2007, Stig h. Johansen and Utopiomania.com" + nl + nl + nl txt + "WARNING: This PROGRAM is protected by copyright law and international treaties."+ nf ;online link field txt + "Visit '" + appName + "' online" + nf txt + "http://www.utopiomania.com" about(parent, txt) EndProcedure Procedure WrapAbout(parent,comp$,desc$,ver$,cwt$,link$) ;next field nf.s = Chr(8) ;next line nl.s = Chr(13) + Chr(10) AppName.s=GetFilePart(ProgramFilename()) ;about field txt.s = "About " + nf ;program name field txt + "'" + AppName + "'" + nf ;company field txt + comp$ + nf ;main text field txt + "'" + AppName + "' "+desc$ + nl + nl build$=FormatDate("%YYYY %MM %DD",#PB_Compiler_Date ) txt + "Ver. "+ver$+", date "+build$ + nl txt + "" + nl + nl txt + nl + "Copyright (c)"+cwt$ + nl + nl + nl txt + "WARNING: This PROGRAM is protected by copyright law and international treaties."+ nf ;online link field txt + "Visit '" + comp$ + "' online" + nf txt + link$ about(parent, txt) EndProcedure ; IDE Options = PureBasic v4.02 (Windows - x86) ; CursorPosition = 640 ; FirstLine = 608 ; Folding = --