pierre_ribery
Posts
-
Push Button -
how to get index of minimum of one array#include <algorithm> using namespace std; int main() { double myArray[10] = {2.12,432.12,543.1,0.32,0.65,12.,54.2,542.5,100,200}; double* start = myArray; double* minimumPosition = min_element(myArray, myArray + 10); double minValue = *minimumPosition; int indexOfMinimum = minimumPosition - start; return 0; }
-
How much data can be stored by CString Type varibleThen use a CRichEdit control. That being said, it is horrible design to put 120Mb into an edit control
-
memory leak in the code?Yes that was exactly my point! If you have allocated memory, then you have to delete it. Therefore it is vital to initialize your pointers to 0 before using them. Cheers, Pierre
-
memory leak in the code?Your code said it. Anyway, I think it is pretty important to show it in the code as well.
-
memory leak in the code?Not like that, see my earlier post. Always initialize pointers!! In this case set them to NULL(0). int* a = NULL; int* b = NULL;
-
memory leak in the code?In a case like this you should initialize both a and b to 0 before the try clause. You cannot delete a or b at this stage, I assume you will need to use them later, or what was the purpose of allocating them? int* a = NULL; int* b = NULL; try { a = new int [N]; b = new int [M]; } catch (bad_alloc) { // Tell the user if a or b failed... } // Do some stuff on a or b // Now delete if they are allocated if(a) delete a[]; if (b) delete b[]; Thanks!
-
Thread structureHi everyone! I guess this has been discussed here before but I couldnt find anything. My question is: Why is the threads sorted only after when the thread was created?
-
Calculate the number of times a character occurs in a stringLike this: std::string str("this is a test string only"); int num = std::count(str.begin(),str.end(),'a'); Remember to include string and algorithm
-
Calculate the number of times a character occurs in a stringLike this: std::string str("this is a test string only"); int num = std::count(str.begin(),str.end(),'a'); Remember: #include #include
-
mfc dialog application problemI agree that it is an alternative. But can you please answer this question: Which approach do you think is the best?
-
mfc dialog application problemWhy wait executing the code? The sooner the better I would think. That being said, you are wasting resources even if it is a one-shot timer. I think that any professional windows programmer would agree with me that the timer approach is not the best, but again you are free to do it the timer way if you think that is best.
-
mfc dialog application problemPlease re-read my post, I have made some updates.
-
mfc dialog application problemBecause you are not guaranteed that the WM_TIMER message will be handled. THe dialog might be closed before the timer elapses (lets say 200-300ms). If you post a user defined message in OnInitDialog you are guaranteed that it will be handled before any messages sent after this! the timer might be invoked too late. From MSDN: The WM_TIMER message is a low-priority message. The GetMessage and PeekMessage functions post this message only when no other higher-priority messages are in the thread's message queue. also, you have to remember to kill the timer as the first thing in the WM_TIMER handler. Another point is that it uses significantly more system resources to simply post a message. Why create a timer which will post a message, when you can directly post the message? Timers are limited system resources. Might be more reasons, but it boils down to what is the best approach. The timer approach is a possibility, but not the BEST.
-
mfc dialog application problemGo for the PostMessage approach. Post it at the end of OnInitDialog. Forget the timer approach. PostMessage is the correct way to do this.
-
Moving a windowHandle WM_NCHITTEST and always return HTCAPTION.
-
On Timerok, if I understand you correc, you want to increment the value of an edit box every 1 second, starting from 0 going to 100. If that is the case, then a timer is the way to go. Your timer needs to be set up for 1000ms(1sec). You have set it up for 100ms only. SetTimer(1,1000,NULL); Now create a member variable for your edit control of type "value" and set its datatype to int. Lets call it "value". In OnTimer: if (nIDEvent==1) { if(value < 100) { value++; UpdateData(FALSE); } }
-
On TimerYou have not specified what is not working as expected, so please tell us what you want to do! What do you need a timer for this?
-
Entering Negative values in MSVS 6.0 Edit dialogs.Create a class derived from CEdit, let us call it CIntEdit, and handle WM_CHAR message: void CIntEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { //Allowed characters CString numeric = "-0123456789."; if (numeric.Find(nChar) != -1) CEdit::OnChar(nChar, nRepCnt, nFlags); } This will only accept integer values. Pierre.
-
wait for CWinThread to terminate -- from UI threadThat is NOT the case. This works as it should for worker threads! Please, show me what in my code would not work!