Visual C++

  Home  Computer Programming  Visual C++


“VC++ Interview Questions and Answers will guide us now that Microsoft Visual C++ (MSVC) is a commercial integrated development environment (IDE) product engineered by Microsoft for the C, C++, and C++/CLI programming languages. Learn MS VC++ or get preparation for the job of Microsoft Visual C++ with the help of this VC++ Interview Questions with Answers guide”



10 Visual C++ Questions And Answers

1⟩ Why Array Index starts from Zero?

This boils down to the concept of Binary digits. Take an array size of 64 for example. We start from 0 and end at 63. We require 6 bits.But, if we were to start from 1 and end at 64, we would require 7 bits to store the same number, thus increasing the storage size.

 237 views

7⟩ How to load an Icon on a CButton at Runtime?

CButton *btnsample = (CButton *)GetDlgItem(IDC_BUTTON1);

btnsample->ModifyStyle(0,BS_ICON,SWP_FRAMECHANGED); //change the style of CButton

HICON hIcon = ::LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDI_ICON)); //load an Icon assuming IDI_ICON is ID of ICON

btnsample->SetIcon(hIcon);

 205 views

8⟩ How to change the Mouse Pointer Over a Button at runtime?

Assuming that you have set the button's ID as IDC_BTNSAMPLE in the resource editor :-

// You have to handle the WM_SETCURSOR message handler to do that

BOOL CTestDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)

{

if (pWnd == GetDlgItem(IDC_BTNSAMPLE))

{ // To load a standard cursor

::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_CROSS));

// To load your own custom cursor. Assuming that you have created a

// Cursor in the resource editor and named it as IDC_CURSAMPLE

::SetCursor(AfxGetApp()->LoadCursor(MAKEINTRESOURCE(IDC_CURSAMPLE)));

// Remember to return TRUE here return TRUE;

}

return CDialog::OnSetCursor(pWnd, nHitTest, message);

}

 214 views

9⟩ How to change the position of Button at runtime?

Assuming that you have set the button's ID as IDC_BTNSAMPLE in the resource editor :-

CButton *pBtnSample = (CButton *)GetDlgItem(IDC_BTNSAMPLE);

pBtnSample->SetWindowPos(0,0,0,100,100,SWP_FRAMECHANGED);

 225 views

10⟩ How to change the Properties of a Button at runtime?

Assuming that you have set the button's ID as IDC_BTNSAMPLE in the resource editor :-

We have to use the ModifyStyle Function to do this. The function is defined as follows :-

CButton *pBtnSample = (CButton *)GetDlgItem(IDC_BTNSAMPLE); // Make the button look like a checkbox

pBtnSample->ModifyStyle(0,BS_AUTOCHECKBOX,SWP_FRAMECHANGED); // Remove the checkbox style and make it again normal

pBtnSample->ModifyStyle(BS_AUTOCHECKBOX,0,SWP_FRAMECHANGED);

 203 views