Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to minimize window and set low priority through API?
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00527416
Message ID:
00528099
Views:
28
Hi Nick,
What is happening here is you are mixing threads and processes. Processes can have 1 or more thread associated with them while threads are singular entities. Look at the following code:
#define PROCESS_SET_INFORMATION		0x200
#define IDLE_PRIORITY_CLASS		0x40
declare integer OpenProcess in kernel32 integer lnaccess, integer lninherit, integer inprocID
declare integer GetLastError in win32api
declare integer SetPriorityClass in kernel32 integer, integer
declare integer CloseHandle in kernel32 integer
local lnhproc
lnhproc = OpenProcess(PROCESS_SET_INFORMATION,0,lnprocID)
if lnhproc = 0 ;
   or SetPriorityClass(lnhproc,IDLE_PRIORITY_CLASS) = 0 then
   ? GetLastError()
endif
CloseHandle(lnhproc)
For SetPriorityClass to work, you must pass in a process handle, not a thread handle. You need to use the OpenProcess function and because you are going to be setting information about the process, pass in the PROCESS_SET_INFORMATION flag.

As discussed before, the process ID is returned in one of the parameters you pass to GetWindowThreadProcessID and this is what needs to be passed to OpenProcess.


>I am also confused with using GetThreadPriority and BITOR stuff...

In order to use GetThreadPriority, you need to have read access to the thread. The THREAD_SET_INFORMATION flag only gives you write access to it. Using BITOR adds both flags together so you get read and write access to it.
lnhthread = OpenThread(BITOR(THREAD_SET_INFORMATION,THREAD_QUERY_INFORMATION),0,lnthreadID)  && give me write acces to set information and read access so I can verify my writes (if you don't believe the return value ;-)
HTH.

*snip*
Larry Miller
MCSD
LWMiller3@verizon.net

Accumulate learning by study, understand what you learn by questioning. -- Mingjiao
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform