Примеры программ PureBasic

Чтобы использовать примеры, скачайте и используйте редактор.
|
1
2
3
|
If OpenWindow(0, 100, 100, 350, 400, "Заголовок", #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget) And CreateGadgetList(WindowID(0))
EndIf
End
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
;Для PB4
Procedure.l DropFiles ()
ProcedureReturn EventwParam ()
EndProcedure
;
Procedure GetNumDropFiles (*dropFiles)
ProcedureReturn DragQueryFile_ (*dropFiles, $FFFFFFFF, temp$, 0)
EndProcedure
;
Procedure.s GetDropFile (*dropFiles, index)
bufferNeeded = DragQueryFile_ (*dropFiles, index, 0, 0)
For a = 1 To bufferNeeded: buffer$ + " ": Next ; Short by one character!
DragQueryFile_ (*dropFiles, index, buffer$, bufferNeeded+1)
ProcedureReturn buffer$
EndProcedure
;
Procedure FreeDropFiles (*dropFiles)
DragFinish_ (*dropFiles)
EndProcedure
;
If OpenWindow (0, 100, 100, 300, 100, "Перетащите любой файл на окно", #PB_Window_SystemMenu)
DragAcceptFiles_ (WindowID(0), 1)
;
Repeat
Select WaitWindowEvent ()
Case #WM_DROPFILES
*dropped = DropFiles ()
num.l = DragQueryFile_ (*dropped , $FFFFFFFF, temp$, 0)
;
f$ = ""
For files = 0 To num - 1
f$ + GetDropFile (*dropped, files) + Chr (13)
Next
MessageBox_ (0, Str (num) + " file (s) dropped:" + Chr (13) + Chr (13) + f$, "Drag 'n' Drop", 0)
FreeDropFiles (*dropped)
;
Case #PB_Event_CloseWindow
Quit = 1
;
EndSelect
Until Quit = 1
EndIf
End
; IDE Options = PureBasic 4.51 (Windows - x86)
; CursorPosition = 20
; FirstLine = 2
; Folding = -
; EnableXP
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
; Автор - 22vlad
; http://purebasic.info/phpBB2/viewtopic.php?t=29&postdays=0&postorder=asc&start=15
If OpenWindow(0,0,0,300,300,"Test",#PB_Window_BorderLess|#PB_Window_ScreenCentered)
For i=10 To 290 Step 10
Rng=CreateRoundRectRgn_(i,i,300-i,300-i,100,100)
SetWindowRgn_(WindowID(0),Rng,#True)
Delay(100)
Next i
EndIf
End
; IDE Options = PureBasic 4.51 (Windows - x86)
; CursorPosition = 1
; EnableXP
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
; Автор - Rostislav
; http://purebasic.info/phpBB2/viewtopic.php?t=29&postdays=0&postorder=asc&start=30
Procedure pam()
For i=10 To 290 Step 10
Rng6=CreateRoundRectRgn_(i,i,320-i,240-i,100,100)
SetWindowRgn_(WindowID(0),Rng6,#True)
Delay(100)
Next i
DeleteObject_(hRgn6)
EndProcedure
If OpenWindow(0,0,0,320,240,"Test",#PB_Window_BorderLess|#PB_Window_ScreenCentered|#PB_Window_Invisible)
SetWindowColor(0,RGB(15, 215, 240))
CHILD_Win=OpenWindow(1,10,70,100,100,"",#PB_Window_Invisible)
SetParent_(CHILD_Win, WindowID(0))
ButtonGadget(0, 0, 0, 100, 100, "ТРЯМ :)")
CHILD_Win1=OpenWindow(2,110,70,100,100,"",#PB_Window_Invisible)
SetParent_(CHILD_Win1, WindowID(0))
ButtonGadget(1, 0, 0, 100, 100, "ВЫХОД")
CHILD_Win2=OpenWindow(3,210,70,100,100,"",#PB_Window_Invisible)
SetParent_(CHILD_Win2, WindowID(0))
ButtonGadget(2, 0, 0, 100, 100, "Свернуть")
SetWindowLong_(CHILD_Win,#GWL_STYLE, #WS_CHILD | #WS_VISIBLE)
SetWindowLong_(CHILD_Win,#GWL_EXSTYLE, 0)
SetWindowLong_(CHILD_Win1,#GWL_STYLE, #WS_CHILD | #WS_VISIBLE)
SetWindowLong_(CHILD_Win1,#GWL_EXSTYLE, 0)
SetWindowLong_(CHILD_Win2,#GWL_STYLE, #WS_CHILD | #WS_VISIBLE)
SetWindowLong_(CHILD_Win2,#GWL_EXSTYLE, 0)
hRgn1 = CreateEllipticRgn_(0,0,320,240)
hRgn = CreateRectRgn_(10,0,310,60)
hRgn5 = CreateEllipticRgn_(120,220,200,180)
CombineRgn_(hRgn1, hRgn1, hRgn, #RGN_OR)
CombineRgn_(hRgn1, hRgn1, hRgn5, #RGN_XOR)
SetWindowRgn_(WindowID(0),hRgn1,#False)
hRgn2 = CreateEllipticRgn_(10,30,90,70)
SetWindowRgn_(CHILD_Win,hRgn2,#False)
hRgn4 = CreateRoundRectRgn_( 10, 10, 90, 90, 40, 40)
SetWindowRgn_(CHILD_Win2,hRgn4,#False)
hRgn3 = CreateEllipticRgn_(10,10,90,90)
SetWindowRgn_(CHILD_Win1,hRgn3,#False)
DeleteObject_(hRgn)
DeleteObject_(hRgn1)
DeleteObject_(hRgn2)
DeleteObject_(hRgn3)
DeleteObject_(hRgn4)
DeleteObject_(hRgn5)
HideWindow(0,0)
Repeat
EventID = WaitWindowEvent()
Select EventID
Case #WM_LBUTTONDOWN
If WindowMouseX(0) >= 0 And WindowMouseX(0) <= 320 And WindowMouseY(0) >= 0 And WindowMouseY(0) <= 240
SendMessage_(WindowID(0), #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
EndIf
EndSelect
If EventID = #PB_Event_Gadget
GadgetID = EventGadget()
If GadgetID = 0
pam()
EndIf
If GadgetID = 1
EventID = #PB_Event_CloseWindow
EndIf
If GadgetID = 2
SetWindowState(0,#PB_Window_Minimize)
EndIf
EndIf
Until EventID = #PB_Event_CloseWindow
EndIf
; IDE Options = PureBasic 4.51 (Windows - x86)
; CursorPosition = 1
; Folding = -
; EnableXP
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
; Автор - MadPsychoCell
; http://purebasic.info/phpBB2/viewtopic.php?t=148&postdays=0&postorder=asc&start=30
Procedure.l CalcEaster(Year.l = #PB_Ignore)
Static B.l,D.l,E.l,Q.l, Result.l
If Year = #PB_Ignore
Year = Year(Date())
EndIf
B = 225 - 11*(Year % 19)
D = ((B-21) % 30) + 21
If D > 48
D - 1
EndIf
E = (Year + Int(Year / 4) + D + 1 ) % 7
Q = D + 7 - E
If Q < 32
Result = Date(Year,3,Q,0,0,0)
Else
Result = Date(Year,4,Q - 31,0,0,0)
EndIf
ProcedureReturn Result
EndProcedure
;пример показывающий дату пасхи в текущем году
Date = CalcEaster()
Debug Str(Day(Date)) + "." + Str(Month(Date)) + "." + Str(Year(Date))
; IDE Options = PureBasic 4.51 (Windows - x86)
; CursorPosition = 1
; Folding = -
; EnableXP
|
|
1
2
3
4
5
6
7
8
9
|
Repeat
If GetAsyncKeyState_(#VK_RBUTTON)=-32767 ; Жмем на правую кнопку мышки.
Debug GetPixelColor(GetMouseX(),GetMouseY())
EndIf
Delay(100)
Until GetAsyncKeyState_(#VK_ESCAPE) ; Прога закроется при шажатии кнопку "Esc" на клавиатуре.
; IDE Options = PureBasic 4.51 (Windows - x86)
; CursorPosition = 2
; EnableXP
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
; Автор - MadPsychoCell
; http://purebasic.info/phpBB2/viewtopic.php?t=148&postdays=0&postorder=asc&start=15
;получить частоту процессора (в Мегагерцах)
Procedure.d GetCPUFreq(DelayTime.l=500)
Static TimerHi.l, TimerLo.l, PriorityClass .l, Priority .l, Process.l, Thread.l
Process = GetCurrentProcess_()
Thread = GetCurrentThread_()
PriorityClass = GetPriorityClass_(Process)
Priority = GetThreadPriority_(Thread)
SetPriorityClass_(Process, #REALTIME_PRIORITY_CLASS)
SetThreadPriority_(Thread, #THREAD_PRIORITY_TIME_CRITICAL)
Sleep_(DelayTime)
DW $310F
MOV TimerLo, EAX
MOV TimerHi, EDX
Sleep_(DelayTime)
DW $310F
SUB EAX, TimerLo
SUB EDX, TimerHi
MOV TimerLo, EAX
MOV TimerHi, EDX
SetThreadPriority_(Thread,Priority)
SetPriorityClass_ (Process,PriorityClass)
ProcedureReturn TimerLo / (1000.0 * DelayTime)
EndProcedure
;пример использования
F.d = GetCPUFreq()
GHz = Int(F / 1000)
MHz = F - GHz*1000
Debug "Частота процессора: "+Str(GHz)+"GHz "+Str(MHz)+"MHz"
; IDE Options = PureBasic 4.51 (Windows - x86)
; CursorPosition = 1
; Folding = -
; EnableAsm
; EnableXP
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
Procedure Timer1()
Layout=GetKeyboardLayout_(0)
If Layout=68748313
SetGadgetText(0,"Русский")
ElseIf Layout=67699721
SetGadgetText(0,"Английский")
Else
SetGadgetText(0,"хз, какой - "+Str(Layout))
EndIf
EndProcedure
If OpenWindow(0, 0, 0, 270, 100, "Язык программы", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
TextGadget(0, 10, 40, 250, 20, "") : Timer1()
SetTimer_(WindowID(0), 0, 400, @Timer1())
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
; IDE Options = PureBasic 4.51 (Windows - x86)
; CursorPosition = 12
; Folding = -
; EnableXP
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
; Автор - kvitaliy
; http://purebasic.info/phpBB2/viewtopic.php?t=1446
Procedure MakeDesktopScreenshot(ImageNr,x,y,Width,Height)
hImage = CreateImage(ImageNr,Width,Height)
hDC = StartDrawing(ImageOutput(ImageNr))
DeskDC = GetDC_(GetDesktopWindow_())
BitBlt_(hDC,0,0,Width,Height,DeskDC,x,y,#SRCCOPY)
StopDrawing()
ReleaseDC_(GetDesktopWindow_(),DeskDC)
ProcedureReturn hImage
EndProcedure
; Проверка работы
For i=1 To 5
MakeDesktopScreenshot(0, 0, 0, GetSystemMetrics_(#SM_CXSCREEN), GetSystemMetrics_(#SM_CYSCREEN))
SaveImage(0, "C:\Temp\"+Str(i)+".bmp")
Delay(100)
Next i
; IDE Options = PureBasic 4.51 (Windows - x86)
; CursorPosition = 1
; Folding = -
; EnableXP
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
; Автор - haav
; http://purebasic.mybb.ru/viewtopic.php?id=131
NewList OBOI.s() ; создаем список для файлов с обоями
If ExamineDirectory(0, GetCurrentDirectory()+"OBOI\", "*.bmp") ; ищем каталог с обоями
While NextDirectoryEntry(0) ;считываем все имеющиеся файлы в формате .bmp
AddElement(OBOI())
OBOI()= DirectoryEntryName(0) ; загоняем имена файлов в список
Wend
razmeroboi=ListSize(OBOI()) ; получаем размер листа
FinishDirectory(0)
SelectElement(OBOI(),Random(razmeroboi-1)) ; станавливаем случайную обоину
SystemParametersInfo_(#SPI_SETDESKWALLPAPER, 0, "OBOI\"+OBOI.s(), #SPIF_UPDATEINIFILE | #SPIF_SENDWININICHANGE) ;клеим обои
EndIf
; IDE Options = PureBasic 4.51 (Windows - x86)
; CursorPosition = 4
; EnableXP
|
