From: Steve Tuckner Date: 2003-12-06T01:53:05+09:00 Subject: Re: Win32API: FindWindow Oops....never mind :-( > -----Original Message----- > From: Steve Tuckner [mailto:STUCKNER@MULTITECH.COM] > Sent: Friday, December 05, 2003 9:29 AM > To: ruby-talk ML > Subject: Win32API: FindWindow > > > We are having trouble running a Win32 function to find if a > window class > is currently registered (so we can see if our app is already running). > We use the Win32 function FindWindow to check for the existence of the > window class. When we do it in Ruby with Win32API, it doesn't work but > if we write a simple C app it does work. Below are the code fragments. > Any ideas? > > Here's the C code that works for detecting the existence of > the client's > window handle given its window class and name: > > if ((hwnd = FindWindow("simplewin00041943040000::faxfinderclass", > "FaxFinder Fax Client Software")) != 0) > strcpy(szResult, "FaxFinder Application Found"); > else > strcpy(szResult, "FaxFinder Application Not Found"); > DrawText(hdc, szResult, strlen(szResult), &rt, DT_CENTER); > > Here's the Ruby code fragments to try and achieve the same thing > > $FindWindow = Win32API.new("user32","FindWindow",["p","p"], "L") > if (hwnd = $FindWindow.call("simplewin00041943040000::faxfinderclass", > "FaxFinder Fax Client Software")) != 0 then > mainDisplay.messageBox("FaxFinder Client Software already running > (look in system tray)", "ERROR") > return > end > > In the above case, some non-zero window handle is always received, > whether the app is running or not. > > Steve Tuckner > > >