|
Do you know any methods or functions that return how many elements that are in the array?
Like before
Array[0] = 1;
Array[1] = 2;
There are "Two" elements in this array.
Do you know of anything like that?
Cheers again,
Michael
|
|
|
|
|
Sorry I dont get your question correctly.
Suppose you are allocating a memeory with size 5. Then the length of the array is 5. And whats the confusion in that?
you can get the size of memory that you dynamically allocated using new or malloc using the function _msize() . Is that what you want?
|
|
|
|
|
Use a std::vector and be done with it.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
yep I agree.... Thank you for your help!
Cheers
|
|
|
|
|
Michael101 wrote: ShortArray[0] = 1;
ShortArray[1] = 5;
Length of the array is 2... Mean there are two elements. How do you return the length?
const unsigned int length = sizeof(ShortArray)/sizeof(ShortArray[0]); That is, you divide the amount (in bytes) of your array by the size (in bytes) of one element.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
Hello all,
I'd like to know how to make a Win32 list view control show multiple lines of text beside the icon just like Explorer does:
|||| file_name.txt
|||| Text document
|||| October 10th 2007
I want to be able to control the text on each line and I am having no success, it just wraps a single line of text if it does not fit on one line. No matter what I do - adding columns, putting newlines to the text, setting number of lines with LVM_SETTILEVIEWINFO... nothing helps.
So far I have found only .net examples please, which are useless to me.
Thanks for any pointers.
|
|
|
|
|
Just for a bit of masochistic fun I decided to try and do this using MFC 6, the class CListCtrl of which doesnt include any explicit support for TileView.
1. ensure _WIN32_IE and _WIN32_WINNT are both defined to 0x0501 for the entire project
2. in OnCreate of CMyListView use supported InsertColumn to add 4 columns, then SendMessage(LVM_SETVIEW,,) and SendMessage(LVM_SETTILEVIEWINFO,,) specifying 2 columns
3. for each item added SendMessage(LVM_SETTILEINFO,,) listing the columns I want to see
4. make an application manifest for the exe, I used the myapp.exe.manifest XML file method rather than the resource method
Hey presto multiline TileView using MFC 6, if any one of those steps is omitted then I dont get multiline TileView.
|
|
|
|
|
It seems that I have overlooked the LVM_SETTILEINFO message and thought that LVM_SETTILEVIEWINFO is all that is needed.
Thanks for helping me, you have saved me a lot of time!
|
|
|
|
|
I have a problem I need to solve - preferably elegantly!
I have a series of inputs to my software.
Imagine... If Input A - turn an output on in 5 seconds for 2 second.
If Input B, turn an output on in 3 seconds for 2.5 seconds.
I was thinking of a queue of "on" times, and checkinh if the output should on every (eg 0.1s).
but imagine InputA came on briefly, then 1 second later InputB came on as well. You would have overlapping ON times.
I know I can do this with brute force, have a list of on-off structs, (probably using CPoint), and check every one of them each 0.1s - and get rid of the "expired" ones.
But I'm sure there must be a more elegant solution, probably using STL. It's possible there could be a *lot* of these queued events, so some some of merging of events would be helpful.
Any ideas welcome!
Iain.
|
|
|
|
|
Iain Clarke wrote: I have a problem I need to solve - preferably elegantly!
I have a series of inputs to my software.
Imagine... If Input A - turn an output on in 5 seconds for 2 second.
If Input B, turn an output on in 3 seconds for 2.5 seconds.
How many outputs are involved? Do Input A and B control the same output?
You could have a queue of inputs, each with an ON time span. First, remove an input from the queue and turn the output on for the specified duration (you'll have to decide when it's appropriate to check the queue for inputs). Set a timer to notify you when that duration has expired. When you get a timer notification notifying you that the current input has expired, get the next input and do the same thing again. This assumes that only one output can be turned on at any one time.
If each input controls its own output, then I would approach it differently. I'd set up a timer to tick periodically, say every 100ms. I'd have a queue for the inputs, just as before. I'd check the queue for inputs in response to timer ticks. If there are any inputs in the queue, I'd remove the first one, turn on an output, and place the input into a second queue. The second queue would be a priority queue with the inputs sorted by their duration.
When an input is placed into the priority queue and the queue was previously empty. I'd reset an accumulator variable to zero. Now in response to each timer tick, I'd add the elapsed time to the accumulator (probably use an unsigned long for this). On subsequent timer ticks, if the priority queue is not empty, I subtract the accumulator from the first item's duration. If the result is less than or equal to zero, I remove the item from the queue and turn off its output. I repeat this action until the priority queue is either empty or the duration of the first item in the priority queue is greater than my accumulator.
So in response to each timer tick, I'd process any inputs in the input queue, update my accumulator, and process any items in the priority queue that have expired. Actually, I'd probably do that in reverse order. Process the priority queue first, then the input queue.
|
|
|
|
|
Leslie & El Corazon,
First, thanks for your long thought out replies! It sounds like you both have a decent amount of real experience.
Secondly, my specs were vague. Both (in fact it's 5 - but I was being "simple") inputs map onto a single output. If any of the inputs decree an ON!, then the output will switch on.
My thought were to have a queue of events pushed by the defect detection thread(s), and a check-the-queue-every-now-and-then thread popping the events off.
As these ON events could overlap, my real question was whether there was a really neat way of merging them, so two overlapping ONs become one longer ON instead.
So, a queue of 1s-5s & 10s-12s would be left alone, while 1s-5s & 4s-8s would become 1s-8s.
So it was more of a pure computing problem than I presented it as.
Thanks again for your time,
Iain.
|
|
|
|
|
Iain Clarke wrote: so two overlapping ONs become one longer ON instead.
that is easier still. Use a queue or a ring-buffer as I mentioned, they can be used interchangeably, though a queue will require mutexing if it does not have implicitely shared in the design. When something is "turned on" put it on the on-queue.
When you output, check the on-queue, if anything is present, check it for expiration, if the time has expired, pop it off, if it has not expired, then send output. Pretty simple asynchronous operation. And you don't even have to do a mid-queue removal either. Even if item two has expired, and item one has not, you will want to output. When item 1 expires, you pop it off, check the next one for expiration, and pop it off. You only care if anything is left in the queue, i.e. the queue is not empty, then output.
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
|
|
|
|
|
Iain Clarke wrote: I have a series of inputs to my software.
Imagine... If Input A - turn an output on in 5 seconds for 2 second.
If Input B, turn an output on in 3 seconds for 2.5 seconds.
I deal with this pretty regularly, all our inputs are asynchronous. I guess I should ask, what is the output? Do you want to blend the output of two things during a "double on" situation? do you want to put one at higher priority? How exactly do you wish to handle a double on situation. Forget the implimentation at the moment, start from the statement of action. You have multiple inputs.... double off, no problem, no output. Single on, single off, single output, again no problem. So then comes the doozy, the exception case, double/many on, what do you see as the preferred output? what is the output? where is it going? Is .1 second check the preferred output format? would you alternate between any/all outputs? is there a priority involved where one output should always be first?
I have one situation with position data where sources number n, some unknown number at startup, 1 to many. The code channels the input to a variety of parallel threads to handle the data as rapidly as it comes in. The output is simply stored in an implicetly shared structure that is read from another thread, synced to video (60 times a second). The result is asynchronous output, though the time can be requested in synchronized form given time sync filtering.
In another case, my streaming debugger for embedded applications, many threads feed a ring buffer that feeds a transmit thread for sending debugging information. This allows for n threaded debugging or any system on a network. N threads feeds 1 thread via single channel shared structure similar to a queue (a ring buffer is just an over-glorified queue with fixed memory footprint).
You can always have a queue of "on" events, rather than check all states, setup another queue, though with a read-only option, probably as a vector or ring buffer because of the fixed memory state. Then you need only "push" an on-event onto the "active" state list. Another thread can read and process only the active states sending output, handling priorities, and "pop" completed activities. We do this for a state engine for script events which is always an asynchronous many to many relationship. My goal is always to keep things asynchronous as the input until the very last frame before display, then synchronize if necessary. But that is because I know my data input is always asynchronous, synchronizing it only lowers its accuracy, so I want to do as little as I have to of manipulation of data.
You can also simulate a threaded operation using any heart-beat hardware event from the host system, from idle calls, to timers, to screen refreshes (vsync), etc.
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
|
|
|
|
|
I replied to Leslie here[^].
It's a bit long to retype - but was "thanks for the help you two, and here are some facts I neglected..."
Iain.
|
|
|
|
|
Hi, i have SDI app with dialog based on CDialog class. I need to get pointer to client area to set some properties.
|
|
|
|
|
zarraza wrote: Hi, i have SDI app with dialog based on CDialog class
Do you have a dialog based app, or a SDI app, with the view based from CFormView? These are different things.
As for your second question, can't you not use
CWnd::GetDC / ReleaseDC?
What sort of properties are you talking about?
|
|
|
|
|
For simplify this lets say it is a SDI app with the view based on CFormView (if needet can be CDialog based).
In this view i want to set size of client area, because on client area i have to put dynamicaly variable number of buttons, and client area size have to be enought big, sometimes even bigger then screen size.
I don't know if GetDC/ReleaseDC can help resolve my problem.
|
|
|
|
|
oninitdialog / getclientrect
|
|
|
|
|
I don't know if i understand MSDN corectly, but there is said that GetClientRect() just return coordinates of client area respectively to window area, not handler of client area.
|
|
|
|
|
That is true - but the only thing you'll care about is the rectangle's width
or you can use MapWindowRect....
Iain.
|
|
|
|
|
If i add a button dynamicaly which is outside client area, the scroll bars doesn't appear and i have to resize window manually(by clicking mouse in corner at runtime) to see this button. It has to be a way to make those scrollbars visible and scrolling very big client area (eg if i want 1000 buttons on dialog or very big image).
|
|
|
|
|
CFormView is based on CScrollView. Normally you would call ResizeParentToFit at some point (or MFC will do it for you), what you want to do is provided by a call to SetScrollSizes after you add this "button which is outside the client area".
|
|
|
|
|
Thank you Roger i search for this solution for few days and couldn't find nothing usefull. I love You man.
|
|
|
|
|
Design a calculator, which should have the following:
sin x, cos x, tan x, Sq Root
Along with standard features and memory facility(M+,M-,MR,MC)
avishekbanerjee
|
|
|
|
|
This is a good assignment. Report back when you are done and tell us how it went.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|