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:
00528084
Views:
33
Hi Larry,

Continuing with this stuff. :)

Can I use SetPriorityClass to set the priority level so that it will be visible in the Task Manager as Low?

I tried

DECLARE SHORT SetPriorityClass in kernel32 INTEGER hThread, INTEGER nPriority
local lnPrClass
lnPrClass = SetPriorityClass(lnhthread, 2) && and that returns 0.
* according to WinAPI help the value 2 corresponds to Idle class, THREAD_PRIORITY_LOWEST, or I don't understand it correctly?

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

Thanks for your patience.

>Nick,
>It does show as Normal in the Task Manager but the actual thread priority setting is Lowest. You can verify this by also declaring GetThreadPriority (you will need to BITOR THREAD_QUERY_INFORMATION (0x40) with THREAD_SET_INFORMATION in order to use GetThreadPriority) and displying the return value.
>
>What is actually displayed in Task Manager is the processes's priority (not thread's) which is set using SetPriorityClass.
>
>>Hmm,
>>lnhthread = OpenThread(THREAD_SET_INFORMATION,0,lnThread_ID)
>>returns teh value now, but the priority still stays "Normal".
>>Digging... :)
>>
>>
>>>Hey Nick,
>>>The thread ID you need to pass to OpenThread is the actual return value from GetWindowThreadProcessID. The passed parameter gets teh Process ID. The Thread ID is the return value. So the following should work (this time I tested it < g >:
>>>
>>>local lnprocID, lnthreadID
>>>lnprocID = 1
>>>DECLARE INTEGER GetWindowThreadProcessId IN user32 INTEGER, INTEGER@
>>>lnthreadID = GetWindowThreadProcessId(THISFORM.nSHWND, @lnprocID)
>>>thisform.set_low_priority(lnthreadID)
>>>
>>>*** set_low_priority() form method
>>>LPARAMETER tnThread_id
>>>#DEFINE THREAD_BASE_PRIORITY_MIN -2
>>>#DEFINE THREAD_PRIORITY_LOWEST THREAD_BASE_PRIORITY_MIN
>>>#define THREAD_SET_INFORMATION  0x20
>>>declare integer OpenThread in kernel32 integer lnaccess, integer lninherit, integer inthreadID
>>>DECLARE SHORT SetThreadPriority in kernel32 INTEGER hThread, INTEGER nPriority
>>>declare integer CloseHandle in kernel32 integer
>>>
>>>local lnhthread
>>>lnhthread = OpenThread(THREAD_SET_INFORMATION,0,lnThread_ID)
>>>SetThreadPriority(lnhthread, THREAD_PRIORITY_LOWEST)
>>>CloseHandle(lnhthread)
>>>
>>>>>I haven't tested this so I'm not sure if it works. However the technique is the same is what I posted concerning killing a process a few of months ago.
>>>>>
>>>>>HTH.
>>>>>
>>>>>>Thanks Larry,
>>>>>>
>>>>>>Could you tell me if I got the syntax right? I have no errors, but it does not seem to set the priority.
>>>>>>
>>>>>>* THISFORM.nSHWND contains the window handle of FP DOS window
>>>>>>
>>>>>>local lnprocID
>>>>>>lnprocID = 1
>>>>>>DECLARE INTEGER GetWindowThreadProcessId IN user32 INTEGER, INTEGER@
>>>>>>GetWindowThreadProcessId(THISFORM.nSHWND, @lnprocID)
>>>>>>thisform.set_low_priority(lnprocID)
>>>>>>
>>>>>>*** set_low_priority() form method
>>>>>>LPARAMETER tnProcess_id
>>>>>>#DEFINE THREAD_BASE_PRIORITY_MIN -2
>>>>>>#DEFINE THREAD_PRIORITY_LOWEST THREAD_BASE_PRIORITY_MIN
>>>>>>DECLARE SHORT SetThreadPriority in kernel32 INTEGER hThread, INTEGER nPriority
>>>>>>SetThreadPriority(tnProcess_id, THREAD_PRIORITY_LOWEST)
>>>>>>
>>>>>>Note that I very rarely work with Win API calls... :)
>>>>>>
>>>>>>
>>>>>>
>>>>>>>API Text View has the constants you need.
>>>>>>>
>>>>>>>#DEFINE THREAD_BASE_PRIORITY_MIN -2
>>>>>>>#DEFINE THREAD_PRIORITY_LOWEST THREAD_BASE_PRIORITY_MIN
>>>>>>>
>>>>>>>For VC++ users, it is in the WINNT.H include file.
>>>>>>>
>>>>>>>>>>Hi All,
>>>>>>>>>>
>>>>>>>>>>I need to programmatically minimize the DOS application window and set its priority to low from VFP app. I assume I can do it with SendMessage() API function. Any body knows the constants I should use for that?(or better the exact syntax :)
>>>>>>>>>
>>>>>>>>>What is "the DOS application window"? Are you running a separate program from Visual FoxPro? If so, you can call a separate program, without opening a DOS prompt, just with RUN /n.
>>>>>>>>>
>>>>>>>>>Hilmar.
>>>>>>>>
>>>>>>>>Hi Hilmar,
>>>>>>>>
>>>>>>>>Yes, my VFP app runs FoxPro 2.5 DOS app with RUN /N1 ... command.
>>>>>>>>But then I need to minimize that FP DOS window and set its priority to low. (analog to DOS command
>>>>>>>>
>>>>>>>>START /MIN /LOW foxprox.exe myprog.fxp )
>>>>>>>>
>>>>>>>>I have the window handle and its Thread Process Id.
>>>>>>>>I found out that to set priority to low I can use SetThreadPriority() API function with THREAD_PRIORITY_LOWEST constant but I can't find that constant value and can't find the .H file to see how it is declared.
Nick Neklioudov
Universal Thread Consultant
3 times Microsoft MVP - Visual FoxPro

"I have not failed. I've just found 10,000 ways that don't work." - Thomas Edison
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform