|
Hi,
I have a sdi program. In the view's OnCreate function, I create a toolbar and a browser control in the view's client area. Now, if the view loses focus, the toolbar is inactive(grey). But I want the toolbar always active. How to do now?
Thanks.
Yu Hailiang
|
|
|
|
|
Handle
UPDATE_COMMAND_UI message for your particular toolbar.
CFrameWnd::OnUpdateButtonsInYourToolbars(CCmdUI* pCmdUI)
{
pCmdUI->Enable(true);
}
Hope this helps
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
Thanks. I find another way in MSDN to solve the problem.
To allow ON_UPDATE_COMMAND_UI handlers to work for other status bar panes and for toolbar buttons, you must derive new control bar classes and implement a message handler for WM_IDLEUPDATECMDUI. This is necessary because the default control bar implementations of OnUpdateCmdUI() assume the parent window is a frame window. However, it doesn't do anything but pass the parent window pointer on to a function that only requires a CCmdTarget pointer. Therefore, you can temporarily tell OnUpdateCmdUI() that the parent window pointer you are giving it is a CFrameWnd pointer to meet the compiler requirements. Here's an example:
LRESULT CMyToolBar::OnIdleUpdateCmdUI(WPARAM wParam,LPARAM lParam)
{
if (IsWindowVisible())
{
CFrameWnd* pParent = (CFrameWnd*)GetParent();
if (pParent)
OnUpdateCmdUI(pParent, (BOOL)wParam);
}
return 0L;
}
|
|
|
|
|
Your codes is neccessary if your handler is not in the CMainFrame (derrived from CFrameWnd).
If your handler is the in CMainFrame. It should be okay of just handling the OnUpdateCmdUI.
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
I had an SDI with some dialogs and through user inputs in the dialogs, i show my graphics in the SDI view using OpengGL rendering.But I was wondering why windows doesn't auto-refresh the view for me because as my dialog is in front of my view, whenever the dialog is shifted or moved, a white patch of the dialog'outline will overlap onto my graphics in the view... I do not know how to refresh my view again in this case...can anyone help?
|
|
|
|
|
You will have to re display ure image in this cse .Use OnPaint event handler for this.
No Worries!
|
|
|
|
|
thanx for replying. Can u elaborate on how i can re-display my image properly? My OpenGl coding was done in the dialog.cpp, then i should code the re-display in the view class OnPaint handler? I tried the following in the View class ONPAint message handler but unable to work:
Void ProjectView:: OnPaint()
{ CPaintDC dc(this);
InValidate();
UpdateWindow();
}
|
|
|
|
|
I need a real function that will create real random numbers, it should be able to be used in old-style c++, you know, console c++. lol
<marquee>Universal Project... Soon to be a .net
|
|
|
|
|
This is a small one to generate a seed.
void MyRandomize()
{
static unsigned int t = 0;
SYSTEMTIME st;
GetSystemTime( &st );
unsigned i = (unsigned int)st.wMilliseconds;
i+=t++;
srand(i++);
}
then call the:
rand() % /*number*/ ;
from <math.h> "I think"
APe
|
|
|
|
|
Not sure exactly what this is doing, but it appears way too complicated. Calling srand(time(NULL)) is sufficient for seeding the random number generator.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
In the code below, the non-recursive version contains less
code than the recursive version one. And the non-recursive
version is also much clear than the recursive version.
We can always use loops to replace recursions, and besides,
many bugs are due to functions calling themselves.
I still have no idea how do we benefit from rescursion?
Can somesone please make an real world example of how do we
benefit from recursion?
Is recursion new addition to C++? Is there recursion in C?
Thanks.
// non recursive version
<br />
#include <iostream><br />
using namespace std;<br />
<br />
int main()<br />
{<br />
unsigned int num;<br />
unsigned long fact = 1;<br />
<br />
cout << "Please enter the n: ";<br />
cin >> num;<br />
<br />
for(int j = num; j > 0; --j)<br />
{<br />
fact *= j;<br />
}<br />
<br />
cout << "The factorial of n is: " << fact << "." << endl;<br />
<br />
return 0;<br />
}<br />
// recursive version
<br />
#include <iostream><br />
using namespace std;<br />
<br />
unsigned long factfunc(unsigned long);<br />
<br />
int main()<br />
{<br />
unsigned int num;<br />
unsigned long fact = 1;<br />
<br />
cout << "Please enter the n: ";<br />
cin >> num;<br />
<br />
fact = factfunc(num);<br />
cout << "The factorial of n is: " << fact << "." << endl;<br />
<br />
return 0;<br />
}<br />
<br />
unsigned long factfunc(unsigned long n)<br />
{<br />
if(n >1)<br />
return n * factfunc(n-1);<br />
else <br />
return 1;<br />
}<br />
<br />
|
|
|
|
|
You're confusing yourself because your example is one that can be simplified down to a loop. (This is called tail recursion optimization because the work happens at the tail end of the code.)
Not all recursive algorithms fit this category. The recursion I write most often is travering a tree - not necessary a literal tree control, sometimes navigating a file system, sometimes things like "do something in this HTML document, plus all its subframes and sub-iframes, and their subframes..."
--Mike--
Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber
Pinky, are you pondering what I'm pondering?
I think so Brain, but if we shaved our heads, we'd look like weasels!
|
|
|
|
|
Okay, you are right, my example is one that can be simplified
down to a loop. But isn't most of the recursions can be simplified
down to a loop? So what is the benefit of using recursive algorithm?
Would you kindly make an example for me which the one that can
not be simplified to a loop?
Thanks.
|
|
|
|
|
Alex Ngai wrote:
Would you kindly make an example for me which the one that can
not be simplified to a loop?
Recursive algorithms are best applied to recursive data structures. As Mike has pointed out, manipulating a tree (which is a recursive data structure) is best done using small recursive functions. Other classic recursive algorithms are parsing, solving mazes, the Knight's Tour and the 9-Queens problem. See any classical CS text for descriptions of these.
That being said, remember that every recursive algorithm can be implemented in a non-recursive manner. In fact that's how all recursivs algorithms are executed in machine code! Converting a recursive algorithm to a non-recursive one basically requires you to manually maintain a stack (which is nothing more than a LIFO collection of state).
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Just because a loop has been eliminated does not make the algorithm more beneficial. All recursive algorithms can be converted to iterative algorithms. There are pros and cons to doing so. Some benefit the programmer, others benefit the computer.
Recursion seems a natural fit when a larger problem can be broken down into one or more smaller problems, using solutions to the smaller problems to solve the original problem. If a few basic rules are followed, recursion is easy (relatively speaking) and practical: 1) Base cases that can be solved without recursion; 2) Making progress towards a base case; 3) Design rule that assumes all recursive calls work; 4) Compound interest rule never duplicates work by solving the same instance of a problem in a separate recursive call.
Consider the recursive implementation of Fibonacci numbers:
long Fib( int N )
{
if (N <= 1)
return 1;
else
return Fib(N - 1) + Fib(N - 2);
}
It seems innocent enough, but for values of N > 30, it's inefficient. Its running time grows exponentially because of all the redundant work (compound interest rule). To compute Fib(N), there is one call to Fib(N - 1) and Fib(N - 2). However, since Fib(N - 1) recursively calls Fib(N - 2) and Fib(N - 3), there are actually two separate calls to Fib(N - 2). Similarly, Fib(N - 3) is computed three times, Fib(N - 4) is computed five times, Fib(N - 5) is computed eight times, etc. These results are thrown away and recomputed later on.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Recursion is easily possible in C and C++, as well as many other languages.
Don't think of it as a "looping is better" / "recursion is better" situation - they are both tools. Certainly there are given procedures that can be expressed using either. But as Mike mentioned, there are some that just seem "natural" to use recursion in implementing, while others make the most sense expressed as loops.
Always remember - you're writing this code for the benefit of the programmer (you and whoever else may read/update the code), not the processor. If it were any other way, you'd be writing machine code...
BTW: you may find this discussion interesting...
Your sincerity about keeping the soapbox organized and civilized is so obvious. I solute your effort.
-- Anonymous, 10/18/03
|
|
|
|
|
Can anyone enlighten me why the compiler is giving this error, "use of class template requires template argument list"?
template<typename T1>
struct MyStruct
{
typedef pair<string, T1<big>&</big>> CLASSINFO;
string className;
static CLASSINFO make_pair <string clsName, const T1<big>&</big> clsRef>
};
typedef int (*PF)(MyStruct<T1><big>&</big> mySt); Thanks for any insight.
William
Fortes in fide et opere!
|
|
|
|
|
|
My property sheet has four pages: new, read, sent, user. When a user is selected, I want to refresh the three pages new, read, and sent. At what event should I handle the refresh?
Eilzabeth
|
|
|
|
|
I'm curious why you'd want to refresh an inactive page. Why not wait until the page is activated before refreshing it?
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
You are right as I am learning more on using property sheet. The OnSetActive() function will work.
Elizabeth
|
|
|
|
|
Has anyone made a chm file for a Chinese program?
I am having problems getting the Chinese characters to appear in the index. At first I thought it was to with fact that I was generating the HTML with script from an Access database however the characters do appear correctly in other viewers. The Help Topics themselves are also correct if I omit the meta tag specifying the "charset=big5"
Is there different version of the HTML help compiler that I need to use for Asian languages? (I may have the same problem with Japanese and Thai in that case)
Happy programming!!
|
|
|
|
|
Hi,
I have Dialog box which has a edit box. I have a separate thread which waits for a event from another application and updates the edit box.
A part of my codeis given below
UINT ScalerOFC( LPVOID lpParam )
{
......
....
while (TRUE)
{
ScalerOF = RtWaitForMultipleObjects(2,ScalOF,FALSE, INFINITE);
if (ScalerOF==WAIT_OBJECT_0)
{
MessageBeep(MB_ICONHAND);
m_errorlog = ........... // I have the problem here
pDialog->ShowWindow(SW_SHOW);
}
}
return 0;
}
I included a member variable of type CString for the Editbox called m_errorlog, but I couldnt access this variable in my thread.while copiling i get a error saying that m_errorlog is an undeclared identifier.
What should I do to access a member variable from my thread?
Is there any way out?
Thanks,
Deepak Samuel
|
|
|
|
|
Pass the class that you wish the thread to access to the threadproc. If you make the threadproc a static member of your active class then you can access private members.
This kinda thing.
class Active
{
public:
Start()
{
ThreadProc(this);
}
private:
static int WINAPI ThreadProc(LPARAM lParam)
{
Active* impl = reinterpret_cast<Active*>(lParam);
while(true)
{
++impl->m_Member;
}
}
volitile int m_Member;
};
..gads, 2 edits
Ryan
|
|
|
|
|
Hi!
I made a managed web service with VC++ and when I try to get the WSDL I've got this message: 'System.SByte* is inaccessible due to its protection level. Only public types can be processed.'
It seems that some kind of pointers are not allowed to be arguments of web methods (I never worked before with C++ nor Visual Studio .NET and I'm a little... confused?). The question is, how I must replace this data type?
Thanks!!!
Pep Lainez
|
|
|
|