|
Danoo wrote:
- Have a WorkerThread that prepares data and an OnTimer handler that displays the data if modified
Sure, you can have a worker thread preparing data. The OnTimer() should be in the GUI thread, though. You must however, of course, correctly synchronize access to shared data.
Danoo wrote:
- Having a WorkerThread that holds a handle to a DC (or maybe memDC) that paints to the window whenever he thinks its due.
If you keep a DC and use it to paint in, then it's not a worker thread in my point of view, but a GUI thread. A memory DC might pass as appropriate in some extreme cases. But don't use multiple GUI threads. Just don't.
Before you think about any other alternative - are you following the #1 rule of optimization?
Dont't optimize until you have actually measured that it's necessary!
Just lowering the CPU usage is not a justified reason to optimize. Is the CPU usage too high? That's the question.
Danoo wrote:
Which approach do you use ?
Given the fact that I must optimize, I tend to stick to one thread only, unless the amount of number crunching required to update the GUI is massive.
I would probably use a class or private DC, since they exist for that particular purpose. When the timer fires, I would invalidate only changed areas and paint what I'd prepared between the timer events.
--
Dad, how strange it is that the pig can speak. *thoughtful pause* It must have lost its "oink". (my 3-year old daughter Moa, while watching Babe)
Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so. (Douglas Adams)
|
|
|
|
|
A combination of both, I believe. If I was doing this, I'd go for the timer function, with an user option to set the refresh rate.
Also, when using the timer approach, you should have a memory DC in the worker thread, draw all data in this thread, and then just use the timer to BitBLT the data from the memory DC into the window's client area. This optimizes graphic card usage, as no data is drawn during the actual 'creation' of the display. Naturally, the worker thread needs a way to tell the timer if the new data is ready to be displayed, or if the thread is still drawing it.
Consider an option that if the window that shows the results is not a top-level window or doesn't have focus (is minimized, for example), then no drawing takes place. This would optimize the CPU usage even more if the user is doing something else meanwhile.
Moreover, if your application requires real-time results display, then the best option is to use DirectX APIs for your display. Unfortunately I cannot provide any examples.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
I'm sure this is something simple that I just can't find.
I am adding a list of disk drives to a combo box. I used GetLogicalDriveStrings for the list of drives and GetVolumeInformation to get the volume name. I take the volume name and combine it with the drive name so it looks just like the drive tree in explorer. My problem is when a volume does not have a label. When a volume does not have a label, Explorer substitutes a generic string like Local Disk, DVD Drive, DVD/CD-RW. Where does it get these strings? GetDriveType doesn't even have a DVD constant added yet. I don't even know what to look for on MSDN, but everything I have tried have not produced any results. Any help is appreciated!!
|
|
|
|
|
This just a guess, but it might be from the registry.
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\D\DefaultLabel
changes the description in Explorer for my CD-ROM drive when there's no disk in the drive. Note the drive letter in the registry key, so you'll need to change that for other drives.
|
|
|
|
|
Graham Bradshaw wrote:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\D\DefaultLabel
What version of windows are you using? I'm using XP Home and that key does not exist. I tried searching for DriveIcons and DefaultLabel. Thanks for trying!
|
|
|
|
|
Pheonix wrote:
What version of windows are you using?
XP Professional SP1. You may have to add the key - I also have an entry for the E: drive, which is a Memory Stick (the computer is a Sony VAIO laptop).
|
|
|
|
|
I guess the home edition of XP just doesn't contain this key. It's good to know that I can put anything I want in there though. I'm trying to find the windows defaults that explorer uses. I'll keep searching. Thanks for the help!
|
|
|
|
|
Update: Just tried it here, and it works with a ZIP drive as well. The key quoted is the whole key. If you set the default entry for that key to a string, Explorer picks that up and uses it instead when displaying the drive.
|
|
|
|
|
Hi all,
I am a new to MFC/VC++.
I have already asked my question,but I think,experts are unable to understand my question.Once again I would like to explain my question.
I create a property sheet which contains three property pages.
pag1.
pag2.
pag3.
page1 contains three - Text Box.
text1,
text2,
text3
Now, I create thee- member- variable of int type.like
m_ntxt1,
m_ntex2 and m_ntxt3,
I enter two integer value in tex1 and text2.
Finally,When I click 'OK' button on a propety sheet(not on a propery page).It should be displayed the sum of integers(m_ntxt1+m_tex2) in text3 and AfxMessageBox.How to do this.
Thanks
rajesh
|
|
|
|
|
The following is a useful check-up list to accomplish what you describe
1. Create a command handler for the property sheet's OK-button click.
2. In this handler, use GetActivePage to get a pointer to the currently active property page object.
3. Use DYNAMIC_DOWNCAST to cast from the CPropertyPage pointer returned above into your derived class' pointer.
4. Create a function into your derived class that does the following:
4.a. Calls UpdateData(TRUE)
4.b. Calculates m_ntxt3 = m_ntxt1 + m_ntxt2
4.c. Calls UpdateData(FALSE)
5. Now, in the property sheet's command handler, call the derived property page class' function that will calculate the sum.
This approach requires that all the controls (Edit boxes) and the integer variables belong to the derived property page class. If you need to display a pop-up message box, then use a temporary CString object, formatting it with the integer data (CString::Format ), then calling AfxMessageBox and supplying the CString object as the text parameter.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
How to call GetActivePage?
rajesh
|
|
|
|
|
This function is defined in CPropertySheet class, from which you have derived your property sheet class. Inside the click-handler function, just call GetActivePage and save the return value into a CPropertyPage -type pointer. This grants you access to the CPropertyPage base class of the object that is currently active.
In here, it is imperative to distinguish between classes and objects. If you feel unsure what their differences are, please look in any given C++ guidebook. Basically, a class is the layout, from which objects (of this class) are built, or instantated.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Hi!
I am writing MFC SDI. The view is to display graphic objects and needed to be wide. I want to hide menubar, I tried GetMenu, but it does not work. If we can get the menubar m_hWnd, we can use ShowWindow, but I don't know how.
So is there anyway to hide the menubar?
Thanks
sovann.
|
|
|
|
|
Here is a code snipet from MSDN ... maybe you can use this to remove the menu and add it back when required. This code is written in CMainFrame
<br />
SetMenu(NULL);<br />
::DestroyMenu(m_hMenuDefault);<br />
<br />
m_NewMenu.LoadMenu(IDR_SHORT_MENU);<br />
ASSERT(m_NewMenu);<br />
SetMenu(&m_NewMenu);<br />
<br />
m_hMenuDefault = m_NewMenu.GetSafeHmenu();
|
|
|
|
|
This code works! Thank you
|
|
|
|
|
Hi, I am writting an application in which some actions needs to be taken when the system is shutdown or restarted. I have been handling the events using WM_QUERYENDSESSION, but lParam parameter used for it is capable off only differentiating between Log off and shutdown events. In fact all the values remains same for Restart and shutdown.
Is there a way through which i can determine whether the system is shutting down or has been requested to restart?
Mayank Goyal
|
|
|
|
|
HI,
I m using VC++ n Directshow to play a video file (.wmv).
I have a Play and Stop Button on Dialog.
When i press Play Button its starts playing. Stop Button Bcoms Enable n Play button to Disable.
i want to know When the Video becomes end ..
actauly i want Disable Stop Button When whole video is played and it becomes to n end.
any idea .. or help thanx
|
|
|
|
|
Hello all,
i need to make some 256x256 bitmaps from lots of other bitmaps that can be 256x256 and smaller...
how would i set up a loop that can take small bitmaps and add them to a 256x256 bitmap and when full create a new 256x256 bitmap and continue adding until all the small bitmaps are done...
i need to add them without going out of bounds of the 256x256 bitmap and without resizing them to fit...
thanks for any help,
i know how to work with the bitmaps but
i need help with the looping process,
thanks,
[B]*SlimGradey*[/B]
|
|
|
|
|
I have write a service program,now I want to start it when computer appears the login UI,what should I do?
|
|
|
|
|
There are numerous examples on writing services to Windows Plaform available here in CodeProject. Just follow this link to the appropriate section.
If you feel like not following the link, then just go to Code Project main page, browse the left-hand menu down to General MFC/C++ -> System -> Services to find what you need.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
I have VS 6.0 and i've been trying to incorporate icons with colors more than 16 but i keep getting a distorted, downgraded appearance. Is there a way to fix this?
|
|
|
|
|
( I'm not in front of VC right now )
did you create icons with bigger palettes ? in VC++6, when you open up an icon, there's a menu somewhere ( in a toolbar ? ) where you can create icons with a different palette. In VC.net, I think it's in a contextual menu when you right click on an icon.
also, I don't believe VC can handle hi-res bitmaps or icons ( more than 256 colors ), yo might need to "patch" them manually in the resources; create a dummy icon file and replace it with a hi-res one, and NEVER editing it in VC.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Hi..can anybody..suggest me How to make timer for
1. Minute
2. Hours
3. days
i.e. User set a time for process to execute after 10 min. then after 10 min. a event is fired & process start running..
this 10 min. can be 10 days...
Plz suggest me how to go next..as I didn't find any timer that even deals with min. or hours..even days r too far. evry timer is based on milisecond..that i don't want...
I hope u'll help me..
Thanks
---Sumit Kapoor--- sumit_kapoor1980@hotmail.com
|
|
|
|
|
1000ms = 1sec
60sec = 1min
60mins = 1hour
24hours = 1day
7days = 1week
got the point?
what's wrong with a timer interval of (1000 * 60 * 10) for 10 minutes (just as an example)?
You can safely use SetTimer . There are not "timers for days/minutes" that I'm aware of.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
thanks for reply..
But there must be limit to pass vaue of time in SetTimer function..I'm not sure but that must be 65,000ms
this means I can do with 10 min. interval..but when I wish to do with days interval then it would be problem for program to check over & again...
do u have any idea..
Thanks..bye
sumit_kapoor1980@hotmail.com
|
|
|
|