Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Spin control... yet again

Posted on 1998-10-01
7
Medium Priority
?
368 Views
Last Modified: 2008-02-07
Me again,
Something is going wrong... refer to the history of the question...
I inserted this into OnInitDialog...
OnVScroll(SB_THUMBPOSITION,m_spin1,NULL)
It compiles and crashes...oops!
When I debug, it perfroms that line and goes to OnVScroll and gets hit somewhere around if(bla bla bla)
HELP PLEEZ... I am now getting desperate
Thanx
0
Comment
Question by:rose3377
7 Comments
 

Author Comment

by:rose3377
ID: 1174135
Does this problem have something to do with the fact that the dialog is not yet displayed and all the DDV,DDX stuff?

Another thing...
If I overlook the inital display problem and I continue, when I press up arrow, it increments in 0.1 which is great.
If I type in 12 and press up arrow, it becomes 1.3
How do I correct this....?
0
 

Expert Comment

by:tsauy
ID: 1174136
Yes, you need to wait until the window is ready to display. You can put OnVScroll() in OnPaint(). If you don't want to reload OnVScroll() afterwards, which means you only want to run once when the window starts, you need a flag to disable it, such as:
void YouClass::OnPaint()
{
   .
   .
   static bool RunOnceFlag=false;
  if(!RunOnceFlag) {
     OnVScroll();
     RunOnceFlag=true;
  }
}

Answer to second question: You could use integer and then devided by 10.
0
 

Author Comment

by:rose3377
ID: 1174137
Refer to the history of the question in titled Spin Control again
I placed that code in OnPaint. The program gets to OnVScroll...

   CString strValue;
   strValue.Format("%3.1f", (double) nPos / 10.0);
***((CSpinButtonCtrl*) pScrollBar)->GetBuddy()
                           ->SetWindowText(strValue);

and crashes on the line with stars...
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:rose3377
ID: 1174138
See Comment Above...
0
 
LVL 2

Expert Comment

by:jrmcg
ID: 1174139
Yours:

       ***((CSpinButtonCtrl*) pScrollBar)->GetBuddy()
           ->SetWindowText(strValue);

There should be parenthesis around the GetBuddy function.  Remember, it is returnin a CWnd*.

Try:::
(((CSpinButtonCtrl*)pScrollBar)->GetBuddy())->SetWindowText(strValue);

Does that do it?
0
 
LVL 11

Accepted Solution

by:
mikeblas earned 0 total points
ID: 1174140
The extra parenthesis that jrmcg suggests aren't required.  (Read a book on C++ for details.)

B ekiM

0
 
LVL 11

Expert Comment

by:mikeblas
ID: 1174141
Calling a notification function directly, like tsauy suggests to do with OnVScroll() directly from OnPaint(), is completely sick and wrong.  If you're unlucky, it will actually work and you'll be fooled until your users upgrade to a new verison of windows and it breaks.  Nominally, it'll cause a crash.

Don't do it; it's wrong.

B ekiM
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question