|
Ohhhh REGISTRY subkeys
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Gee, wasn't it obvious?
|
|
|
|
|
Oh right, I thought it was a similar question to one I'd answered a few days ago, but I didn't notice that it was the same person...
Regards,
--Perspx
Don't trust a computer you can't throw out a window
-- Steve Wozniak
|
|
|
|
|
I have a serious problem which i am not being able to figure. This program finds all the permutations of a given string using recursion. The diagnostic outputs show that the values of the 'choice' and 'final' character arrays is not maintained at a position (I don't know why). Please help.
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <string.h>
using namespace std;
class Permutation
{
private:
static char s[20];
int width,l;
public:
void input();
void compute();
void recur(char choice[],char final[],int);
};
char Permutation::s[20];
void Permutation::input()
{
cout<<"Enter the string:";
gets(s);
cout<<"Places to arrange:";
cin>>width;
};
void Permutation::compute()
{
l=strlen(s);
char s1[20];
recur(s,s1,0);
}
void Permutation::recur(char choice[],char final[],int p)
{
int i,j,chk,c=0;
if(p==width){
cout<<"OUT: "<<final;
cout<<endl;
return;
}
for(i=0;i<l;i++){>
chk=0;
for(j=0;j<strlen(final);j++){>
if(s[i]==final[j])
chk=1;
}
if(chk==0){choice[c++]=s[i];}
}
choice[c]='\0';
for(i=0;i<c-1;i++){>
final[p]=choice[i];
final[p+1]='\0';cout<<"Beforein:\t "<<choice<<" -\t "<<final<<" -\t "<<p+1<<" -\t"<<i+1<<" "<<c<<endl<<endl;
recur(choice,final,p+1);
cout<<"Returned: \t"<<choice<<" - \t"<<final<<" - \t"<<p+1<<"-\t"<<i+1<<" "<<c<<endl<<endl;
}
}
int main()
{
Permutation arrange;
arrange.input();
arrange.compute();
getch();
return 0;
}
</string.h></stdio.h></conio.h></iostream.h>
|
|
|
|
|
What is "Places to arrange"?
Could you please give an example of expected input-output?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Ok, that was hasty programming, "places to arrange" means the spaces in which we have to arrange it. eg. 'pineapple' can be taken 2 at a time or three at a time to form a string (pi,ne,ea etc).
Enter a string:care
Places to arrange:3
so we can have:
are,car,ear,rac ...etc..etc..
|
|
|
|
|
Well, I had troubles following the logic of your program hence rewrite my own version based on the requirements. It is almost plain C , if you feel its output correct then you can easily incapsulate it in a class.
#include "stdafx.h"
#include <string.h>
void choose(char in[20], int len, int width, int level);
int main(int argc, char* argv[])
{
char in[] = "abcd";
choose2(in, 4,3,0);
return 0;
}
void swap(char & a, char & b)
{
char t = a;
a = b;
b = t;
}
void choose(char in[20], int len, int width, int level)
{
int i;
char out[20];
memcpy( out, in, 20);
if ( level == width)
{
for (i=0; i<level; i++)
{
putchar(out[i]);
}
putchar('\n');
return;
}
choose(out, len, width, level+1);
for (i=level+1; i<len; i++)
{
swap(out[level],out[i]);
choose(out, len, width, level+1);
}
}
BTW the program is far from being optimized.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I really appreciate the the code you compiled. It is simplified.I would like to state my problems very clearly with the code I wrote.The crux of the problem is my inability to understand why the recursion procedure is not following the pattern it was supposed to:
class Permutation
{
private:
static char s[20];
int width,l;
public:
void input();
void compute();
void recur(char choice[],char final[],int);
};
char Permutation::s[20];
the above is the class definition, easy enough.
void Permutation::input()
{
cout<<"Enter the string:";
gets(s);
cout<<"Places to arrange:";
cin>>width;
};
function to enter the values.
void Permutation::compute()
{
l=strlen(s);
char s1[20];
recur(s,s1,0);
}
this is the function which calls the recursive function
RECURSIVE PART:
1.
void Permutation::recur(char choice[],char final[],int p)
choice[]: contains all possible letters which can take the position
eg. care - for the first position > c,a,r,e is stored as 'care' when the first is set to 'c' then for the second position is 'a,r,e' and so on..
final[]: stores the string to be printed..when all the spaces are filled , it is printed
p: holds the position where a character has to be inserted from the choice[] to final[]
2.
int i,j,chk,c=0;
if(p==width){
cout<<"OUT: "<<final;
cout<<endl;
return;
} >
this is the base conditon: if the width is reached it prints the string
3.
for(i=0;i<l;i++){>
chk=0;
for(j=0;j<strlen(final);j++){>
if(s[i]==final[j])
chk=1;
}
if(chk==0){choice[c++]=s[i];}
}
choice[c]='\0';
This is the part in the recursive function which finds all the possible characters which can be put into a space...it checks the initial string and compares it to final[] ...the choice[] are the ones which aren't present in final.
4.
for(i=0;i<c-1;i++){>
final[p]=choice[i];
final[p+1]='\0';cout<<"Beforein:\t "<<choice<<" -\t "<<final<<" -\t "<<p+1<<" -\t"<<i+1<<" "<<c<<endl<<endl;
recur(choice,final,p+1);
cout<<"Returned: \t"<<choice<<" - \t"<<final<<" - \t"<<p+1<<"-\t"<<i+1<<" "<<c<<endl<<endl;
}
}
The chart of the recursive function is shown here:
http://i452.photobucket.com/albums/qq241/ronjay_2008/Misc/chart.jpg[^]
the characters assigned for a position on final[] are taken from choice[]
4.
int main()
{
Permutation arrange;
arrange.input();
arrange.compute();
getch();
return 0;
}
Simple class construction
5. What I did not understand:
Since I wasn't getting the output, I added diagnostic check in the recursive function to check how the values were changing on each step. I knew that in the stack for each recursive iteration a separate instance of the array is created (choice[],final[] and p),but the output did not conform.
check this:
http://i452.photobucket.com/albums/qq241/ronjay_2008/Misc/OUTPUT.jpg[^]
The part in yellow shows the state at an earlier iteration. Therefore, when 'recur' return to that state later, it should have printed the same values of choice[] and final[] which is not so. Only p,i and c are consistent. Whatever happened to choice[] and final[]? They should have retained their original values which according to the ouput it hasn't.
Maybe, there is minor error which i have overlooked. Please sort this.
If you want the .exe file its here:
output_permutation.exe
|
|
|
|
|
Hi All,
I tried to identify with depends.exe .(COM dlls can be known from this tool .)
But could not identify.
Can someone help me in this regard.
Thanks
Appala Naidu Uppada
Appu..
"Never explain yourself to anyone.
Because the person who likes you does n't need it.
And the person who dislikes you won't believe it."
|
|
|
|
|
you could try calling LoadLibrary on the file, then call GetProcAddress on the handle, to see if the EXE exports DllGetClassObject.
|
|
|
|
|
That only works for DLLs though.
|
|
|
|
|
which part doesn't work in EXEs ?
|
|
|
|
|
I mean, is there any tool like Depends available to identify the EXE is a component?
Appu..
"Never explain yourself to anyone.
Because the person who likes you does n't need it.
And the person who dislikes you won't believe it."
|
|
|
|
|
Hi,
I have one application, which should use pop up window. If I configer the system as dual monitor, drag the application to the secondary display, then click the button to pop up the window, the window will go to the primary display. In the source code, the pop up window is created by:
wnd->CreateEx(menuAlwaysOnTop ? (WS_EX_TOPMOST | WS_EX_TOOLWINDOW) :
WS_EX_TOOLWINDOW,
AfxRegisterWndClass(CS_NOCLOSE), "MenuWindow",
WS_POPUP, rect, NULL, 0, NULL);
I tried to change it to
wnd->CreateEx(menuAlwaysOnTop ? (WS_EX_TOPMOST | WS_EX_TOOLWINDOW) :
WS_EX_TOOLWINDOW,
AfxRegisterWndClass(CS_NOCLOSE), "MenuWindow",
WS_POPUP, rect, parent, 0, NULL);
Changed the last third parameter from NULL to parent, which is the main application window. But the pop up window is still go to the primary display. How can I figure it out?
Thanks in advance!
|
|
|
|
|
I am not sure what the problem is??
But to solve your problem you can get parent window rect and set the child window position accordingly using
1.SetWindowPos
2.MoveWindow
You can also try calling
CenterWindow(GetParent()) from child window.
I hope it helps..
Regards,
Sandip.
|
|
|
|
|
Hi Sandip,
Thank you very much for your tip. I will try the ways as you said.
Here I would like to clarify my question again: actually I found many applications have this problem same as mein. For example, Outlook, if you configure your system as dual monitor, start Outlook, drag the outlook to the secondary display, then click compose new email. You will see the new email composing window pops to the primary display. But an opposite example is Visual Studio. If you do the same thing for Visual studio, click open file button, the new dialog sticks same with the main visual studio window.
|
|
|
|
|
Hi Sandip,
I tried CenterWindow(GetParent()). But it doesn't work. The pop up window is still in the primary display, while the main application window is in the secondary display. I do it in this way:
wnd->CreateEx(menuAlwaysOnTop ? (WS_EX_TOPMOST | WS_EX_TOOLWINDOW) :
WS_EX_TOOLWINDOW,
AfxRegisterWndClass(CS_NOCLOSE), "MenuWindow",
WS_POPUP, rect, parent, 0, NULL);
wnd->CenterWindow(parent->GetParent());
Does it mean the "parent" is not the real main window? or CenterWindow() doesn't work? Actually the position of the pop up window is same as before.
Best,
|
|
|
|
|
'Dual view' is complicated stuff, and this is how it works. If anything can be done to avoid this behavior then that can be done in 'Display Driver', as far as I know.
Cheers,
Vishal
|
|
|
|
|
Hi Vishal,
Could you please give me a hint how to do in "Display Driver"? I never use it. But I would like to try.
|
|
|
|
|
logiqworks wrote: wnd->CenterWindow(parent->GetParent());
Here you should pass i think only parent.
BTW what is parent?? is it main window or just another child of main window??
I hope it helps..
Regards,
Sandip.
|
|
|
|
|
Do you mean to pass only parent like this:
wnd->CenterWindow(parent);
The parent is one child of main window. Because it is complicated to get the main window, so I just use one child window.
|
|
|
|
|
logiqworks wrote: Do you mean to pass only parent like this:
wnd->CenterWindow(parent);
Yes, But does window pointed by parent come in primary display or it comes properly.
You can get the handle to main window using
AfxGetMainWnd();
Regards,
Sandip.
|
|
|
|
|
Hi Sandip,
The situation is that the parent window is initially generated in primary display. I drag it to the secondary display. Then do some operations and pop up some windows. And the pop up window will go back the primary display.
I tried
wnd->CreateEx(menuAlwaysOnTop ? (WS_EX_TOPMOST | WS_EX_TOOLWINDOW) :
WS_EX_TOOLWINDOW,
AfxRegisterWndClass(CS_NOCLOSE), "MenuWindow",
WS_POPUP, rect, AfxGetMainWnd(), 0, NULL);
wnd->CenterWindow(AfxGetMainWnd());
as you said. But the pop up window is still in the primary display. And it doesn't locate in the center of the window.
|
|
|
|
|
May be then you should do
CRect rect;
parent->GetWindowRect(rect);
wnd->MoveWindow(rect.left,rect.top,500,400,TRUE);
this should work i think.
If it works then you can adjust the wnd position according to rect values to where ever you want.
Regards,
Sandip.
|
|
|
|
|
Hi Sandip,
Thank you very much for your so nice help. I tried the code above, but it still doesn't work. I debugged it. rect.left is -2200, rect.right is -786. Does it mean the parent lies in the secondary display? I set the secondary display as in the left side, and the primary display in the right side.
The strange thing is that whatever I do, the pop up window is always in the primary display, the same position.
Best regards,
|
|
|
|
|