|
I have read through www.flounder.com Asynchronous Process Notification/Worker Thread and Arjay thread articles but I can't figure out how to get the two work together
From Asynchronous Process Notification, I understand to use Afxbeginthread to create a thread to wait for the process to end and post a message.
From Worker Thread and Arjay thread articles, I understand that I can use SuspendThread() and ResumeThread().
void CProcessManagerDlg::OnBnRun()
{
ptrThread = AfxBeginThread(WaitThread, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
ptrThread->m_bAutoDelete = FALSE;
ptrThread->ResumeThread();
}
void CProcessManagerDlg::OnPause()
{
ptrThread->SuspendThread();
}
UINT WaitThread(void *pParam)
{
CProcessManagerDlg* pThis= (CProcessManagerDlg*)pParam;
HANDLE hProcess = Launch(_T("notepad"));
::WaitForSingleObject(hProcess, INFINITE);
pThis->PostMessage(UWM_DONE, 0, (LPARAM)hProcess);
}
Press Pause wouldn't do anything. I am guessing WaitForSingleObject is preventing the thread from receiving suspend or resume(which would explain why TerminateThread and PostMessage(WM_QUIT) do not work either). So how would I go about suspending a thread that needs to waitforsingleobject on external process?
|
|
|
|
|
Why do you need to suspend the thread if it's already waiting for the external process?
|
|
|
|
|
I want the ability to pause/resume the external process.
|
|
|
|
|
The thread that launches the process is not the thread inside that process. Each process has its own threads.
If you want to pause the external process, you'll need to use the information in this article:
http://msdn.microsoft.com/en-us/library/ms686701(VS.85).aspx[^]
Specifically, see Traversing the thread list .
|
|
|
|
|
Ah so I can't use the thread that spawn the process to pause it. This is going to be a lot more complicated
Thanks for the link I am looking into it. I don't suppose there is an article with demo on here or CodeGuru for me to fiddle with it.
|
|
|
|
|
There very well might be an article here.
The idea is that you enumerate all the processes until you find the one you just launched, then enumerate all the threads in the process and pause each one.
|
|
|
|
|
I forgot to mention that if you want to start the external process in a suspended state, you can call CreateProcess() with a special flag called CREATE_SUSPENDED, and the process will be loaded, but will not run until you resume each of its threads.
|
|
|
|
|
I have to look into that. With Pause and Resume I noticed how much I could have used PROCESS_INFORMATION. I could have skipped thread list traverse with SuspendThread(pi.dwThreadId),if I am not mistaken
|
|
|
|
|
Yes, you could have. But if the remote process spawns any new threads, you would still have to enumerate them to see what they are.
|
|
|
|
|
Thanks again. You have no idea how long I have been racking over my brain over this problem.
|
|
|
|
|
|
Did u used ShellExecute to create the process?
Величие не Бога может быть недооценена.
|
|
|
|
|
Sorry if I wasn't clear my Launch() = ShellExecuteEx
|
|
|
|
|
Can you show the code inside Launch()?
Well i prefer to use CreateProcess.
Величие не Бога может быть недооценена.
|
|
|
|
|
You know while I was investigating this I have thought about switching back to CreateProcess base on what I read. Before, I had gone back and forth between CreateProcess and ShellExecuteEx (at one point I had two launch functions). But ultimately I stuck with the one that allows me to use lpOperation, open associated program automatically and open url using default application. Also I was influence by An Introduction to Processes: Asynchronous Process Notification[^], where Microsoft recommend the use of ShellExecute.
Now if there is someway for CreateProcess to use lpOperation that would be nice. OR have ShellExecuteEx populate PROCESS_INFORMATION.
I always wonder why there isn't a function that encapsulate both strengths.
|
|
|
|
|
Every time I run this code it fails at AppendCategory to the JumpList.
Any pointers or what effects that could cause that.
Thanks in advance.
ICustomDestinationList* pJumpList = NULL;
if (SUCCEEDED(CoCreateInstance(CLSID_DestinationList, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pJumpList))))
{
MessageBox (NULL, (LPCSTR)"JumpList variable Created!", (LPCSTR)"JumpList", MB_OK);
if (SUCCEEDED(pJumpList->SetAppID(L"My App")))
{
MessageBox (NULL, (LPCSTR)"AppID Set!", (LPCSTR)"JumpList", MB_OK);
UINT uMaxSlots;
IObjectArray* pRemoved;
if (SUCCEEDED(pJumpList->BeginList(&uMaxSlots, IID_PPV_ARGS(&pRemoved))))
{
MessageBox (NULL, (LPCSTR)"Beginning to create JumpList!", (LPCSTR)"JumpList", MB_OK);
IObjectCollection* pContents = NULL;
if (SUCCEEDED(CoCreateInstance(CLSID_EnumerableObjectCollection, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pContents))))
{
MessageBox (NULL, (LPCSTR)"Created ObjectCollection!", (LPCSTR)"JumpList", MB_OK);
IShellItem* pItem = NULL;
if (SUCCEEDED(SHCreateItemInKnownFolder(FOLDERID_Downloads, KF_FLAG_DEFAULT, L"iTunes64Setup.exe", IID_PPV_ARGS(&pItem))))
{
MessageBox (NULL, (LPCSTR)"Identified Item to ShellItem!", (LPCSTR)"JumpList", MB_OK);
if (SUCCEEDED(pContents->AddObject(pItem)))
{
pItem->Release();
MessageBox (NULL, (LPCSTR)"Added ShellItem to ObjectCollection!", (LPCSTR)"JumpList", MB_OK);
IObjectArray* pContentsArr = NULL;
if (SUCCEEDED(pContents->QueryInterface(IID_PPV_ARGS(&pContentsArr))))
{
pContents->Release();
MessageBox (NULL, (LPCSTR)"Linking ObjectCollection to ObjectArray!", (LPCSTR)"JumpList", MB_OK);
if (SUCCEEDED(pJumpList->AppendCategory(L"Custom Category", pContentsArr)))
{
pContentsArr->Release();
MessageBox (NULL, (LPCSTR)"Appended ObjectArray to the JumpList!", (LPCSTR)"JumpList", MB_OK);
pJumpList->CommitList();
MessageBox (NULL, (LPCSTR)"JumpList Created!", (LPCSTR)"JumpList", MB_OK);
}
else
{
MessageBox (NULL, (LPCSTR)"Can't AppendCategory!", (LPCSTR)"JumpList", MB_OK);
}
}
}
}
}
}
}
}
|
|
|
|
|
Hi,
I'd like to use a transparent PNG image as the background of a top level window (WS_POPUP).
Using GDI+ I have the image displayed correctly, but the problem is the transparent area (eg what is under my window) is not refreshed when I move the window.
How can I get it refreshed?
case WM_ERASEBKGND:
{
Gdiplus::Graphics graphics((HDC)wParam);
graphics.DrawImage(myImage, 0, 0, myImage->GetWidth(), myImage->GetHeight());
break;
}
Thanks for your help !
|
|
|
|
|
I'm not completely sure what you are trying to achieve there but i think you should rather check this[^] out.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
I have already tried to use the WS_EX_LAYERED style and the UpdateLayeredWindow function to get the image displayed and it works fine. But the problem is I want to add child controls to my window and with this approach they are not rendered.
|
|
|
|
|
Well, if you use layered windows you have to draw (and possible also handle) controls yourself. As far as i know there's no safe, reliable way to do what you want to do (i mean the way you are trying to do it). An alternative can be using Window regions[^], you can use these with windows displaying normal controls BUT this does not give you a nice look, it just lets you clip the window to some shape, but you can't nicely antialias the window for example. Another way would be combining a layered window and a non-layered window. The layered part would contain the transparent parts and the non-layered part would contain the controls, you would need to keep the Z-Order and visibility state synchrnoized between the two types of windows. It is probably a pain in the ass to implement correctly but it can be done.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
Just to clarify things up, here is what the window looks like: http://img52.imageshack.us/img52/3956/81503777.jpg
And here is what happens when I move the window over the desktop: http://img186.imageshack.us/img186/7079/96798366.jpg
What do you think would be the best way to display this kind of window (transparent background image + controls)?
Thanks!
|
|
|
|
|
Have you tried calling OnNcPaint() while/after moving the window?
L u n a t i c F r i n g e
|
|
|
|
|
Not yet, I will give it a try.
I solved the problem by using two windows, one for the background (WS_EX_LAYERED) and one for the controls
|
|
|
|
|
It was just a thought I had after looking at the images. It looked as if it was the non-client area that wasn't getting updated properly. I've no idea if it'll work or not.
L u n a t i c F r i n g e
|
|
|
|
|
I guess it is too late now since your other post(s) tell me you did with the "1 layerer + 1 normal window" solution but yepp, i would have recommended that also. Your app looks nice, btw...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|