|
Hey all,
I'm currently making an editor for my latest game project. In order to make the application draw the OpenGL viewport each "frame" I'm currently using the OnTimer() message and then invalidating the view but I'm VERY interested in other ways to achieve this!
Do you guys have any experience doing this?
Thanks in advance,
Soren
|
|
|
|
|
You can use Multimedia Timer (see timeSetEvent) which has high precision. If you update the screen with high frequency, you may draw directly from timer message handler, without invalidating. OnDraw in this case should not be used.
Another way is using of idle time, you can see such applications here: http://nehe.gamedev.net/
However, this method doesn't look professional in Windows environment.
|
|
|
|
|
better use a loop with Sleep calls at the end.
Don't try it, just do it!
|
|
|
|
|
Alexander M. wrote:
better use a loop with Sleep calls at the end.
..in an MFC app? How's that?
Alex Farber wrote:
You can use Multimedia Timer (see timeSetEvent) which has high precision
Do I really need higher precision? I mean, I just need to constantly update the view.
Anyways, you're suggesting that I shouldn't use the OnDraw() message to do the drawing but rather my own function?
Any other suggestions?
|
|
|
|
|
Use idle time processing. This is the technique you're looking for. If this is an MFC app, override OnIdle in the application class, and adapt the following handler code:
BOOL CAnApp::OnIdle(LONG lCount) <br />
{<br />
CWinApp::OnIdle(lCount);<br />
<br />
if (lCount >= 2)<br />
DoSomething();<br />
<br />
return(TRUE);<br />
}
Only do your processing when the lCount parameter is >= 2; the framework is doing it's thing when it's 0 and 1. If you return TRUE, the application will continue to call your OnIdle as long as the message queue is empty, and will re-commence calls to OnIdle after processing any messages that are received. Return FALSE and OnIdle will be called once (and only once) each time the message queue is emptied.
|
|
|
|
|
First off, thanks for the great answer!
LunaticFringe wrote:
if (lCount >= 2)
DoSomething();
Would you recommend invalidating the view in order to update my OGL window or should I use a separate function? I mean, after all, I DO need the device context of the view which is automatically passed as a parameter to OnDraw().
|
|
|
|
|
Yes. Invalidate, and perhaps call UpdateWindow to force the issue.
|
|
|
|
|
Hi,
Is it possible to write a function which will take a variable number of arguments????
What i'm passing in is an array of doubles, and at the moment my function looks like
void func(int num, double* arr)
with "num" been the number of elements in the array.
So, can I pass just the array, and work out the number of elements inside the function??
any ideas??
thanks,
henry
|
|
|
|
|
Lookup va_start, va_arg and va_end in MSDN
int average( int first, ... )
{
int count = 0, sum = 0, i = first;
va_list marker;
va_start( marker, first ); /* Initialize variable arguments. */
while( i != -1 )
{
sum += i;
count++;
i = va_arg( marker, int);
}
va_end( marker ); /* Reset variable arguments. */
return( sum ? (sum / count) : 0 );
}
Michael
But you know when the truth is told,
That you can get what you want or you can just get old,
Your're going to kick off before you even get halfway through.
When will you realise... Vienna waits for you? - "The Stranger," Billy Joel
|
|
|
|
|
hdaly wrote:
So, can I pass just the array, and work out the number of elements inside the function??
Not when using a plain array. Because you can't pass a whole array to a function, just a pointer to the first element, the way you have it now is the correct way. The alternative is to use an STL vector or other container that knows its size.
--Mike--
Ericahist | CP SearchBar v2.0.2 | Homepage | 1ClickPicGrabber New v2.0! | RightClick-Encrypt
Actual sign at the laundromat I go to: "No tinting or dying."
|
|
|
|
|
Hi,
I need an idea to lock a MFC-Application after a specific time when no
user action happens.
The problem is:
The application has some internal messages like WM_TIMER, and some listctls get messages to display new text.
When the time is up the application has to lock itself and it appears a
login dialog.
|
|
|
|
|
Idefix wrote:
The problem is:
The application has some internal messages like WM_TIMER
Is this a problem?
You can have many timers. Each of them has an identifier.
I think that this should work:
void CMainFrame::OnStartTimer()
{
m_nTimer1 = SetTimer(1, 2000, 0);
m_nTimer2 = SetTimer(2, 2000, 0);
}
void CMainFrame::OnTimer(UINT nIDEvent)
{
switch(nIDEvent)
{
case 1:
break;
case 2:
break;
}
CMDIFrameWnd::OnTimer(nIDEvent);
}
Let me know if it helped.
modified on Monday, November 29, 2010 6:12 AM
|
|
|
|
|
Yes of course, the app can have many timer but how can I recognise
when the user has made no actions for e.g. 5 min. ?
At first I thought to use the OnIdle function but the internal WM_TIMER message
annul the idle state.
Another Problem is that the app is a client programm and get a lot of IP packets form the server and displays the data in controls. This are not user actions!
|
|
|
|
|
You can use GetLastInputInfo on Win2k to give you the time of the last "input" event - and compare that to the current time and then lock the app if the time out has gone
If you wanna run on 9x I think your into hook land - look up WH_FOREGROUNDIDLE - you might find this http://www.microsoft.com/msj/0200/c/c0200.aspx and this http://msdn.microsoft.com/msdnmag/issues/0500/c/default.aspx useful which do what you want.
|
|
|
|
|
I'd simply poll keyboard and mouse inputs in the message queue.
~RaGE();
|
|
|
|
|
One way would be to get the screen saver timeout value at the start of your application. Then set this value to whatever idle time you are interested in. Once that idle time has been reached, Windows will broadcast a SC_SCREENSAVE message. When your application ends, restore the screen saver timeout value to what it was.
Another idea that comes to mind would be to call SetWindowsHookEx() . As far as which type of hook to use, I don't know. Several of them look like they might work, but ultimately it'd probably be only one of them.
Classier ways may exist, but having never done this, I'm not familiar with them.
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
Many thanks for your suggestions.
I realized the application lock to filter out
the messages WM_KEYDOWN, WM_SETCURSOR, WM_MOUSEMOVE ...
I use the WindowProc from CMainframe and PreTranslateMessage from the
Application to keep the user event in mind.
I set a timer to pull the last user event and divided the time of timer by 10.
When the timer the peeks the noted user event it puts them back. After 10 times without user events the applcations will be locked.
It goes well and is not so complicate.
I get another problem with messageboxes. When a messagebox appears there are no window messages In addition I have to handle a opened messagebox.
At the moment I'm thinking about this problem.
Thanks
|
|
|
|
|
I'm so stupid.
Why I haven't tried GetLastInputInfo at first? (don't answer me)
That works very simple and it is what I wanted.
Thanks
|
|
|
|
|
Hi,
I have at CListBox in a dialog box but I'm not able to capture mouse click (ex. LButtonUp() ) ?
Context-menu works fine on the mouse right click.
Can anybody help me ?
|
|
|
|
|
If the List box does not provide a way handle a message - WM_LBUTTONUP message in your case, you will have to use subclassing (write your own message procedure) for this control.
See the articles on subclassing here at CP, or at msdn.microsoft.com...
"Needless redundancy is the hobgoblin of software engineering." - Peter Darnell
|
|
|
|
|
Have MFC subclass it for you with a DDX_Control statment, if its based on a resource:
1. Derive a class from CListBox
2. Double click on the list box in the resource editor with CTRL held down
3. Select control
4. Select your new derived list box class
5. Give it a name
Then use class wizard to add a handler to your LB for WM_LBUTTONUP to your new LB
|
|
|
|
|
hi!
I have complete my app using mscomm32.ocx,then it runs ok on my machine (os:win2k) which installed vc studio 6.0.But it can't run on the other machine (os:win2k) without intalling vc studio 6.0.
especially I register this ocx in the other machine.
why?
thanks!
|
|
|
|
|
How can load bitmap into the dialog base......
|
|
|
|
|
Can any one tell me where can i get the latest SDK if i want to use this interface
IHTMLWindow4
Live as if your were to die tomorrow. Learn as if you were to live forever.
-Mahatma Gandhi
|
|
|
|
|
I guess this must be in the platform sdk in webdevelopment section.
I Touched Osama Bin Ladens Bushy Beard
|
|
|
|