|
I am interesting in using Mr. Naughter CCPUTicker, but I want to use it as accurately as possible.
Is there a way to place a "lock," something like a semaphore, around a set of C++ instructions, and stop all other messages from being serviced during this time?
In other words, can I change
foo(a);
bar(b);
to
BEGIN(lock)
foo(a);
bar(b);
END(lock)
and know that foo and bar were executed sequentially? For CCPUTimer, this would allow me to time between to calls as accurately as possible.
Thanks,
Ryan
|
|
|
|
|
Remember that 32-bit Windows systems use preemptive multitasking. You can't ensure that your process is utilizing all CPU resources all the time.
You can of course ensure that other thread from your process is not called during foo and bar. Is your application multithreaded?
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
No, I am not using a multithreaded application.
Would CWinThread::SetThreadPriority(THREAD_PRIORITY_TIME_CRITICAL) be the closest I could get to locking out the other processes? I realize windows is not a RTOS, but thought it might be possible to force a process to "utilize all CPU resources" for a short time.
-Ryan
|
|
|
|
|
Yeah, SetThreadPriority and SetPriorityClass will make your process real resource hog
If your app is singlethreaded, don't worry about message pump - it's running in the same thread. Just don't call PeekMessage/GetMessage manually inside foo and bar.
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
Hmmm... I'm looking at Richter's Advanced Windows, chapter 4, and it looks like if you were to get really piggy you could SetPriorityClass for the process to REALTIME_PRIORITY_CLASS and SetThreadPriority to THREAD_PRIORITY_TIME_CRITICAL to give it a level of 31.
31 is the maximum. 31 is extreme. 31 will never yield. 31 can alter the fabric of the space time continuum as we know it.
Well, thats the impression I get anyway.
On NT you'll need the Increase Scheduling Priority privilege.
|
|
|
|
|
I have been programming C++ for about a year, and have learnt quite a lot. However, moving to Visual C++ has really created problems for me. I understand most things, I can deal with messages properly, interact with UI elements etc, but it still seems a long way off that I would be able to put together a complex application or game. How did you guys learn, and what is the best way for me to go from here?
|
|
|
|
|
designing software to implement is the vision thing ... it takes a bit longer to do architecture but keep plugging away and you'll get there
---
"every year we invent better idiot proof systems and every year they invent better idiots"
|
|
|
|
|
I need to draw transparent rectangle (will have only BOUNDING LINES VISIBLE) above existing drawing. Rectangle will be drawn in real time by the user. No part of drawing underneath must be destroyed. Is there any smart way of how to save & restore overlaid parts of the existing drawing?
I am relatively new to GDI.
Thanks in advance.
|
|
|
|
|
Hold the two images in different bitmaps and merge them in OnPrepareDC or OnPaint direct to the screen.
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
Thanks, I'll keep it in my mind. Any other ideas?
|
|
|
|
|
Use DrawFocusRect. Or set the ROP2 mode to R2_NOTXORPEN, brush to NULL_BRUSH and draw whatever you want. To remove drawn rectangle, repeat the steps - since you're XORing the pixels, second pass will restore them to initial values.
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
If I draw black (black pen, black brush) rectangle with R2_NOTXORPEN, will it appear all black? Where are stored pixels of original drawing in this case? Where is stored this information? I must restore them from somewhere.
|
|
|
|
|
Geez, man - do you know how XOR works?
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
|
> 1 xor 1 makes 0
And what about 1 xor 0, 0 xor 1 and 0 xor 0? If you draw rectangle *twice* in XOR mode, it will disappear and your original picture will remain intact. XOR 'toggles' bits - zeros become ones and vice versa. Two XORs give you original bits. Of course, you have to ensure that rectangle coordinates do not change. Is that clear enough?
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
Ok, I tried DrawFocusRect which is XOR function.
CRect rc (0, 200, 200, 0);
pDC -> DrawFocusRect (&rc);
in my OnPaint (). I see no rectangle on the screen.
I doubt now. I believe DrawFocusRect draws in logical coord. space.
Mapping mode, window origin and extent are set accordingly. Everything seems to be all right. Did I something wrong?
|
|
|
|
|
From the DrawFocusRect documentation:
"DrawFocusRect works only in MM_TEXT mode."
If you need some other mapping mode, the only way is to call SetROP2 and draw rectangle manually. You can use MoveTo/LineTo or set a brush to GetStockObject(NULL_BRUSH) and call Rectangle. I'm assuming you need only outline of the rectangle - as specified in original post.
You can check KB article Q135865 to get sample on "How to use Win32 API to Draw a Dragging Rectangle on Screen DC". Your task is probably easier - you'll be drawing inside your own window only. You can also search for "sample setrop2" in your VC++ help - this search gives more than 20 hits on my workstation.
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
You are right, I'm using MM_ANISOTROPIC mapping mode.
Now I'm trying:
CRect rc (10, 200, 200, 40);
pDC -> SetROP2 (R2_NOTXORPEN);
pDC -> Rectangle (&rc);
It looks fine. This is what I wanted. THANKS!
|
|
|
|
|
I'd code it differently. Assuming that you want to decrease dialog height to hide the button, it would look like this:
CRect rcDialogClient, rcDialogWindow;
GetWindowRect(rcDialogWindow);
GetClientRect(rcDialogClient);
CRect rcBtnWindow;
m_btn.GetWindowRect(rcBtnWindow);
ScreenToClient(rcBtnWindow);
int cyDelta = rcDialogClient.Height() - rcBtnWindow.top;
SetWindowPos(NULL, 0, 0,
rcDialogWindow.Width(),
rcDialogWindow.Height() - cyDelta,
SWP_NOMOVE | SWP_NOZORDER);
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
Thanks for the reply Tomasz, but I actuall thought of something similar after I had just posted it... and deleted the post, thought no one would have seen it yet.
cheers,
-Ben
"Its funny when you stop doing things not because they’re wrong, but because you might get caught." - Unknown
|
|
|
|
|
Hi there ,
I GOT A SIMPLE PROBLEM.I AM COMPILING A VC++ ( 5.0 ) PROGRAM WHERE I AM HAVING A DIALOG BOX APPLICATION.IN THE DIALOG BOX I AM HAVING A EDIT BOX WHER5E I WISH TO DISPLAY THE VALUE OF THE ITERATION COUNT IN THIS EDIT BOX . SIMPLE !!!
THE CODE I HAVE WRITTEN ON MOUSE CLICK OF A PUSH BUTTON IS AS FOLLOWS.
:: OnPress()
{
for ( int i=0;i<10;i++)
{
m_number=i;
UpdateData (FALSE );
Sleep( 1000 );
}
}
m_number is variable associated with the edit box and is integer type.When i run the program only last count i.e 9 is displayed in the edit box.why not all count is displayed in the edit box?
Can somebody please guide me?Why this is happening.
Thanks in advance.
Lets share our knowledge and make this world even more beautiful.
|
|
|
|
|
I believe it has to do with your calls to the Sleep() function. The sleep function was not realy meant to be used in this maner. What the sleep function does is suspend the execution of your current thread. So your edit box wont even have time to update itself before the sleep starts... or even after. I imagine the only thing displayed in you edit box, after 9 seconds, is 9.
I'd recomend looking at using a timer, and update the edit box with that.
-Ben
"Its funny when you stop doing things not because they’re wrong, but because you might get caught." - Unknown
|
|
|
|
|
Think : "Message pump". I do not believe that UpdateData forces messages to be processed for the windows in question, thus your edit window is not refreshed until you fall out what ever message handler you are in. In other words, the message pump is suspended while your loop is processing thus the window you wish to display the result in never recieves the message to update itself with the value. You will need to force the message pump to run from within your loop.
Try adding a method like this to your dialog, and call it from within your for loop:
BOOL
CFWThumbsDlg::ProcessMessageQue()
{
MSG msg;
while( ::PeekMessage((LPMSG) &msg, (HWND) NULL, 0, 0, PM_REMOVE ))
{
TranslateMessage((LPMSG) &msg);
DispatchMessage((LPMSG) &msg);
}
return( TRUE );
}
|
|
|
|
|
Hi.
Your code would be right for a console (or DOS) app, which is run as a sequence.
As mentioned above, you block the message pump, because you do your work in thread which runs the GUI of your app. So you block the whole app!
There are some ways to avoid this problem:
1. Use threads
Count in a thread and send the changes as a (User-)message to the main window.
2. Use a timer
Create a timer when clicked on "Start" and kill it when clicked on "Stop"
In the timer routine you can do your UpdateData().
A propos: Never forget to call UpdateData(TRUE) before UpdateData(FALSE) !!
Learning to make a good desing will save you a lot of trouble!
Bye, Karl
|
|
|
|
|
I'm using VC6 SP5. Sometimes whilst coding I right click on the source code window, to bring up the context menu, and then click the ClassWizard item. Sometimes for seemingly no reason at all, the ClassWizard item is disabled, and will stay displayed until I close down, and restart VC6.
Anyone know why?
|
|
|
|