|
SetTimer() is used, with or without MFC.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
If your 'regular C++ class' represents a Window then you can use ::SetTimer and handle the message. If it doesn't then you could look at ::CreateTimerQueueTimer , which requires W2000 or later but which will regularly call a function for you.
class HasATimerCallback
{
private :
HANDLE hTimer_ ;
static void CALLBACK TimerFunc ( void * param, BOOLEAN bTimer )
{
if ( param )
{
reinterpret_cast < HasATimerCallback*>( param )->DoTimerFunc () ;
}
}
void DoTimerFunc ()
{
}
public :
HasATimerCallback ()
{
::CreateTimerQueueTimer ( &hTimer_,
0,
TimerFunc,
this,
60000,
60000,
WT_EXECUTEINTIMERTHREAD
} ;
}
~HasATimerCallback ()
{
::DeleteTimerQueueTimer ( 0, hTimer_, INVALID_HANDLE_VALUE ) ;
}
} ;
I haven't compiled this, just cut'n'paste from some code I had lying around.
Paul
|
|
|
|
|
Got the idea, but....
When I try to copile it I get:
error C2039: 'CreateTimerQueueTimer' : is not a member of '`global namespace''
Any idea why ?
shay
|
|
|
|
|
The documentation for CreateTimerQueueTimer here[^] suggests that you have to define _WIN32_WINNT=0x0500 or greater. I usually do this in the project settings, where it may already be set to a lower level. The thread pool functions are only available on W2000 and later, which is slightly constraining but makes for a very quick example.
The documentation also says that the function will be called every 'interval' whether or not the previous call has returned. IOW your timer call back must be 're-entrant'. The Thread Pool functions make life easier but they don't save you from synchronisation issues.
Paul
|
|
|
|
|
I have a problem concerning the preprocessor.
How is it possible to use a #if within a macro?
I give u an example:
#define MACRO( x, y ) \
x *= y; \
#if y == 3 \
x /= 2; \
#endif
void main()
{
int iTemp = 10;
MACRO( iTemp , 1 );
MACRO( iTemp , 2 );
MACRO( iTemp , 3 );
MACRO( iTemp , 4 );
}
Is there a way to do that?
Thx
Don't try it, just do it!
|
|
|
|
|
well, is there a problem with that code ?
it seems to be right, even if i really dislike that way of coding (i prefer inline functions to macros...)
TOXCCT >>> GEII power
|
|
|
|
|
i can't use inline functions here because the code in the macro is not c code... it is SSE assembler code
Don't try it, just do it!
|
|
|
|
|
Why not use this instead?
#define MACRO(x,y) { x *= y; if (y == 3) x /= 2; }
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
here, the "if" test will be performed every time the macro is called, where in the other case, it will be defined only if the y is set to 3.
(you're probably right, in your code, david, but i continue thinking that i prefer inline functions than macros).
TOXCCT >>> GEII power
|
|
|
|
|
The compiler will see if ( 3 == 3 ) or if ( 2 == 3 ) etc and shouldn't actually generate any code for the 'if' statement. Possibly worth trying and checking the generated code to see.
Paul
|
|
|
|
|
thx guys, i will check this.
Don't try it, just do it!
|
|
|
|
|
Paul Ranson wrote:
and shouldn't actually generate any code for the 'if' statement
There is generated code. It looks like:
int iTemp = 10;
{ iTemp *= 1; if (1 == 3) iTemp /= 2; };
{ iTemp *= 2; if (2 == 3) iTemp /= 2; };
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
I meant that the compiler wouldn't generate any code for tests that only have one outcome.
This code,
#define MACRO(x,y) { x *= y; if (y == 3) x /= 2; }
int main()
{
int iTemp = 10;
MACRO( iTemp , 1 );
MACRO( iTemp , 2 );
MACRO( iTemp , 3 );
MACRO( iTemp , 4 );
std::cout << "Ends up with " << iTemp << std::endl ;
return 0;
}
in an optimised build turns into
push 120
call ostream etc
IOW the compiler has taken all the fun out of it.
This function
int UseMacro ( int i )
{
MACRO( i , 1 );
MACRO( i , 2 );
MACRO( i , 3 );
MACRO( i , 4 );
return i ;
}
compiles to
?UseMacro@@YAHH@Z PROC NEAR ; UseMacro, COMDAT
; 10 : MACRO( i , 1 );
; 11 : MACRO( i , 2 );
; 12 : MACRO( i , 3 );
mov eax, DWORD PTR _i$[esp-4]
lea eax, DWORD PTR [eax+eax*2]
shl eax, 1
cdq
sub eax, edx
sar eax, 1
; 13 : MACRO( i , 4 );
shl eax, 2
; 14 :
; 15 : return i ;
; 16 : }
ret 0
?UseMacro@@YAHH@Z ENDP ; UseMacro
So I don't think we have to worry about optimising the Macro.
Interesting stuff to look at though, this is VC++ 7.1 and it seems pretty clever to me.
Paul
|
|
|
|
|
toxcct wrote:
where in the other case...
Which is the case that does not work.
toxcct wrote:
(you're probably right, in your code, david, but i continue thinking that i prefer inline functions than macros).
I was not comparing one against the other in terms of speed, efficiency, maintenance, etc. I was just correcting what he was attempting.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Hi all,
I hope that somebody can help me. I have written a program which slices a 3D part into a set of 2D slices. The amount of data generated by that function can be very large (i.e. greater that 300 MB).
To save main memory I want to save these data into a file. I want to do that in a way to have a fast access to single layers. My current implementation is working like follows:
I have a list of 'int' values for every layer:
n,i1,i2,...,in
'n' is equal to the number of vertices for every layer
i1,...,in are indeces refering to co-ordinates of a corresponding points et.
By attaching all lists together I get a 'int' based representation of the layered representation of the 3D part:
n,i11,...,i1n,m,i21,...,i2m,o,i31,...,i3o,...
I save these data into a file.
To get the data for a single layer I can use the 'n','m' as offset to set the file handle to the right position. That means if I want the data of the third layer I start from the beginning and add the offset 'n'+'m'+2. The file handle is now positioned at 'o'. I use 'o' to read all data of the third layer.
This is working very well and is quite fast. But unforetunatly sometimes the software crashes. It seems that for some reasons wrong data are saved. The offsets 'n','m',... are not corresponding to the file size/lenght of 'int' list.
I have tried out to find the reason for that. This will only happen, if I save the 'int'list to a file. If I hold all data in the main memory there is no problem.
Has somebody an idea, why this is happen? Or a better idea to save main memory with a fast access to the layer data?
Ciao,
f.o.b
|
|
|
|
|
Hi,
Sorry, I don't know what can be the problem, but I have a suggestion to a different approach to your problem. You could use a compound file storage, this is the same as Word, Excel and many other do.
The idea behind structured storage (check MSDN) is to replicate the structure of a file system, folders and files, inside of a file, folder are call storages and files streams. So you create a tree structure of storages and save your data on a stream on the appropriated storage.
Getting the data back is fairly easy, find the storage you are looking for, open it, open the stream, get the data.
The nice thing about this, is you can have meaningful names for your data and the path where is located.
To see what I'm talking about, look for the "DocFile Viewer" application on the "Microsoft Visual Studio 6.0 Tools" and open a Word or Excel file.
If after reading a little you still need more help, let me know and I can give you another push.
Fabian
|
|
|
|
|
I need to charge an image from a PATH...Anybody can help me?
|
|
|
|
|
Hugo Bertorello wrote:
...charge an image from a PATH
What exactly does this mean?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Use LoadImage with the LR_LOADFROMFILE flag
HBITMAP bmp = (HBITMAP)LoadImage(NULL, _T("C:\\MyBitmap.bmp"), IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE);
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
Hi!
I need to be able to control the life time of a window that was created in a different process. For that purpose I set a CBT-hook to check for the HCBT_DESTROYWND notification. The problem is that I only get notifications for destroyed windows that were created by threads in my own process.
The hook callback function is, as the docs request, in a separate dll.
I use this function call to set the hook:
::SetWindowsHookEx(WH_CBT, _CBTProc, hInstance, NULL);
Here, hInstance is the handle to the loaded separate dll and _CBTProc is the pointer to my callback inside that dll.
As I said: it works, I get notifications, but ONLY for windows owned by threads in my process. That's not what I consider a "system wide" hook!
As a workaround I also tried to get the ID of thread owning the window I want to be informed about via GetWindowThreadProcessID() and used that ID instead of the NULL parameter when setting the hook - to no avail...
In this same separate dll I use a system wide mouse hook. This mouse hook _does_ work however.
So my question is: did I miss something important concerning CBT hooks? How can I get a really system wide CBT hook installed?
Thanks in advance
Nick
|
|
|
|
|
Hello,
I want to scroll the content (among other things) and I would like to use CScrollView class that already handles all the bulk of the code.
The question is: Can a View as CFormView used without an atached Doc and a Frame?, that's it appart of Doc/View architecture.
Thanks in advanced.
|
|
|
|
|
I believe it can't, but that doesn't mean you're stuck: simply create an "empty" document class. To add the view to that document, you can either do it manually, or even better: create a document template.
You can create the document using the class-wizard, which is a snap. The template you simply instanciate with the run-time classes of the document and the view.
-- Nitzan
|
|
|
|
|
I've made my application in Visual C++ 6.0 using the MFC.
One of users is reporting that application is crashing with the "Runtime Error! Program: C:\.....\..exe abnormal program termination", I can't reproduce this bug on my computer.
When the runtime shows this message box ? There is no address of crashing code,
so I can't find the problem
What to do ?
Thanks
rrrado
|
|
|
|
|
Nothing definitive, but:
Does it crash often, or was it a one-time thing?
Does it crash in the same place (e.g., opening of a certain file, rendering of a particular graphic) everytime?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
It crashes every time and always at the same place.
But if I try to make the same steps which leads to crash on
my computer, everything is working correctly.
I can't visit the user with the debugger
rrrado
|
|
|
|
|