win32lib 'destroy_self'
- Posted by wolfgang fritz <wolfritz at KING.IGS.NET> Apr 03, 2000
- 384 views
...someone recently asked for something like this ? This win32lib program destroys itself in 2 seconds if another copy is already running. -- start demo -- include win32lib.ew atom ptr, ptr2, ok, proghwnd constant -- new function ! zFindWindow = linkFunc(user32, "FindWindowA", {C_POINTER,C_INT},C_INT) -- the normal win32lib main szClassName ptr = allocate_string("Win32Lib AppWindow 1") -- the following is this win 'title' ptr2 = allocate_string("kick_self") -- is this already running ? proghwnd= c_func( zFindWindow, { ptr, ptr2 } ) constant Win = create( Window,"kick_self",0,Default,Default,250,200,0) procedure check_self() -- destroy second instance, if first exists if proghwnd != 0 then -- just to test, lets see this instance for 2 seconds...anyways setVisible(Win,1) sleep(2) closeWindow(Win) end if end procedure procedure goto_first_instance() if proghwnd !=0 then -- set focus to first instance ok = c_func( xSetForegroundWindow,{proghwnd}) end if free(ptr) free(ptr2) end procedure onOpen[Win] = routine_id("check_self") onDestroy[Win] = routine_id("goto_first_instance") WinMain( Win, Normal ) -- end demo --