485
edits
m (fixing starzen link) |
(Updated "createmutex succeeded" test to test for NULL not ERROR_INVALID_HANDLE as per Frank Cheng's recommendation see https://support.dataaccess.com/Forums/showthread.php?67791-Limiting-Dataflex-Instances-to-1-per-Laptop&p=368346#post368346) |
||
(3 intermediate revisions by one other user not shown) | |||
Line 3: | Line 3: | ||
# Using mutexes | # Using mutexes | ||
# Using FindWindow WinAPI | # Using FindWindow WinAPI | ||
# Using Atoms | |||
=== Using mutexes === | === Using mutexes === | ||
Line 11: | Line 12: | ||
In the SRC file within the panel object put this piece of code: | In the SRC file within the panel object put this piece of code: | ||
<source lang=" | <source lang="dataflex"> | ||
Procedure Exit_Application | Procedure Exit_Application | ||
integer iVoid | integer iVoid | ||
Line 21: | Line 22: | ||
And in a package that gets hit on startup: | And in a package that gets hit on startup: | ||
<source lang=" | <source lang="dataflex"> | ||
// Constants | // Constants | ||
Define ERROR_INVALID_HANDLE for 6 // taken from error.h of VS7 | Define ERROR_INVALID_HANDLE for 6 // taken from error.h of VS7 | ||
Line 42: | Line 43: | ||
Move "Unique String For My Application" To sID | Move "Unique String For My Application" To sID | ||
Move (CreateMuteX(0,1,AddressOf(sID))) To ghMuteX | Move (CreateMuteX(0,1,AddressOf(sID))) To ghMuteX | ||
If (ghMuteX <> | If (ghMuteX <> 0) Begin | ||
Move (GetLastError()) To iErr | Move (GetLastError()) To iErr | ||
If (iErr = ERROR_ALREADY_EXISTS) Begin // program is already | If (iErr = ERROR_ALREADY_EXISTS) Begin // program is already | ||
Line 60: | Line 61: | ||
Send Create_MuteX_Object | Send Create_MuteX_Object | ||
</source> | </source> | ||
Dave Robinson says - | |||
A warning: We found CodeJock skinning broke this, though YMMV. | |||
=== Using FindWindow WinAPI === | === Using FindWindow WinAPI === | ||
Line 66: | Line 70: | ||
Usage in SRC: | Usage in SRC: | ||
<source lang=" | <source lang="dataflex"> | ||
Use myPanel,pkg | Use myPanel,pkg | ||
Object Main is a myPanel | Object Main is a myPanel | ||
Line 72: | Line 76: | ||
Source myPanel.pkg | Source myPanel.pkg | ||
<source lang=" | <source lang="dataflex"> | ||
//////////////////////////////////////////// | //////////////////////////////////////////// | ||
// | // | ||
Line 112: | Line 116: | ||
The FindWindow technique is also discussed in the book [http://starzen.com/products/books-and-magazines/mastering-visual-dataflex/ Mastering Visual DataFlex] from Starzen. | The FindWindow technique is also discussed in the book [http://starzen.com/products/books-and-magazines/mastering-visual-dataflex/ Mastering Visual DataFlex] from Starzen. | ||
Dave Robinson says: | |||
The FindWindow method depends on the Title in the program taskbar being known and consistent. | |||
[[Category: Tutorials]] | [[Category: Tutorials]] |