|
i don't know what is the reason of of error.
i write it with c++ & i send what is it about.
it is the code:
<big>#include <iostream>
#include <string>
#include <cctype>
using namespace std;
class cart{
public:
cart(char a[2]="paq"){
cout << a[0]<<a[1]<<a[2];};
char left()
{
char a[2];
swap(a[0],a[1]);
for (int b=1;b>=2;b++)
cout << a[b];
return 'L';
};
char right()
{
char a[2];
swap(a[2],a[1]);
for (int b=1;b>=2;b++)
cout << a[b];
return 'R';
};
char en()
{
char a[2];
swap (a[0],a[2]);
for (int b=1;b>=2;b++)
cout << a[b];
return 'E';
};
char fo()
{
char a[2];
for (int b=1;b>=2;b++)
cout << a[b];
return 'F';
};
};
int main ()
{cout << "swap the cart juker1,ace,juker2" <<endl;
char b[50];char a[2];a[0]='p';a[1]='a';a[2]='q';
for (int i=1;i>=50;i++){
cin >>b[i];
if (b[i]='.') break;
};
cart x;
for (int i=1;i>=50;i++){
if ((b[i]='l')|(b[i]='L')) x.left();
else if ((b[i]='r')|(b[i]='R')) x.right();
else if ((b[i]='e')|(b[i]='E')) x.en();
else if ((b[i]='f')|(b[i]='F')) x.fo();
};}</big>
and it is what i want to do:
He has a table with three face-up cards in a row: two jokers and one ace, with the ace in the middle. After you make a small wager, he turns the cards face-down and begins to manipulate the cards, swapping cards two at a time. After he completes the swaps, you are then to guess which card is the ace.
The series of card swaps will be given to you in order as a String swaps, containing only the characters 'L', 'R', 'E', and 'F'. swaps[0] indicates the first swap. The 4 characters indicate the following moves:
L: swap the left and middle cards
R: swap the right and middle cards
E: swap the cards on the ends (the left and right cards)
F: fake swap (no cards actually change position)
Write a method that returns the final position of the ace, after all the swaps have been performed. Your method should return "L" if the left card is the ace, "R" if the right card is the ace, and "M" if the ace is in the middle.
thanks for attention
|
|
|
|
|
You've got the wron forum --- this is for MFC (Microsoft Foundation Classes) that use a version of Visual Studio or Visual C++.
AF Pilot
|
|
|
|
|
1) this sounds like homework - we dont do homework - at best we will give you hints, but if you're expecting us to jump in and solve all your issues, go to RentACoder or such
2) DONT GET IMPATIENT AND POST MORE THAN ONCE - most of us here have jobs we get paid to do, I doubt any of us get paid to help others on CP - except CP staff themselves, and most of them are involved with the actual running of the site, not answering questions
3) post in the correct forum - showing that you can do so indicates some level of intelligence - else, the responses you get will be rather 'trite' if not, brutal
Some suggestions :-
1) show what output you get - or where there's a compile error or such - I dont think you've actually stated what the problem/issue is
2) assuming your code compiles : learn how to use the debugger - use F10/F11 to single step through your program, inspect the contents of variables etc as you go - or at worst, print out their contents, then walk through what you're trying to do 'on paper' and see if that tells you whats going wrong.
3) comment your code - if you cant understand it, and cant tell us what each piece is doing, we wont spend much time on it either
4) looking at your code, I think you need to go back through your textbooks, a bit more .. for example char a[2]="paq" .. ok, so, if 'a' is a character array of size '2', how many characters are you trying to stuff in there - perhaps 3 ?? Im not sure what compiler you are using, but I can tell you in MSVC(6) you'll get "error C2117: 'paq' : array bounds overflow"
'g'
|
|
|
|
|
Hello ,
Even though my application does not have the manifest file,Vista shows shield icon over my exe.
Initially I thought it was because of the Installer detection Techniques,
such as:
1) Analyzing the Exe name, the OS identifies the required level of Execution.
2) Analyzing the binary content of the application, where the OS identifies the required level of execution.
I copied the Exe to the desktop, but it did not put the shield icon over my exe.
So I came to a conclusion that the above two scenarios are not the reason for this failure.
Environment:
Installed OS - Vista Business.
Account - Administrator with UAC turned on.
The Exe was displayed under Program Files directory. To run the application Admin Rights is not required.
Is there a different scenario that we need to try inorder to remove the shield icon which is displayed over the exe file
Note: Previously My application had manifest file, but now we have changed the Exe inorder to make it run in the standard user privilege. (Therefore we removed the manifest file)
The funniest part was, even though it displays the shield icon, UAC prompt did not pop up, when i am trying to launch the Exe and therefore the Application launched without any problem.
Is this a Vista bug? what can i do remove this shield icon.
Would really appreciate your help.
Thanks,
WindowsPistha.
|
|
|
|
|
WindowsPistha wrote: I copied the Exe to the desktop, but it did not put the shield icon over my exe
Do you have a standalone manifest file for it in the directory where it exists when it displays the shield? Even if the manifest does not exist in the executable as a resource, it should still look for one in the directory of the executable and use it if it fits.
I've noticed those standalone manifests suffer from caching when you try to delete or remove one, the effect can linger even though the manifest no longer exists there. Various techniques to shake it loose like rebooting ultimately prevail but not after some cursing and head scratching.
Anyway, just an idea.
|
|
|
|
|
Thanks Bob !
rebooting also did not help
|
|
|
|
|
Dear All,
I want to create GUI in MFC like the one we see in Apple iTunes or in a Sony ericsson PC suite. In the mentioned GUI's the dialog is loaded when the user clicks on a button at the right panel. When I develop an application like this, my program throw assertion error due to loading and unloading dialogs. This is due to the memory while calling DoModal() recursively while clicking the buttons.
Please guide me to develop an application where we can load 'n' number of dialogs at 'n' number of times.
Many thanks in advance.
|
|
|
|
|
It is strange that a dialog uses this much memory...
What operation is done to use this much memory? Are you freeing them proper?
- ns ami -
|
|
|
|
|
I have four buttons in my dialog, totally four dialogs for four buttons, when I click a button1 it will load the appropriate dialog1 (dlg1->DoModal()). If I click button2 then it will load the dialog2 (dlg2->Modal). Code snippet is :
<br />
Dialog1 dlg1 = new Dialog1();<br />
OnCancel();
dlg1->DoModal();<br />
<br />
Dialog2 dlg2 = new Dialog2();<br />
OnCancel();
dlg2->DoModal();<br />
<br />
<br />
Dialog3 dlg3 = new Dialog3();<br />
OnCancel();
dlg3->DoModal();<br />
<br />
<br />
Dialog4 dlg4 = new Dialog4();<br />
OnCancel();
dlg4->DoModal();<br />
<br />
|
|
|
|
|
bhanu_8509 wrote: new Dialog1();
If you are creating dialog using new, then in each button click, a new instance of dialog will be created. It might be the reason of memory leak. I think you need to create them once, and reuse it again and again.
- ns ami -
|
|
|
|
|
please tell me how to do this. i cannot create a global object to each and every dialog. frankly I dont know how to create global objects which can be accessed in other dialogs.
thanks.
|
|
|
|
|
For such an application a main dialog/window should be there to track these button selections... So that these kind of recursive DoModal can be avoided.
A sample... not perfect but only to get the idea.
void CMainDlg::ShowDlgs()
{
for( ;; )
{
int nNextDlg = 1;
switch( nNextDlg )
{
case 1:
{
Dialog1 dlg;
nNextDlg = dlg.DoModal();
}
case 2:
{
Dialog2 dlg;
nNextDlg = dlg.DoModal();
}
case ID_EXIT:
return;
}
}
}
Better is to make the use of user/registered message communication between parent (main dialog/window) and child dialogs (Dialog1, Dialog2, etc.), but I don't know exactly what you are trying to do.
- ns ami -
|
|
|
|
|
Why not...
void CMyFirstDialog::OnButtonOne ()
{
EndDialog (ID_BUTTON1);
}
....
...
CDialog *pDlg = new CMyFirstDialog ();
int nReturn = 0;
while (pDlg)
{
nReturn = pDlg->DoModal ();
delete pDlg;
pDlg = NULL;
switch (nReturn)
{
case ID_BUTTON1:
pDlg = new CFirstDlg;
break;
case ID_BUTTON2:
pDlg = new CSecondDlg;
break;
....
}
}
ASSERT(!pDlg);
OK, that was very quick and hacky - with no real error checking, but I hope it gives you an idea. The main difference is you wait till one dialog is finished and tidied up, *then* move on to the next one. Other wise, they just stack one on top of the other...
Iain.
switch (
Codeproject MVP for C++, I can't believe it's for my lounge posts...
modified on Tuesday, January 27, 2009 9:54 AM
|
|
|
|
|
I'm not certain I understand correctly what you want to achieve.
I don't have iTunes in front of me; and I don't see what you mean by "clicks on a button at the right panel".
Me think it's quite moronic to call DoModal() recursively.
If you want to create and display N dialogs M number of times, you'd better
use modeless dialogs and be conscious about managing the memory (when you
create and destroy the dialogs).
|
|
|
|
|
No I dont want to use modeless dialogs. I will try with Ian suggestion and get back to you all.
Thanks.
|
|
|
|
|
Hello Community,
i need to check if users have change the selection in CListCtrl,
i have now this if users change selection with the mouse(mouse click),
but the selection change is posible with the arrow keys too!
How to check this event: user change selection with arrow keys in CListCtrl,
i need to do some updates if there is a new selection in CListCtrl??
Thanks for any help!!
termal
|
|
|
|
|
termal wrote: How to check this event: user change selection with arrow keys in CListCtrl
Make the use of LVN_ITEMCHANGED notification.
- ns ami -
|
|
|
|
|
Hello,
thanks for answer, i try this way!
regards
termal
|
|
|
|
|
Please handle LVN_ITEMCHANGED[^] message. When a selection change occurs in the list control, the parent dialog/window will get a LVN_ITEMCHANGED message
|
|
|
|
|
Hello,
thanks for answer and i hope its ok if i answer here to naven only??
Yes this works fine, and easy to implement this funktion!
Only one funny thing is now in execution of program, this LVN_ITEMCHANGED is send 3 times?? Also my function i called 3 times??
Here my code:
ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST, &CMyDialog::OnLvnItemchangedListAll)
void CMyDialog::OnLvnItemchangedListAll(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLISTVIEW pNMLV = reinterpret_cast<lpnmlistview>(pNMHDR);
int iCurIndex = m_cListAll.GetSelectionMark();
CString csItemText = m_cListAll.GetItemText(iCurIndex, 1);
TRACE(L"%s\n", csItemText);
PrintData(csItemText);
*pResult = 0;
}
</lpnmlistview>
So is in output the same text 3 times listed , for example if i have text in my current selection: www.codeproject.com
they is dump three times , any idea how to avoid this(if possible ), or is this common property??
But this is that what i'm looking for!
Thanks for help!
termal
modified on Tuesday, January 27, 2009 10:02 AM
|
|
|
|
|
That is because the notification is sent for different states. You can check the new and old state flags in the "LPNMLISTVIEW pNMLV". And if the new state is selected and old is not selected, then proceed it.
- ns ami -
|
|
|
|
|
termal wrote: thanks for answer and i hope its ok if i answer here to naven only??
Its ok. I will inform ns.ami cause he is my friend and we both work in same company
termal wrote: Only one funny thing is now in execution of program, this LVN_ITEMCHANGED is send 3 times??
Yes this is because, the LVN_ITEMCHANGED is fired not only for selection change but also for foucs changes. So you should check, whether the current LVN_ITEMCHANGED is for selection change or not.
NM_LISTVIEW* pNMListView = reinterpret_cast<NM_LISTVIEW*>(pNMHDR);
if( LVIF_STATE == (pNMListView->uChanged&LVIF_STATE) )
{
if( LVIS_SELECTED == (LVIS_SELECTED&pNMListView->uNewState) )
{
}
else if( LVIS_SELECTED == (LVIS_SELECTED &pNMListView->uOldState) )
{
}
}
|
|
|
|
|
Hello,
thank you very much to you and ns.ami for help, it works now!!
with best thanks
termal
|
|
|
|
|
Naveen wrote: he is my friend and we both work in same company
Please don't tell the truth...
- ns ami -
|
|
|
|
|
I have an application, where i open the private Queue. This works fine.
But when I run this app as a windows service, it gives an error failed to open the Queue, Access is denied.
I know it has got to do something with the rights.
If the app is run as an exe, it will have the logon credentials. When run as windows service it will run with System credentials, which may not have access to Private Queue.
How do i enable my windows service to have access to the private Queue???
Any help will be great.
Thanks,
Saleem
|
|
|
|
|