|
|
Which version of comctl32? Updating it (by installing latest IE) might fix it...
I remember such problems to. Either there was a flaky comctl32 version out, or it happens only in some "strange" scenarios. Can you reproduce the problem in a simple dialog based application with only the list box on it?
Flirt harder, I'm a Coder
mlog || Agile Programming | doxygen
|
|
|
|
|
How do you find a programs Process ID?
|
|
|
|
|
How about GetCurrentProcessId() ?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
That depends on the kind of data you already have.
Is it the current process? Or do you have the name of the executable? Or a window handle?
Jens
|
|
|
|
|
Yeah the name is armyops.exe
|
|
|
|
|
|
If you have the name of the process, and that process is not you, you must either search for a window you know that process created, and get the process ID from that, or, if you only have the name of the process, you need to use the PSAPI/ToolHelper API to enumerate all running processes, look at each one's name, check if it matched, and if so, grab it's process ID.
See here
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/perfmon/base/about_psapi.asp
Bare in mind PSAPI only works with NT/2k/XP so if you want a cross platform soulition, use ToolTip - see the file Tlhelp32.h in the platform SDK for a statring point- but you want something like this which terminates a process given a name
<br />
BOOL CTestEnvKillerApp::InitInstance()<br />
{<br />
<br />
OSVERSIONINFO osvi;<br />
memset(&osvi, NULL, sizeof(OSVERSIONINFO));<br />
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);<br />
GetVersionEx(&osvi);<br />
<br />
if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
{<br />
HMODULE hLib = LoadLibrary( _T("psapi.dll") );<br />
if (NULL == hLib)<br />
{<br />
AfxMessageBox(_T("Could not load PSAPI.DLL.\nPlease check it's in your path"), MB_OK | MB_ICONEXCLAMATION);<br />
return FALSE;<br />
}<br />
lpfnEnumProcesses pFnEnumProc = (lpfnEnumProcesses)GetProcAddress( hLib, "EnumProcesses" );<br />
lpfnGetModuleBaseName pFnGetModBaseName = (lpfnGetModuleBaseName)GetProcAddress( hLib, "GetModuleBaseNameA" );<br />
lpfnEnumProcessModules pFnEnumProcMod = (lpfnEnumProcessModules)GetProcAddress( hLib, "EnumProcessModules" );<br />
<br />
if ( (NULL == pFnEnumProc) || (NULL == pFnGetModBaseName) || (NULL == pFnEnumProcMod) )<br />
{<br />
AfxMessageBox(_T("Could not find procedure in PSAPI.DLL"), MB_OK | MB_ICONEXCLAMATION);<br />
FreeLibrary(hLib);<br />
return FALSE;<br />
}<br />
<br />
DWORD dwNeeded = 0;<br />
DWORD dwProcessIDs[1024];<br />
memset(dwProcessIDs, NULL, sizeof(DWORD)*1024);<br />
<br />
if ( pFnEnumProc(dwProcessIDs, 1024, &dwNeeded) )<br />
{<br />
char szProcessName[MAX_PATH];<br />
<br />
short sNumProcs = (short)( dwNeeded/sizeof(DWORD) );<br />
for (short s = 0; s < sNumProcs; s++)<br />
{<br />
memset(szProcessName, NULL, sizeof(char)*MAX_PATH);<br />
<br />
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ | PROCESS_TERMINATE,<br />
FALSE, dwProcessIDs[s] );<br />
if (hProcess) <br />
{ <br />
HMODULE hMod = NULL;<br />
dwNeeded = 0;<br />
<br />
if ( pFnEnumProcMod( hProcess, &hMod, sizeof(hMod), &dwNeeded) ) <br />
{<br />
if (!pFnGetModBaseName( hProcess, hMod, szProcessName, sizeof(szProcessName) ) )<br />
{<br />
CloseHandle(hProcess);<br />
continue;<br />
}<br />
<br />
if ( ItsOurProcess() )<br />
{<br />
TerminateProcess(hProcess, 0);<br />
}<br />
}<br />
<br />
CloseHandle(hProcess);<br />
}<br />
}<br />
}<br />
<br />
FreeLibrary(hLib);<br />
}<br />
else if (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
{<br />
HMODULE hLib = LoadLibrary( _T("kernel32.dll") );<br />
if (NULL == hLib)<br />
{<br />
AfxMessageBox(_T("Could not load kernel32.DLL.\nPlease check it's in your path"), MB_OK | MB_ICONEXCLAMATION);<br />
return FALSE;<br />
}<br />
<br />
lpfnProcess32First pFnProc32First = (lpfnProcess32First)GetProcAddress( hLib, "Process32First" );<br />
lpfnProcess32Next pFnProc32Next = (lpfnProcess32Next)GetProcAddress( hLib, "Process32Next" );<br />
lpfnTH32Snap pFnTH32Snap = (lpfnTH32Snap)GetProcAddress( hLib, "CreateToolhelp32Snapshot" );<br />
<br />
if ( (NULL == pFnProc32First) || (NULL == pFnProc32Next) || (NULL == pFnTH32Snap) )<br />
{<br />
AfxMessageBox(_T("Could not find procedure in Kernel32.DLL"), MB_OK | MB_ICONEXCLAMATION);<br />
FreeLibrary(hLib);<br />
return FALSE;<br />
}<br />
<br />
PROCESSENTRY32 pe;<br />
memset(&pe, NULL, sizeof(PROCESSENTRY32));<br />
<br />
HANDLE hSnapshot = pFnTH32Snap(TH32CS_SNAPPROCESS, 0);<br />
<br />
if (!hSnapshot)<br />
{<br />
AfxMessageBox(_T("Could not retrieve process snapshot"), MB_OK | MB_ICONEXCLAMATION);<br />
}<br />
<br />
pe.dwSize = sizeof(PROCESSENTRY32);<br />
<br />
if ( pFnProc32First(hSnapshot, &pe) )<br />
{<br />
MODULEENTRY32 me32 = {0}; <br />
BOOL bGotModule = FALSE; <br />
do<br />
{<br />
if ( GetProcessModule(pe.th32ProcessID, pe.th32ModuleID, &me32, sizeof(MODULEENTRY32), hLib) )<br />
{<br />
char szProcessName[MAX_PATH];<br />
memset(szProcessName, NULL, sizeof(char)*MAX_PATH);<br />
<br />
char drive[8];<br />
char dir[MAX_PATH]; <br />
char ext[8];<br />
_splitpath(me32.szExePath, drive, dir, szProcessName, ext);<br />
strcat(szProcessName, ext);<br />
<br />
if ( ItsOurProcess())<br />
{<br />
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ | PROCESS_TERMINATE,<br />
FALSE, pe.th32ProcessID);<br />
if (hProcess)<br />
{<br />
<br />
TerminateProcess(hProcess, 0);<br />
<br />
CloseHandle(hProcess);<br />
}<br />
}<br />
}<br />
}<br />
while(pFnProc32Next(hSnapshot, &pe));<br />
}<br />
<br />
CloseHandle(hSnapshot);<br />
<br />
FreeLibrary(hLib);<br />
}<br />
else<br />
{<br />
AfxMessageBox(_T("Operating system does not support this application"), MB_OK | MB_ICONEXCLAMATION);<br />
}<br />
return FALSE;<br />
}
FYI ToolHelp works on both sets of platform so you could just use that
|
|
|
|
|
Hi!
I'm searching for code or just the name of the windows api function that can turn _only_ the screen (not the whole computer) into standby mode, in other words, turn it off, until the mouse gets moved or a key gets pressed.
I found out that there's a (user configurable) display idle timer, however, I haven't found a way to manipulate this timer programmatically.
There are actually quite a lot of functions in the windows api related to power managment, but seemingly not one to turn only the screen off...
Maybe someone can help me,
Martin Leonhartsberger
mleonhartsberger@a1.net
|
|
|
|
|
Create a power scheme where USER_POWER_POLICY.VideoTimeoutAc is set to 1 (second). Save the policy by calling WritePwrScheme() . Then call SetActivePwrScheme() to set the current power scheme to the one that you just created. This is just a high-level overview, but hopefully you get the gist enough to fill in the blanks.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Yeah thanks I successfully used your description to send my screen into darkness after one second.
But (there's always one ) theres the problem of waking up again. If I don't move the mouse around continously the screen blankens immediately again (no surprise, timer is still set to 1 second).
So I thought, well, why don't wait the second until standby mode kicks in, and then write the old timer back? I use Sleep() for this, but the problem is, after Sleep() returns, the system thinks that it should awaken itself again and the screen turns on.
So, I need a way to wait this second and write the old scheme back WITHOUT letting the system think it should wakeup.
|
|
|
|
|
You might need to use GetLastInputInfo() to know when the mouse/keyboard was last used.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
I'd like to introduce into my app a control like Dundas Chart (it's so pretty..., but so expensive too..., no cracks wanted and no burning either) but I don't want to use Microsoft's Chart Control...
OH !!, I'm a MFC programmer.
Please, if you know about a class like Dundas Chart make me know it...
Thankx !!
|
|
|
|
|
|
If a computer is suspended/hibernating, does that affect then length of time a process will sleep for?
If a process is told to Sleep () for 1 hour and after half an hour the computer is put into hibernate for 2 hours, when it starts back up again and Windows resumes, does the process still have half an hour to Sleep (), or is its Sleep () time up (having effectively slept for 2 1/2 hours already)?
|
|
|
|
|
i don't know for your effective question, but don't use sleep() function for so long waits...
i uses active waits, and so need full CPU time.
TOXCCT >>> GEII power
|
|
|
|
|
Yeah, it's not good - I got a program dropped on my desk and while I'm fixing it by re-writing it, I still have to try and make the old version work
|
|
|
|
|
I am not quite sure if Sleep really waits actively...
See MSDN:
<quote>The Sleep function suspends the execution of the current thread for at least the specified interval.
Jens
|
|
|
|
|
yes, what does it say with that ??! give us the entire paragraph please...
i already read the MSDN ; it is not advised
TOXCCT >>> GEII power
|
|
|
|
|
My comment didn't answer your original question.
I just wanted to state that I don't think that
calling "Sleep" will cause the thread to wait actively.
It would be rather dumb to implement a task scheduler which lets a thread that called Sleep wait actively, wouldn't it?
To clarify:
By "waiting actively" I mean a continous loop until a condition is reached, like this one:
<br />
while ( true )<br />
{<br />
if ( bConditionIsReached )<br />
{<br />
break;<br />
}<br />
}<br />
Jens
|
|
|
|
|
yes, i understood what your previous post said about this, and i know what is an active wait.
just paste here what MSDN say about sleep() (but give the entire text on it).
TOXCCT >>> GEII power
|
|
|
|
|
|
well, you didn't want to copy the text, i give you :
If you have a thread that uses Sleep with infinite delay, the system will deadlock.
How do you understand this ????
TOXCCT >>> GEII power
|
|
|
|
|
Well the context of this sentence deals with messages, and if you read a little bit more it reads
Message broadcasts are sent to all windows in the system. If you have a thread that uses Sleep with infinite delay, the system will deadlock
And this one makes sense. Think about a SendMessage call to all windows with no timeout and one of the threads sleeps endlessly. Then the calling process will also hang.
But I don't see this as an evidence that Sleep waits actively.
Jens
|
|
|
|
|
no messages are advised ! do you read entierely the particle or you only see some word ?!
MSDN says that if you have to create a nex thread, you mustn't use sleep() because of this problem.
TOXCCT >>> GEII power
|
|
|
|
|