|
Hi david can u guide me how to convert this function to Win32 API,
ie how can i handle this function as message
void CMainFrame::OnInitMenu(CMenu* pMenu)
{
#if _MFC_VER < 0x0800
#undef __FUNCTION__
#define __FUNCTION__ "OnInitMenu()"
#endif // _MFC_VER < 0x0800
AfxTrace(_T(__FUNCTION__) _T(": %#0x\n"), pMenu->GetSafeHmenu());
MENUITEMINFO minfo;
minfo.cbSize = sizeof(minfo);
for (UINT pos=0; pos<pMenu->GetMenuItemCount(); pos++)
{
minfo.fMask = MIIM_FTYPE | MIIM_ID;
pMenu->GetMenuItemInfo(pos, &minfo, TRUE);
HICON hIcon = GetIconForItem(minfo.wID);
if (hIcon && !(minfo.fType & MFT_OWNERDRAW))
{
AfxTrace(_T("replace for id=%#0x\n"), minfo.wID);
minfo.fMask = MIIM_FTYPE | MIIM_BITMAP;
minfo.hbmpItem = HBMMENU_CALLBACK;
minfo.fType = MFT_STRING;
::SetMenuItemInfo(pMenu->GetSafeHmenu(), pos, TRUE, &minfo);
}
else
AfxTrace(_T("keep for id=%#0x\n"), minfo.wID);
// ::DestroyIcon(hIcon); // we use LR_SHARED instead
}
}
We Have To Conert it into case WM_INITMENU:
|
|
|
|
|
See here. Googling for such will also turn up dozens of examples.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi all,
I have a thread in my application.
When the thread is running its eating up the CPU.
My thread code is like:
ThreadProcess(LPVOID)
{
while(TRUE)
{
if(flag==true)
{
ExecFunc();
}
}
}
If the flag is set then it will execute the function.This flag is set in other function.
So I want to keep this thread idle until the flag is set.
How can I do it.Please help me.
Regards,
Sunil Kumar
|
|
|
|
|
|
Don't use a boolean but use an event instead (and use the WaitForSingleObject[^] function). There's also a good tutorial about threads here[^]
|
|
|
|
|
If you expect the wait time to be relatively long, then use one of those WaitFor... functions. If the wait time would be very low, then a spin loop is an ideal candidate.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Hi All
i have got article of write data in excel from code project.But it's give one exception error.Error is
An unhandled exception of type 'System.NullReferenceException' occurred in WEDLL.dll
Article link http://69.10.233.10/KB/mcpp/automate_Excel_in_C__.aspx[^]
How to solve that problem.
Plz help me.
|
|
|
|
|
|
Hi all,
I want to get process ID for my dialog based application, when i close my process..
How can i get it...
Thanks in advance
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
|
Hi friends,
I have a tree control in MFC, if I use the check box option, then even the root item
gets the check box.
I want to have a tree control with check boxes in the child but not at the root.
thanks
Raanojay
|
|
|
|
|
i will send you the source codes. MSN: zhu_lin4103@126.com
it's my pleasure to make friend with you.
|
|
|
|
|
Thanks a lot, friend
where do I find the source codes ?
|
|
|
|
|
tell me your msn or your email, i will send to you
it's my pleasure to make friend with you.
|
|
|
|
|
Hi
i have two columns in the CListCtrl. i want to display the immage only for the subitems and not for the first column. The CListCtrl has set the extended style property of LVS_EX_SUBITEMIMAGES.
when i am trying to load the icons for the subitems it also displayes the first column. how to avoid displaying the icon in the first column?. is there any restrictions or precondition required?
Thanks in Advance
Gokul
|
|
|
|
|
|
Hi
I'm new to multi-threading.
I have 2 classes CClass1 and CClass2.
CClass2 creates a new thread. CClass1 needs to trigger a function in this new thread. So I'm thinking of doing
void CClass1::MyCode1()<br />
{<br />
PostThreadMessage(Class2ThreadID, MY_MESSAGE, wParam, lParam);<br />
}
and catch this in CClass2 using
BEGIN_MSG_MAP(CClass2)<br />
MESSAGE_HANDLER(MY_MESSAGE, MyCode2)<br />
END_MSG_MAP()
But how do I make sure MyCode2 runs in this thread that I will create in CClass2 as it gets instantiated?
void CClass2::InitThread()<br />
{<br />
HANDLE myThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) MyCode2, NULL, 0, &Class2ThreadID);<br />
}
Also, I don't want MyCode2 to run until the message is received, but with this, it looks like CreateThread is going to want to run MyCode2 as soon as it creates the thread.
I'm confused.
Please help!
|
|
|
|
|
PaulowniaK wrote: But how do I make sure MyCode2 runs in this thread that I will create in CClass2 as it gets instantiated?
Do you mean you want to ensure that the thread has started ?
If so, you could use GetExitCodeThread[^] on the handle to check if the exit code is STILL_ACTIVE .
Or you could have the CClass2 constructor wait on a manual reset event after creating the thread.
The thread can set the event when it starts running.
PaulowniaK wrote: Also, I don't want MyCode2 to run until the message is received
You don't want to run the thread until the message is received, but the message can be sent only when the thread is running. Is there a chicken and egg problem here?
Well, you could again use events here.
Create an event using CreateEvent[^] and pass the event handle to the thread.
The thread will wait for the event to be signaled as soon as it is started.
The rest of the stuff in the thread will execute only after the event has been signaled from your main class.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
<quote>Do you mean you want to ensure that the thread has started ?
Not quite. I was wondering how to "attach" MyCode2 to the new thread. If I just wrote a code for MyCode2 and just called it, it would run in the default thread and the not the one I created anew, right?
I've done:
<br />
void CClass2::InitThread()<br />
{<br />
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) MyRoutine, NULL, 0, &hThread); <br />
}<br />
<br />
void CClass2::MyRoutine()<br />
{<br />
MSG msg;<br />
for(;;)<br />
{<br />
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))<br />
{<br />
DoWork();<br />
}<br />
}<br />
}<br />
While CClass1 does PostThreadMessage.
It seems to work, but it is a scary thought that MyRoutine is running continuously looking for messages...
Maybe I need to read up about Events... hmmm...
Thanks for the help.
|
|
|
|
|
PaulowniaK wrote: Not quite. I was wondering how to "attach" MyCode2 to the new thread. If I just wrote a code for MyCode2 and just called it, it would run in the default thread and the not the one I created anew, right?
I've done:
void CClass2::InitThread()
{
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) MyRoutine, NULL, 0, &hThread);
}
In the above code snippet MyRoutine will be started in a new thread. That is what CreateThread does for you.
PaulowniaK wrote: It seems to work, but it is a scary thought that MyRoutine is running continuously looking for messages...
Use GetMessage instead of PeekMessage so that it does not loop continuously.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Thanks for the advice. I needed to loop using PeekMessage so that messages were received at any time for the duration of the thread (entire lifetime of the application).
I've had to add additional functionalities which meant I really had to think seriously about using events instead. I want to use CEvent but to do that I need afxmt.h.
If I include afxmt.h in my stdafx.h after atlbase.h I get an error about MFC applications not being allowed to have windows.h.
If I put the afxmt.h before atlbase.h I get a linker error about _DLLMain@12 already being defined. It looks like the problem is in atlbase.h so I have a chicken and egg situation.
I've looked at changing the order of linking libraries, but with not much success as the error says _DLLMain is defined already in MyObject.obj (i.e. obj file created from my application I am writing at the moment).
Please help!
|
|
|
|
|
Hello folks!
I am trying to build a filter graph which includes a sample grabber filter. I add the sample grabber filter (and configure it to take video input) and the null renderer filter to the graph, then i add a source filter using IGraphBuilder::AddSourceFilter[^] for a certain video file. After this i query the source filter for its output pin and the sample grabber for its input pin and once i got these, i tell the grapbh builder to connect them. At this point my program quits. There is no error code returned, no exception thrown, nothing usefull in the debug output window, no nothing, the process simply stops without a word (at least nothing i can see). I checked around the net and looked at a few examples and basicly this aproach seems to be ok, others build the sample-grabber graphs the same way. Then i tried to recreate these steps using GraphEdit, i added the source filter for the same file, i added the sample grabber filter and tried to connect the two and the result was the very same (as much as one can tell by looking at it), GraphEdit quits without saying anything. Since graphedit behaves exactly like this too i guess the error doesn't seem to be in my code but then where? Does anyone have any idea what might cause this or where i should check to see the problem? Am using VS2003 and VC++.
Thanks for any help in advance...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
what's the format of your video file. does the programme quite whatever source files connect?
it's my pleasure to make friend with you.
|
|
|
|
|
It is a DivX avi, after i read your reply i also tried with an mpg file (in graphedit), with mpg graphedit crashed, i tried with another DivX avi, with that it could connect the pins (also in graph edit), i have yet to try this with my own program to see how that behaves, however i don't see the pattern yet.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
I had written a case which rendered a wmv file and grab picture in the grabber filter years ago. It work well. If you need the source codes, please contact to me. I will send you.
my MSN: zhu_lin4103@126.com
it's my pleasure to make friend with you.
|
|
|
|