|
After step 1, *x contains (*x ^ *y) . After step 2, *y contains (*y ^ (*x ^ *y)) , which is just *x . After step 3, *x contains ((*x ^ *y) ^ *x) , which is *y . Make sense? Any number XORed with itself is 0.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
The logic is this:
A = A (operation) B
B = A (operation Inverse) B
A = A (operation Inverse) B
If you do one operation and then two inverse operations you will have swapped the numbers. The "xor" operator is actually the inverse of itself, so that's why it works the way it does.
For example if you use +, - is the inverse:
A = 10, B = 20
A = A + B (10 + 20 = 30)
B = A - B (30 - 20 = 10)
A = A - B (30 - 10 = 20)
A = 20, B = 10
A = 10, B = 20
A = A * B (10*20 = 200)
B = A / B (200/20 = 10)
A = A / B (200/10 = 20)
A = 20, B = 10
A = 10, B = 20
A = A ^ B (10 ^ 20 = 30)
B = A ^ B (30 ^ 20 = 10)
A = A ^ B (30 ^ 10 = 20)
A = 20, B = 10
xor is also communiative, so it didn't matter the order you have A or B when doing ^. This XOR swap was generally used by small processors which memory operations were slow, so 3 XOR instructions could be faster. That actually used to be the method of setting registers to 0 as well, XOR reg, reg as it was faster than a MOV reg, 0.
8bc7c0ec02c0e404c0cc0680f7018827ebee
|
|
|
|
|
So you can think of it as:
1. Combine the numbers together and store in one of the values.
Combined = A + B for example 10 + 20 = 30. In +. But any operation will combine numbers.
2. Inverse, thus if two numbers are combined you will get the opposite number of what you inverse.
Original1 = Combined - B, for example, 30 - 20 = 10. You get the original number.
3. Using the opposite number, now you use the combined number to get the original.
Original2 = Combined - Original1 So you do the inverse again on the new number to get the original.
You can see that if you combine two numbers, you can use those numbers in inverse operations to get the original numbers.
8bc7c0ec02c0e404c0cc0680f7018827ebee
|
|
|
|
|
The Stupid XOR Trick[^]
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
Is there any method found in the IDE of Visual C++ 2003 to remove functions seen in "Class View"? (other than manually delete text in .cpp and .h.)
Thanks!
Maxwell Chen
|
|
|
|
|
Hii alll
how can i change the background of my form????in vc++
thanks
|
|
|
|
|
You can read up on WM_CTLCOLORDLG[^] or you can set it when you register the window class.
Alex Korchemniy
|
|
|
|
|
Look in the CFrame, CMDIFrame, CView, or a class derived from one of these, for some methods to do this. Those classes perform the drawing of the windows and their background. There may be some public members that can be directly set also. My personal guess is a CFrame derived class. I don't remember completely, but you may have to use some API functions to get the pointers to the objects that would need to be changed.
The form background should not be in the App class or the Doc class, since these have to do with running the program and storing the data. I know this does not provide all the answer, but just gives somewhere to start.
David Spain, C++ Applications Programmer
|
|
|
|
|
Hi,
I want add a context menu on a tree (hosted in MFC Dialog), everything wotrk fine unless I do not get the menu draw (only a little strip).
So what's wrong in my code :
CMenu menu;
POINT pp;
GetCursorPos(&pp);
if (menu.LoadMenu(IDR_MENU_TREE))
{
menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON,
pp.x, pp.y,
AfxGetMainWnd()); // use main window for cmds
}
Thanks in advance ...
|
|
|
|
|
You are trying to show a top-level menu as a popup menu which is not possible.
You will need to get a submenu of IDR_MENU_TREE, like this:
menu.LoadMenu(IDR_MENU_TREE);
CMenu* pSubMenu = menu.GetSubmenu(0);
if (pSubMenu != NULL)
{
pSubMenu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON,
pp.x, pp.y, AfxGetMainWnd());
}
Hope this helps
|
|
|
|
|
hello,
i need to know steps to create a modeless dialog box in a parent SDI application.I know that a CreateDialog function is to be used;but how?
please guide
thanks
|
|
|
|
|
m_pDlg = new CMyDialog;
m_pDlg->Create (IDD_MYDIALOG);
m_pDlg->ShowWindow (SW_SHOW);
Note:Modeless dialog boxes are dismissed by calling DestroyWindow, not End-Dialog. You mustn't allow CDialog::OnOK or CDialog::OnCancel to be called on a modeless dialog box, because both call EndDialog.
Also create it on the heap always.
suhredayan There is no spoon.
|
|
|
|
|
It is a little long to explain how to use moldeless dialogs so I'll point you to an article: here[^] is a good article that explains the basis of modeless dialogs.
And, BTW, what do you mean by 'dialog box in a parent SDI application' ? The difference between modal and modeless dialogs is just that the dialog isn't 'blocking' (that means the parent window will still be active with a modeless dialog). The modeless dialog is not 'embedded' in the parent window.
|
|
|
|
|
cedric moonen wrote:
And, BTW, what do you mean by 'dialog box in a parent SDI application' ?
I think the second parameter below was meant by the parent.
explicit CDialog(
LPCTSTR lpszTemplateName,
CWnd* pParentWnd = NULL
);
suhredayan There is no spoon.
|
|
|
|
|
Yes of course I know that you can set a parent to a modeless dialog but I think what he really wants to do (as seen also in his previous post) is a dialog which is 'included' in the parent. So, that is a dialog that has no title bar and that is pasted on the parent. But I'm not sure so that's why I asked for some details.
|
|
|
|
|
thanks,
i was successful in creating a modeless dialog box.But i am still not able to use the Ondestroy() function.Kindly tell me the same.As you said that modeless dialog can't be opened in mdi window(which is exactly what i was trying).Then it means we will have to display it as child window.The properties section of dialog editor offers similar option.Is it correct?
thanks
|
|
|
|
|
Hello!
I need to show CPropertySheet object with not first page opened.
SetActivePage in OnInitDialog doesn't work. Can anybody help?
Oleg Chebotar
|
|
|
|
|
Why doesn't SetActivePage() work? It is what I call from the propertysheet's OnInitDialog() function and it works fine for me. I just make sure it is the last thing called in OnInitDialog() before it returns.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
I have declared the following in my application.
CMap<cstring,lpcstr,cwnd*,cwnd*> m_map;
I have a windows explorer like setup.
When i click a node in the tree i need to display an MDI Window.
So i have mapped the node item's text (LPCSTR) to that of the window pointer .So when i click a node i use CMap to get the window pointer and display the window.
Now when i alternatively click the windows i get the window pointer and i want to correspondingly shift the focus on the tree items.
So my question is how do i look up the key ( i.e LPCSTR) when i have the value (i.e.. CWnd*).
laiju
|
|
|
|
|
I have declared the following in my application.
"CMap < CString,LPCSTR,CWnd*,CWnd* > m_map"
I have a windows explorer like setup.
When i click a node in the tree i need to display an MDI Window.
So i have mapped the node item's text (LPCSTR) to that of the window pointer .So when i click a node i use CMap to get the window pointer and display the window.
Now when i alternatively click the windows i get the window pointer and i want to correspondingly shift the focus on the tree items.
So my question is how do i look up the key ( i.e LPCSTR) when i have the value (i.e.. CWnd*).
.
laiju
|
|
|
|
|
Is there any reason you're using CMap instead of map, in the C++ standard library ? CMap, CList, CArray,etc. were all written only as a stopgap until the stl came online. They are really crappy in comparison.
You need to build a second map that goes the other way. Even if you iterate through the keys collection, checking for the value ( which is a very lousy thing to have to do ), there's no guarentee that your value appears only once, so there's no guarentee you'll find the right key.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
You'll need to iterate through all keys and check if each key's value matches the CWnd* you're searching for.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
But that only works if each CWnd is only in there once. And it's damn ugly.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
True. What he really needs is a multimap.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Does multimap let you search the values ?
Christian Graus - Microsoft MVP - C++
|
|
|
|