|
Hi,
I have timers which are started by non-window classes. I need to access some information, from the class which started the timer. For window classes I get the handle of the window using the HWND parameter. How can I access the class information from a timer procedure for non-window classes?
Thanks
Arthi
|
|
|
|
|
You've raised a very interesting problem! Apparently, there's no suitable callback parameter one can use to store a pointer to the object responsible of handling a TimerProc -driven timer. A workaround, if a little contrived one, is to have a map from timers IDs to objects. The following sketches the approach (warning: I haven't even compiled it, look for typos)
class MyClass
{
private:
typedef std::map<UINT,MyClass *> MapFromIdToMyClass
static MapFromIdToMyClass idToMyClass;
protected:
UINT SetTimer(UINT uElapse)
{
UINT id=::SetTimer(NULL,0,uElapse,staticTimerProc);
if(id){
idToMyClass[id]=this;
}
return id;
}
BOOL KillTimer(UINT id)
{
MapFromIdToMyClass::iterator it=idToMyClass.find(id);
assert(it!=idToMyClass.end());
if(!::KillTimer(NULL,id)) return FALSE;
idToMyClass.erase(it);
return TRUE;
}
static VOID CALLBACK staticTimerProc(HWND,UINT,UINT id,DWORD dwTime)
{
MapFromIdToMyClass::iterator it=idToMyClass.find(id);
assert(it!=idToMyClass.end());
(it->second)->TimerProc(id,dwTime);
}
void TimerProc(UINT id,DWORD dwTime)
{
...
}
...
); The idea is to forward all timers to a static TimerProc which uses the map to redirect the call to the associated MyClass object. If you get this to work and find it fit for your needs, please be aware you'll need some kind of concurrency protection (like a CRITICAL_SECTION ) to prevent racing problems that can occur if the timer triggers before the id has been mapped to the associated object.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I ran into this problem just yesterday and what I have done is sent in my this pointer in the user DWORD and the static member function of my class references that pointer as the pointer to the object to process the data.
I wrapped the processing of the TimerProc that uses the "unsafe" pointer in a try block to catch any exceptions if for some reason the pointer was not an object that I am interested in.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
i will really appreciate if some one can tell me a fixed point rotation function for vc which could rotate an image at angles of
1-10 degrees..(rotation with point)
looking forward from all the gurus of code
|
|
|
|
|
you can use SetWorldTransformation on NT/2K/XP to rotate a DC.
otherwise, you'll have to rotate the image pixel-by-pixel. there is code on this site to do it with shearing and i've seen some on codeguru that will rotate a DIB via a reverse transformation.
of course, if you are looking for a high-quality solution, i know where you can get one...
-c
Cheap oil. It's worth it!
|
|
|
|
|
Why not use the .NET GDI+. Its easy to do with that. And u can do it in any lang... VC included
|
|
|
|
|
Sudip wrote:
Why not use the .NET GDI+.
currently, .Net requires that you ship a 20+MB runtime package. that alone is reason enough for me not to use it.
-c
Cheap oil. It's worth it!
|
|
|
|
|
Actually, GDI+ requires you to install a PSDK, and ship a single dll, which is available from Microsoft also.
Having said that, GDI+ is not a good solution for rotating bitmaps. It doesn't do it in a way that I would regard to be overly useful.
Christian
I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
|
|
|
|
|
GDI+ does NOT require .NET, merely an install of the platform SDK.
Christian
I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
|
|
|
|
|
i think this is the toughest ...
is there a way i can detect edges of an image .. in simple words i want to inhance,clarify and most importantly want to detect the edges of an image..
looking forward from all the gurus of code
|
|
|
|
|
yes. start with the top left corner pixel. scan across the top row of pixels: if one pixel doesn't "match" the top-left corner, that row is in the image, everything above it is border. do the same thing for the other three edges. "match" can be as strict or as loose as you're willing to allow.
or... see my above post for something that can already do this.
-c
Cheap oil. It's worth it!
|
|
|
|
|
I've written an article on edge detection filters right here on CP. You should search the site before asking questions - that is what the articles are for.
Christian
I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
|
|
|
|
|
i want to take an image directly from a scanner and then want to save it in msaccess database.The image should first be displayed on the screen before saving it in the db . Also The software should be able to save multiple images in the database
looking forward from all the gurus of code
|
|
|
|
|
to capture an image from a scanner, you'll have to learn about TWAIN. to display an image, you'll have to get that scanner image into a DIB or HBITMAP. and to put it into an access database, i think you'll have to use a "blob" field.
-c
Cheap oil. It's worth it!
|
|
|
|
|
How would I find out what kind of exception is thrown when catch(...) catches the exception?
Background:
I have a DCOM server method that is processing a file but after about 5 minutes or so the client app crashes. I wrapped a try/catch around the method call but can't get the exception out of it. Is there a client side timeout?
thanks
Like it or not, I'm right.
|
|
|
|
|
you don't. that's why many people consider the (...) a dangerous thing - since you don't know what happened, how can you reasonably react to it?
-c
Cheap oil. It's worth it!
|
|
|
|
|
I would use the _set_se_translator function. Look at the documentation in MSDN. If you want more information, just tell me and I'll work out something with you to get what you want.
Michel
It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
- TreeBeard
|
|
|
|
|
Would you like to use my article?
http://www.codeproject.com/cpp/seexception.asp
|
|
|
|
|
Good article
Michel
It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
- TreeBeard
|
|
|
|
|
|
Thanks, but it didn't work.
My whole setup is strange.
I'm using a COM DLL that connects to a DCOM server which sends a file to a web server through an ISAPI DLL.
I just can't seem to figure out where the error is occurring.
I may have to put your code in all of my apps for it to work.
Like it or not, I'm right.
|
|
|
|
|
Jason Henderson wrote:
Thanks, but it didn't work.
Ouch, that's strange. I though if you would add to your catch block catching CSeExcpetion, then you will catch all SE exceptions and you should be able to get address of it (them).
OK, another way, I guess you can debug your code. Start debug session. Change the handling of all exceptions from 'Stop, if not handled' to 'Stop always' just before your problem usually occurs. Then debugger will jump directly to place where it has happened.
|
|
|
|
|
Jason Henderson wrote:
Thanks, but it didn't work.
Did you execute _set_se_translator(SeTranslator) in your application startup code and catch the exception by using catch(CException * e) in the catch block before the catch(...) block?
John
|
|
|
|
|
Yep, did all that.
I'm not sure if my app is even causing the problem right now.
Like it or not, I'm right.
|
|
|
|
|
Hi,
I have an MDI Application, and in that I have created the worker thread. From the worked thread I want to access the "Document" class of the MDI Application. Whenever I try to do GetMainWnd() and from that try to get the document, using GetActiveDocument() I am gettting an error.
This is the few lines of code :
CMyApp *app = (CMyApp *)AfxGetApp();
CMDIFrameWnd *pMain = (CMDIFrameWnd *)app->GetMainWnd();
CMyDoc *pDoc = (CMyDoc *)pMain->GetActiveFrame()->GetActiveDocument();
Can someone tell me my error???
Thanks in Advance...
Arthi
|
|
|
|