Setting command button visibility in VC++ 6.0? - visual-c++

How can I make the command button in my VC++ 6.0 dialog visible or invisible on load?

From the resource editor once you select the button, you can see its properties in the properties window. Here you can set the visible property to true / false. (assuming this functionality is present in 6.0 - i use 2003 now and cannot remember if this used to be present in 6.0)
Add CButton variable
If you want to dynamically change the buttons visibility during load, add a variable for your button using the MFC class wizard. (you are lucky to have this - this wizard seems to have been removed from Visual Studio .NET)
Override CDialog InitDialog
Next override the initdialog function of your dialog box and then once the base InitDialog function has been successfully called, set the buttons showwindow property to SW_HIDE / before showing the dialog box.
Code
BOOL CMyDialog::OnInitDialog()
{
CDialog::OnInitDialog();
if (ConditionShow)
m_MyButton.ShowWindow(SW_SHOW);
else
m_MyButton.ShowWindow(SW_HIDE);
return TRUE;
}

You can also do it without adding a CButton variable - just call
In the OnInitDialog method of the window containing the button/control, put in code:
CWnd *wnd = GetDlgItem (YOUR_RESOURCE_NAME_OF_THE_BUTTON)
wnd->ShowWindow(SW_SHOW) or SW_HIDE

What do you mean by 'commnad button' exactly ?
Anyway, you need to obtain the handle of the button then call ShowWindow function:
BOOL prevState = ShowWindow( itemHandle, SW_HIDE );

Only use
ShowDlgItem(Your_DLG_ITEM_ID,1); // visible = true
ShowDlgItem(Your_DLG_ITEM_ID,0); // visible = false

Related

How to check and uncheck and enable and disable a check Box control in MFC

What is the source code to do the standard checkbox actions with a Visual C++ MFC checkbox control?
set a check in the displayed checkbox control
clear a check in the displayed checkbox control
enable the displayed checkbox control for user input
disable the displayed checkbox control for user input
Controlling Checkboxes in MFC
Here's how to check, uncheck, enable, and disable a checkbox in MFC:
CButton* pBtn = (CButton*) GetDlgItem(IDC_SETUP_AM);
pBtn->SetCheck(0);// uncheck it
CButton* pBtn = (CButton*) GetDlgItem(IDC_SETUP_AM);
pBtn->SetCheck(1);// check it
CButton* pBtn = (CButton*) GetDlgItem(IDC_SETUP_AM);
pBtn->EnableWindow(0);// disable it
CButton* pBtn = (CButton*) GetDlgItem(IDC_SETUP_AM);
pBtn->EnableWindow(1);// enable it
bool isRemoveChecked = IsDlgButtonChecked(IDC_removeProf);
Alternatively, you won't need to retrieve a pointer to the button (checkbox) if you use CWnd::CheckDlgButton to check/un-check the button, for example:
BOOL isChecked = ...
CheckDlgButton(IDC_SOME_ID, isChecked);
And, enabling/disabling can be simplified to:
BOOL isEnabled = ...
GetDlgItem(IDC_SOME_ID)->EnableWindow(isEnabled);

How to show/hide an radio button dependant on option set field CRM 2011

I'm newbie on javascript. I'm triying to hide an radio button when a user choose a specific value of the option set. I have wrote this script
function showhideradiobuttom(){
var optValue = Xrm.Page.getAttribute("nav_phone1type").getValue();
if (optValue == 1) {
Xrm.Page.ui.controls.get("nav_phone1spam").setVisible(false);
}
else {
Xrm.Page.ui.controls.get("nav_phone1spam").setVisible(true);}
}
Unfortunatelly this is not working...
Make sure that you are running your javaScript function on the OnChange even of Option Set.

Dynamically Change Button Image in Excel 2010

