|
I didn't read your reply until this morning, so I am just replying now.
Looking at your PROCESS macro, it seems like most of it could easily be changed to be a member template function of class MainWindow (although I am making some assumptions about what the various symbols are).
The assumptions that I am making are:
- CallbackWrapperSpecific is a templated class derived from CallbackWrapperGeneric.
- The args passes to PROCESS is a specific variable with the type matching the first argument passed to PROCESS.
- The PROCESS macro is being used inside a member of MainWindow. I assume this because the "this" pointer is being passed to the constructor of CallbackWrapperSpecific.
- The m_localWorkMap is a member of MainWindow which is used to hold thread ids which map to CoreWorkUnit * objects (part of your cleanup mechanism).
- The m_threadPool is a member of MainWindow which is used to create a thread to process the request, with its Process member returning the thread id.
Given these assumptions, the only problem line that I see in the entire macro is:
CoreWorkUnit* cWorkUnit = new CoreWorkUnit(Function_##function, cbwDest);
This line is constructing a Function_ name from a combination of a constant string and the name of the member routine in MainWindow. This appears to be the only line which can't directly be converted into using a member template function. If you could explain what this is for, perhaps I could suggest another way to do this.
The rest of the code looks straight forward and should be easy to change - the following is close to what would be used (if my assumptions were correct):
<br />
template <typename type><br />
void Process( void (MainWindow::*memberFn)(type&), type args )<br />
{<br />
CallbackWrapperSpecific< MainWindow, void (MainWindow::*)(type&), type >* cbwSpecific =<br />
new CallbackWrapperSpecific< MainWindow,void(MainWindow::*)(type&), type>( this, memberFn, args );<br />
<br />
CallbackWrapperGeneric<type>* cbwGeneric = cbwSpecific;<br />
CallbackWrapperDestroy* cbwDest = cbwSpecific;<br />
CoreWorkUnit* cWorkUnit = new CoreWorkUnit( cbwDest);<br />
m_localWorkMap.insert(map<int, CoreWorkUnit*>::value_type(m_threadPool->Process(cbwGeneric), cWorkUnit));<br />
}<br />
Note that I commented out the first argument to the CoreWorkUnit constructor as I didn't know what to put here.
The calling sequence is slightly different, as you pass the type as a template parameter, and the address of the MainWindow routine as the first argument - the call would look something like:
<br />
Process<int>( &MainWindow::DoSomething, 1 );<br />
|
|
|
|
|
I am surprised that you were able to deduce so much from just seeing this code snippet -- your assumptions are almost 100% on the spot. The m_localWorkMap actually holds work IDs and the call to Process from m_threadPool returns the work ID so I can insert it into m_localWorkMap. In my ThreadPool class (not shown), I have a work ID being mapped to a WorkUnit. In my local (caller) class, CoreWorkUnit maps work IDs to resources that I need to free (namely cbwDest, as you can see above, which is the basest class of CallbackWrapperGeneric and CallbackWrapperSpecific) and the function name. Say I pass in MyFunction as my "function name", when the CoreWorkUnit constructor executes, it will set an enum value for CoreWorkUnit (Function_MyFunction). This is used when I get my data later on (I have to know which work ID corresponds to which work function that I actually called). I can easily fill this in by just passing the enum value directly (but one of my goals is to make PROCESS simple and as parameterless as possible to use, so I'll take that into account.
The below seems to work...
template<class T>
inline void MainWindow::Process(void (MainWindow::*funcPtr)(T&), T args)
{
CallbackWrapperSpecific<MainWindow, void (MainWindow::*)(T&), T>* cbwSpecific =
new CallbackWrapperSpecific<MainWindow, void (MainWindow::*)(T&), T>(this, funcPtr, args);
CallbackWrapperGeneric<T>* cbwGeneric = cbwSpecific;
CallbackWrapperDestroy* cbwDest = cbwSpecific;
CoreWorkUnit* cWorkUnit = new CoreWorkUnit(Function_DoWork, cbwDest);
m_localWorkMap.insert(map<int, CoreWorkUnit*>::value_type(m_threadPool->Process(cbwGeneric), cWorkUnit));
}
...with the following prototype...
template <class T> void Process(void (MainWindow::*funcPtr)(T&), T args);
To be honest, I didn't think a class member template function was possible without the class being a template class, so now I have dispelled another myth.
-- modified at 10:10 Friday 15th June, 2007
|
|
|
|
|
That makes sense in some situations when you want a resource to be held as short as possible. Ie:
{
mutex lock(some_lock);
...
}
But as you said it is often better to have it as a separate function.
|
|
|
|
|
Cyrilix wrote: Do people ever do this:
Yes.
As others have stated, to ensure a resource is in scope only as long as it's needed like a device context. I've also used it to ensure my assertions on scoping within a function were clear and somewhat enforced if some delicate resource balancing act were being performed.
|
|
|
|
|
I'm trying to set my icon for a exe file in visual studio 2003. I think this should be a common thing to do, but google has given me no info for the keywords I've been trying. Can anyone point me in the right direction on how to do this?
|
|
|
|
|
figured it out.
For those who were also wondering. What you got to do is go into the resource folder on the solution tab. make an icon with the same name as your executable (or click on said icon if its already there, which it was for me)
Then the weirdness happens. Click on the icon; then You need to right click on the main page where the icon is and select some of the other resolutions, then change your icon to suite that.
Something this common shouldn't be impossible to figure out. fyi this was mfc.
|
|
|
|
|
Explorer looks at the icon resources in the EXE and uses the icon with the smallest ID.
|
|
|
|
|
Do you want to change icon of your program
|
|
|
|
|
Hi, I'm developing a Visual C++ App.
I need to save my app's screenshot and save it as an image (to analize it in future).
Can somebody help me to do this on a Button's click event?
Thanks a lot
|
|
|
|
|
CDRAIN wrote: I need to save my app's screenshot...
To where?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
You can save your app's screen as a bmp file. there are many samples in code project desribing this. Have a search. How ever i will explain the steps.
Get the device context of your window.
Create a memory dc and a bitmap.
bitblt the content of the screen to the memory dc
now get the pixel data and other informarion from this bimap object and write to a file.
|
|
|
|
|
Do you have any handle of this screenshot (hbitmap)?
|
|
|
|
|
I need to save the screenshot in a file .bmp or jpg (better) and the post it via email.
I don't have implement nothing code yet, have you sample code?
How I've just said I need to post it in email message (compiled with the TO: address), is there an API function (like the HTML "mailto:mymail@my.com" or some simple command) to open the user's email App with this message ready to me sent?
Thanks.
-- modified at 6:53 Friday 15th June, 2007
|
|
|
|
|
Yeah I had and I think its easy for you,you can send a message with attachment for send message with attachment you can use of IMAPI(I think you can find an example on the codeproject.
for make a file simplest code is like this (but you didnt tell me do you have a handle (hbitmap) or no)
CImage m_Image;
m_Image.Attach(hbitmap);
m_Image.Save(filename,file type but if you dont set this parameter I think it makes a bitmap);
m_Image.Detach();
this code is simplest code that you can make your file.
Does this information helpful and does your problem solve or no.
|
|
|
|
|
I don't have hbitmap I need to capture the screen, and than save the image with the code you post (thanks for this).
- I need to know how to capture the screen bitmap?
- Can you easilly post me code or an example of the IMAPI's use (or when I can I'll search an examle)..
Thaks of all.
|
|
|
|
|
You must wait till I find my code and then send for you.
|
|
|
|
|
HDC m_hdcMem,hdc;
HBITMAP m_Bitmap,m_OldBitmap,hMainBmp ;
you can simply change 800x600(640x480/1024x768,...)
int x=800;
int y=600;
hdc=GetDesktopWindow()->GetDC()->m_hDC;
m_hdcMem= CreateCompatibleDC(hdc);
m_Bitmap = CreateCompatibleBitmap(hdc,x,y);
m_OldBitmap=(HBITMAP) SelectObject(m_hdcMem, m_Bitmap);
BitBlt(m_hdcMem, 0,0,x,y, hdc,0,0,SRCCOPY);
hMainBmp =(HBITMAP) SelectObject(m_hdcMem, m_OldBitmap);
CImage m_Image;
m_Image.Attach(hMainBmp);
m_Image.Save("c:\\test.bmp");
m_Image.Detach();
DeleteDC(m_hdcMem);
DeleteObject(hMainBmp );
DeleteObject(m_OldBitmap);
for second part I could'nt find my program but I found a good article for you Another simple MAPI class[^]
|
|
|
|
|
Thanks al lot for the help, now I'm able to save and send screenshot vie email.
With the sample you send me I'm able to send email directly in "background", but how can I obtain an editable and pre-compiled mail on my email's Manager (Outlook Express) so that I can add text or modify something before send it?
Thanks.
|
|
|
|
|
I think you can find exmaples about outlook express but I'm not sure I saw on the Codeproject or other sites(I saw many years ago) on that article user able to fill fields on the outlook,but why you dont use of your program I dont know aout your program is that a project or homework but for example you can insert two options to your program on the first option user use of a file that this file made previous with program,on other choise you show a dialog to user and he can selects detaily for send (To,Bc,BCC,attachment) and for detaily of image(size of image(100x100,...),type of image(bmp,...) and advanced option on the BitBlt(0(or insert different x),0(or insert different y),x,y,..).
|
|
|
|
|
My programm is a project, an "analisy and reporter project", and I want to fit it with the MS Office's standards, so I must have a preview of the mail to send with the document attached (or empty if so).
However I accept your suggest and I can try to perform this (initially) but then I like to obtain what I search.
Thanks a lot for Help, it's very usefull.
Bye
|
|
|
|
|
Some time ago I saw a question on this forum bout preview of print well it seems to you do you wan to make your print preview or use of a activex (I personal dont want to tell you use of activex I like that you make your class and use of it its better for preview an article is on the www.codresource.net (Im not sure spell of this address is correct or no) except this site on the codeproject you can see a lot of articles that they show steps for write preview).Your answer doesnt have an answer "MS Office's standards" I think you want to write a package that conform with office well I think you are lucky I think if you search on the codeproject you can find your answer and more thing that I like to tell you always check variables and return value and generaly all things for example you get a screenshot but hbitmap is null so if you pass this variable to CImage you will get an exception or other example you run your program of CD so you cant save your file on the CD.
I hope this informations helpful for you.
|
|
|
|
|
Hi, I solve my problem with your help.
Thanks a lot.
Bye
|
|
|
|
|
I tried to told a good answer to you but maybe I was lucky that I saw your question!;)
|
|
|
|
|
In my application I have a button to start another application (a different program altogether). I use the old WinExec which works fine. The problem is that I don't want multiple instances of the other application. (For example the user clicks on the first application and again it gets control and then he clicks on the button again.)
What I would like to do is transfer control to that program if it is running and not start and new instance of it. (This would be the equivalent of clicking on its icon on the bar on the bottom of the screen.) Is there a way to do such a thing?
Thanks,
Ilan
|
|
|
|
|