-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo2.prg
194 lines (157 loc) · 5.98 KB
/
demo2.prg
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
* MINIGUI - Harbour Win32 GUI library Demo
*
* Copyright 2020 Sergej Kiselev <[email protected]>
* Copyright 2020 Verchenko Andrey <[email protected]> Dmitrov, Moscow region
*
* Çàïóñê âòîðîé êîïèè ïðîãðàììû ñ îæèäàíèåì.
* Launching a second copy of the program pending.
*/
#define _HMG_OUTLOG
#define SHOW_TITLE "My test program (2)"
#include "hmg.ch"
PROCEDURE MAIN(cParam)
LOCAL nY, nX, nW, nH, cMsg
DEFAULT cParam := ""
SET CODEPAGE TO RUSSIAN
SET LANGUAGE TO RUSSIAN
SET MSGALERT BACKCOLOR TO { 238, 249, 142 } // for HMG_Alert()
DEFINE FONT DlgFont FONTNAME "DejaVu Sans Mono" SIZE 14 // for HMG_Alert()
SET FONT TO "DejaVu Sans Mono", 12
SET OOP ON
IF cParam == "RESTART"
cMsg := SHOW_TITLE +": Çàïóñê âòîðîé êîïèè ïðîãðàììû / Starting a second copy of the program"
? cMsg
SET WINDOW MAIN OFF
WaitWindow( cMsg, .T. )
nY := 0
DO WHILE myIsProgaInMemory(SHOW_TITLE,"HMG_", .T.)
? "." ; ? "-------- Is there a program in memory ["+SHOW_TITLE+",HMG_*] ? ------ For:",nY++
wApi_Sleep(500)
ENDDO
WaitWindow() // close the wait window
SET WINDOW MAIN ON
ENDIF
// Ïðîâåðêà íà çàïóñê âòîðîé êîïèè ïðîãðàììû
// Check to run a second copy of the program
OnlyOneInstance( SHOW_TITLE, .T. )
nY := nX := 0; nW := System.ClientWidth ; nH := 150
DEFINE WINDOW test ;
AT 155, nX WIDTH nW HEIGHT nH ;
TITLE SHOW_TITLE ;
ICON "1MAIN_ICO" ;
MAIN NOMAXIMIZE NOSIZE ;
BACKCOLOR { 238, 249, 142 } ;
ON INIT {|| This.Label_1.Setfocus } ;
ON RELEASE {|| myExitPrg() } ;
ON INTERACTIVECLOSE {|| myExitPrg("[x]") }
nW := This.ClientWidth
nH := This.ClientHeight - GetTitleHeight()
DEFINE MAIN MENU
POPUP "Run"
ITEM "Çàïóñê êîïèè ïðîãðàììû" ACTION myRestart()
ITEM "Running a copy of the program" ACTION myRestart()
SEPARATOR
ITEM "Exit" ACTION ThisWindow.Release
END POPUP
POPUP "About"
ITEM "Info" ACTION MsgAbout()
END POPUP
END MENU
@ 0, 0 LABEL Label_1 VALUE "" WIDTH nW HEIGHT nH SIZE 22 TRANSPARENT CENTERALIGN VCENTERALIGN
This.Minimize ; This.Restore ; DO EVENTS
END WINDOW
test.Activate
RETURN
//////////////////////////////////////////////////////////////////
STATIC FUNCTION myExitPrg(cVal)
LOCAL nI
DEFAULT cVal := ""
? "..." ; ? "Program is exit [" + SHOW_TITLE + "] " + cVal + " " + TIME()
DbCloseAll()
IF ! ThisWindow.Closable
For nI := 20 to 1 Step -1
This.Label_1.Value := "Closing a program through " + HB_NtoS(nI)
wApi_Sleep(200)
Next
ENDIF
RETURN .T.
//////////////////////////////////////////////////////////////////
STATIC FUNCTION myRestart()
ThisWindow.Closable := .F. // ïî [X] çàêðûòü îêíî áëîêèðóåì è ïîòîì àíàëèçèðóåì
WaitWindow( 'Restart the program ...', .T. )
? " ."
? " ShellExecute( , 'open', '" + Application.ExeName + "' , RESTART , 2 )"
? " ."
ShellExecute( , 'open', Application.ExeName, "RESTART", , 2 )
ReleaseAllWindows() // çàêðûòü ïðîãðàììó
RETURN NIL
//////////////////////////////////////////////////////////////////
FUNCTION MsgAbout()
LOCAL cMsg
cMsg := SHOW_TITLE + ";;"
cMsg += "Çàïóñê âòîðîé êîïèè ïðîãðàììû ñ îæèäàíèåì;"
cMsg += "Launching a second copy of the program pending;;"
cMsg += hb_compiler() + ";" + Version() + ";" + MiniGuiVersion() + ";;"
cMsg += PadC( "This program is Freeware!", 70 ) + ";"
cMsg += PadC( "Copying is allowed!", 70 )
AlertInfo(cMsg,"About this demo")
RETURN NIL
//////////////////////////////////////////////////////////////////
// Èñïîëüçîâàíèå EnumWindows - ñïèñîê îêîí ïðîãðàìì â ïàìÿòè
// Using EnumWindows - a list of program windows in memory
FUNCTION myIsProgaInMemory( cAppTitle, cMskClass, lLogOut)
LOCAL nI, cI, lRet := .F., ahWnd := EnumWindows()
cAppTitle := UPPER(cAppTitle)
IF ! Empty(lLogOut)
FOR nI := 1 TO Len(ahWnd)
cI := ""
BEGIN SEQUENCE WITH {|e| break( e ) }
cI := GetClassName(ahWnd[nI])
END SEQUENCE
IF empty(cI) ; LOOP
ENDIF
IF empty(cMskClass) .or. cMskClass $ cI
? nI, '.', ahWnd[nI], cI, GetWindowText(ahWnd[nI])
// ïðèìåð êàê áóäåò â ëîã-ôàéëå:
// 21 . 984750 HMG_FORM__HMG_CHILDWAITWINDOW ''
// 24 . 1115838 HMG_FORM__HMG_CHILDWAITWINDOW ''
// 26 . 15795926 HMG_FORM_test My test program
// 34 . 591448 HMG_FORM_Forma_1 Convert Dbf to Xls
// 86 . 9504564 HMG_FORM_Form_Main Compare / merge two dbf
ENDIF
NEXT
?
ENDIF
FOR nI := 1 TO Len(ahWnd)
// ïðîâåðêà çàïóñêà ïðîãðàììû ÒÎËÜÊÎ äëÿ ÌèíèÃóè
// check the launch of the program ONLY for MiniGui
cI := ""
BEGIN SEQUENCE WITH {|e| break( e ) }
cI := GetClassName(ahWnd[nI])
END SEQUENCE
IF empty(cI) ; LOOP
ENDIF
IF cMskClass $ cI .AND. UPPER(GetWindowText(ahWnd[nI])) == cAppTitle
lRet := .T.
EXIT
ENDIF
NEXT
RETURN lRet
//////////////////////////////////////////////////////////////////
// Ïðîâåðêà çàïóñêà ïðîãðàììû íà ÂÒÎÐÓÞ êîïèþ ïðîãðàììû
// Check the start of the program on the second copy of the program
Function OnlyOneInstance( cAppTitle, lLogOut )
Local hWnd := FindWindowEx( ,,, cAppTitle )
if hWnd # 0
iif( IsIconic( hWnd ), _Restore( hWnd ), SetForeGroundWindow( hWnd ) )
if ! Empty(lLogOut)
? PROCNAME(0), cAppTitle, hWnd, "ExitProcess( 0 ) -> Program is already running"
endif
ExitProcess( 0 )
else
if ! Empty(lLogOut)
? "..." ; ? "Program is running [" + SHOW_TITLE + "] " + TIME() + " ProcLine()=",ProcLine()
endif
endif
Return NIL