Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about WIN32/Kernel32

Status
Not open for further replies.

RTTRAY

Programmer
Jan 12, 2003
3
HK
I want to use Power Builder to write function to check whether my computer is running "Microsoft Excel" or not.
I have tried the following code, but it doesn't work.
At local external function, I wrote:
FUNCTION long GetModuleHandleA(string modname) Library "Kernel32.dll"
Then I build a button to do the following:
ulong rtn
rtn = GetModuleHandleA("excel.exe")
MessageBox("Return Code: ", string(rtn))
The "rtn" always return 0, no matter the excel is on or off.
Any suggestion for me please? I am using Window NT for OS.

Rdgs
RTT
 
Try this

FUNCTION ULONG FindWindowA (REF STRING lpClassName, REF STRING lpWindowName) LIBRARY "user32.dll"

ulong rtn, i
string s,c

SetNull(s)
c = "XLMAIN"

rtn = FindWindowA(c, s)
messagebox("Handle", rtn)

 
Thank you, Srajgopal.
But I have tried it too, it doesn't work for me. Because the window name for excel always changes. (e.g. "Microsoft Excel - Book1" or could be "Microsoft Excel - XYZ" if a spreadsheet is opened.)
The FindWindowA function searches by exact match window name, so it cannot help me out.

Rdgs
RTTRAY
 
If you look at the function, the first parameter is the class name and the second is the window name. You should set the input class name to XLMAIN and leave the window name to NULL, because the window name always is different.

I tried in winnt and xp and it works for me. Please check again.
 
Thanks srajgopal! It works for me now.
 
How do we use the same feature to check for a generic EXE ? any executable.....

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top