-
April 30th, 2004, 02:01 AM
#1
Swap Button Positions
Hi Guys,
I have here a simple problem that I could not figure how to do it. I have two buttons, lets say button 1 and 2, I need to swap these button to each others position. This means That button 1 will take button 2 position in the dialog and button 2 will take button 1 position.
For the time being, I changing the text on the button and it looks like its swapping but its just changing the text.
PHP Code:
void CPLAYDlg::OnButton(UINT uID)
{
// TODO: Add your control notification handler code here
SetDlgItemText(uID,"0");
CString str;
str.Format ("%d",uID-1000);
SetDlgItemText(IDC_BUTTON0,str);
}
in the above code, I changed the text of button 0 with the button with uID as ID. Any one can help me on this????
Thank You.
Come Join This Poll Where are we from? (Ultimate)
Knowing is not enough; we must apply. Willing is not enough; we must do. - Johann Wolfgang
An idle brain is the devil's workshop. - unknown
-
April 30th, 2004, 02:22 AM
#2
Do you need to do this permanently (i.e. from start-up) or are you saying that you want to the buttons to be swapping positions while the program is actually running?
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
April 30th, 2004, 02:50 AM
#3
Originally posted by John E
Do you need to do this permanently (i.e. from start-up) or are you saying that you want to the buttons to be swapping positions while the program is actually running?
Tha buttons is supposed to swap when one of the buttons is clicked. And it should not be permanent as as I may add more buttons and add the same functionality to swap between each other.Is that possible??
Come Join This Poll Where are we from? (Ultimate)
Knowing is not enough; we must apply. Willing is not enough; we must do. - Johann Wolfgang
An idle brain is the devil's workshop. - unknown
-
April 30th, 2004, 03:07 AM
#4
Max - I've heard of some great ways to confuse your users but that one deserves a prize...!
Try something like this for each of the buttons (I haven't tested the code but it should work)
GetDlgItem(IDC_BUTTONx)->MoveWindow(newXPos, newYPos, newWidth, newHeight);
GetDlgitem(IDC_BUTTONx)->ShowWindow(SW_HIDE);
GetDlgitem(IDC_BUTTONx)->ShowWindow(SW_SHOWNA);
You might have to experiment with 'SW_SHOWNA'. If it doesn't work, try SW_SHOW or SW_SHOWNORMAL
Good luck!
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
April 30th, 2004, 03:10 AM
#5
Code:
void FOO_DIALOG::SwapButtons(CButton& button1, CButton& button2)
{
CRect rect1, rect2;
button1.GetWindowRect(&rect1);
button2.GetWindowRect(&rect2);
ScreenToClient(&rect1);
ScreenToClient(&rect2);
Button1.MoveWindow(&rect2);
Button2.MoveWindow(&rect1);
}
Didn't test it
Wakeup in the morning and kick the day in the teeth!! Or something like that.
"i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do."
-
April 30th, 2004, 03:19 AM
#6
Originally posted by John E
Max - I've heard of some great ways to confuse your users but that one deserves a prize...!
Originally posted by souldog
code:--------------------------------------------------------------------------------
void FOO_DIALOG::SwapButtons(CButton& button1, CButton& button2)
{
CRect rect1, rect2;
button1.GetWindowRect(&rect1);
button2.GetWindowRect(&rect2);
ScreenToClient(&rect1);
ScreenToClient(&rect2);
Button1.MoveWindow(&rect2);
Button2.MoveWindow(&rect1);
}
--------------------------------------------------------------------------------
Didn't test it
That just what I wanted. Thanks both of you.
Come Join This Poll Where are we from? (Ultimate)
Knowing is not enough; we must apply. Willing is not enough; we must do. - Johann Wolfgang
An idle brain is the devil's workshop. - unknown
-
April 30th, 2004, 03:30 AM
#7
Pleasure - incidentally, I've sometimes found that changing a window's style or position - e.g. MoveWindow(), SetWindowPos(), ModifyStyle() etc - can't be relied upon to work immediately in all flavours of Windows. Sometimes the window isn't moved or re-styled until it next gets re-drawn - therefore it's a good idea to force a re-draw by hiding the window and re-showing it again.
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
April 30th, 2004, 06:35 AM
#8
You could also use SetDlgCtrlID() and swap the control id's. Combine this with swapping the button text, it might be easier that moving everything around. Plus, this method should preserve the tab ordering or the buttons.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|