I'm using XML to create a custom Excel Ribbon in which I have a button that contains an image. I would like to be able to change this image when the button is pressed (like a toggle) to show what state it's in. I have the following XML to describe the button:
<button id="MyButton"
label="MyLabel"
screentip="Some useful info."
onAction="MyAction"
getImage="GetImage"
size="large"/>
Where the MyAction method is defined as:
public void MyAction(Office.IRibbonControl control)
{
// Change button image here...
}
Is there some way I can change the button's image in the MyAction() method?
Cheers
EDIT: sorry, I just realised this was on the C# forum and I wrote the functions in VB. Do you need me to have the code translated into C#? Note that the callback behavior should be the same.
I find the easiest way to do update a control is to Invalidate the control or the whole ribbon and have the parameters update through the control's callbacks like getImage, getVisible, getLabel, etc
What I write here will work for any of a controls' parameters (label, enabled, visible, ...)
So if you define your button in the XML this way:
<button id="MyButton"
label="MyLabel"
onAction="OnAction"
getImage="GetImage"/>
You can then use the OnAction callback to update the button's paramater this way (assuming that you have a boolean variable called condition):
Public Sub OnAction(ByVal control As Office.IRibbonControl)
// Do your button stuff here
condition = Not condition
gui.InvalidateControl(control.Id)
End Sub
Then the callbacks of the button will get called, for getImage you can use:
Public Function GetImage(ByVal control As Office.IRibbonControl) As String
If condition Then
Return "MacroPlay"
Else
Return "DeclineInvitation"
End If
End Function
Note that for all this to work you need to store the Ribbon into the gui variable. For this you need to use in the XML:
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="OnRibbonLoad"> ...
and in the code:
Public Sub OnRibbonLoad(ByVal ribbon As Office.IRibbonUI)
gui = ribbon
End Sub
It looks as though you are correct. The only way I have found to edit the appearance of custom ribbon elements is to use 'Ribbon (Visual Designer)' and not XML.
For example, if I want to change an image on a toggle button called toggleButton1 I can do the following:
public void toggleButton1_Click(object sender, RibbonControlEventArgs e)
{
toggleButton1.Image = GetImage(toggleButton1.Checked);
}
where GetImage is defined as:
public Bitmap GetImage(bool pressed)
{
return new Bitmap(pressed ? Properties.Resources.img_1 : Properties.Resources.img_2);
}
Cheers
<button id="MyButton" label="MyLabel" onAction="OnAction" getImage="GetImage"/>
The solution above worked for me. Just make sure that you don't use loadImage event on your customUI xml node. Looks like if you use both loadImage and GetImage then addin fails to load.

Click OK in Dialog box display output text in SDI

I have a dialog box displayed when I press a menu item in the SDI window. In the Dialog box When i press OK button it should display "SUCESS" in the SDI window... In ONVIEW() i have to use pDC->TEXTOUT() but how to execute that statement on pressing OK button.. I am using visual C++ 6
you should define a user defined message and use PostMessage to call your method in SDI Window.
I am working on assumption that your dialog is modal.
You do not have to define or send any messages.
Retrieve data from the dialog.
Presumably you store 2D vector data in some kind of an array declared as a member variable of the dialog.
When OK button is pushed and copy data to a view’s member variable of the same type. Use it to draw whatever you desire.
void CSDIPopupSampleView::OnViewDialog()
{
CSimpleDlg dlg;
int iResponse = dlg.DoModal();
if(IDOK == iResponse)
{
//Copy data from a dialog here.
}
Invalidate(); // this will cause redraw
}

Disabling "Next" button In InstallScript

Using InstallShield - InstallScript project:
I made a custom dialog for browsing for a file.
On the dialog initialization I want to disable the "Next" button.
I am successful in disabling other buttons on this dialog except for any of the buttons of the install wizard: Cancel, Next and Back.
I used the functions _WinSubEnableControl or EnableWindow.
It works for me:
function
HWND hwndDlg, hwndNext;
...
begin
...
hwndDlg = CmdGetHwndDlg( strDialogName );
hwndCtrl = GetDlgItem(hwndDlg, NEXT);
EnableWindow(hwndCtrl, FALSE);
...
end;
If you didn't find this useful, please publish your code.
The code for disabling the button should be after the call to SdGeneralInit.
If you put it before (like I did) the change won't stick.
The call to SdGeneralInit explicitly enables the "Next" button, that is why it did not work for the "Next" button but did work for the other custom buttons on the dialog.
It should look something like that:
case DLG_INIT:
SdGeneralInit( szDlg, hwndDlg, 0, szSdProduct );
hDlgHandle = CmdGetHwndDlg(szDlg);
hNextButton = GetDlgItem(hDlgHandle, 1); // 1 is the id for the next button.
EnableWindow(hNextButton, FALSE);

Resources