In Particular I need help with the the boxes with stars inside them. Thank you _
ID: 3916838 • Letter: I
Question
In Particular I need help with the the boxes with stars inside them. Thank you
_____ Create a new project in Visual studio and call it Test_3_YourName. Make the project an MFC Application that is dialog based. (In the Advanced Features uncheck "Active X controls" and "Common Control Manifest". Also remember to right-click the project name, select Properties and set the Character Set property to "Not Set".
_____ Move the OK button and change the text to "Exit".
_____ Add three check boxes with the text set respectively to "Red", "Green", and "Blue".
_____ Create BN_CLICKED event handlers for each of the check boxes in the projectNameDlg class.
_____ Add a variable to each of the check boxes with which to reference each.
_____ Add two buttons at the bottom of the dialog. Set the text on the first to "All On". Set the text on the second to "All Off".
_____ Create BN_CLICKED event handlers for each of the buttons in the projectNameDlg class.
_____ Use the SetWindowText function to set the title of the dialog to "Test 3 - Your Name".
_____ Make an explicit call to the OnPaint() function to redraw the dialog (See details below on the OnPaint() function.)
_____ For the "All On" button use the CBVar.SetCheck(1) to set each of the check boxes to selected.
_____ For the "All Off" button use the CBVar.SetCheck(0) to set each of the check boxes to not selected.
_____ Make an explicit call to the OnPaint() function to redraw the dialog (See details below on the OnPaint() function.)
_*****_ Get a pointer to a CDC by calling the function this->GetDC().
__****___ For each of the three check boxes. Use the GetCheck() function to see if the checkbox is selected. If so use the cdc->FillSolidRect(x, y, width, height, COLORREF) to fill a color rectangle of the currently set color in the position shown in the above image. If the checkbox is not selected color the rectangle a dark dray. (Hint: In the sample image shown above the size parameters were (150, 30, 150, 30) for the red rectangle, (150, 80, 150, 30) for the green rectangle, and (150, 130, 150, 30) for the blue rectangle. Colors can be set with Red = RGB(255, 0, 0), Green = RGB(0, 255, 0), Blue = RGB(0, 0, 255), and Dark Gray = RGB(128, 128, 128).)
In Particular I need help with the the boxes with stars inside them. Thank you
This program demonstrates the standard RGB colors for a computer display. When one of the three check boxes is clicked it changes the background color of a rectangle to the right of the check box to the appropriate color (RED, GREEN, or BLUE). If the check box is not selected the rectangle appears dark gray. Clicking the All On button sets all check boxes selected and all the rectangles colored. Clicking the All Off button sets all check boxes not selected and all the rectangles dark gray._____ Create a new project in Visual studio and call it Test_3_YourName. Make the project an MFC Application that is dialog based. (In the Advanced Features uncheck "Active X controls" and "Common Control Manifest". Also remember to right-click the project name, select Properties and set the Character Set property to "Not Set".
_____ Open the main dialog in the resource editor and add the following widgets in order to create a dialog window that looks like the one in the above image:_____ Move the OK button and change the text to "Exit".
_____ Add three check boxes with the text set respectively to "Red", "Green", and "Blue".
_____ Create BN_CLICKED event handlers for each of the check boxes in the projectNameDlg class.
_____ Add a variable to each of the check boxes with which to reference each.
_____ Add two buttons at the bottom of the dialog. Set the text on the first to "All On". Set the text on the second to "All Off".
_____ Create BN_CLICKED event handlers for each of the buttons in the projectNameDlg class.
_____ In the OnInitDialog() function of the projectNameDlg class do the following:_____ Use the SetWindowText function to set the title of the dialog to "Test 3 - Your Name".
_____ In each of the event handler functions for the three check boxes do the following:_____ Make an explicit call to the OnPaint() function to redraw the dialog (See details below on the OnPaint() function.)
_____ In the event handler functions for the two buttons do the following:_____ For the "All On" button use the CBVar.SetCheck(1) to set each of the check boxes to selected.
_____ For the "All Off" button use the CBVar.SetCheck(0) to set each of the check boxes to not selected.
_____ Make an explicit call to the OnPaint() function to redraw the dialog (See details below on the OnPaint() function.)
_____ In the onPaint function do the following:_*****_ Get a pointer to a CDC by calling the function this->GetDC().
__****___ For each of the three check boxes. Use the GetCheck() function to see if the checkbox is selected. If so use the cdc->FillSolidRect(x, y, width, height, COLORREF) to fill a color rectangle of the currently set color in the position shown in the above image. If the checkbox is not selected color the rectangle a dark dray. (Hint: In the sample image shown above the size parameters were (150, 30, 150, 30) for the red rectangle, (150, 80, 150, 30) for the green rectangle, and (150, 130, 150, 30) for the blue rectangle. Colors can be set with Red = RGB(255, 0, 0), Green = RGB(0, 255, 0), Blue = RGB(0, 0, 255), and Dark Gray = RGB(128, 128, 128).)
Test3-Sample Red Green Blue All On All Off ExitExplanation / Answer
Below file is the CTest3YourNameDlg.cpp
Rest of the files are unchanged.
We added three variables to the check boxes and in the onpaint method, we checked their state to determine the color of the rectangle.
Also in the allon and AllOff methods, we checked (unchecked) all the check boxes using the same variables.
// Test3_YourNameDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Test3_YourName.h"
#include "Test3_YourNameDlg.h"
#include "afxdialogex.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialogEx
{
public:
CAboutDlg();
// Dialog Data
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_ABOUTBOX };
#endif
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialogEx(IDD_ABOUTBOX)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()
// CTest3YourNameDlg dialog
CTest3YourNameDlg::CTest3YourNameDlg(CWnd* pParent /*=nullptr*/)
: CDialogEx(IDD_TEST3_YOURNAME_DIALOG, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTest3YourNameDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_CHECK1, CB1);
DDX_Control(pDX, IDC_CHECK2, CB2);
DDX_Control(pDX, IDC_CHECK3, CB3);
}
BEGIN_MESSAGE_MAP(CTest3YourNameDlg, CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDOK, &CTest3YourNameDlg::OnBnClickedOk)
ON_BN_CLICKED(IDC_CHECK1, &CTest3YourNameDlg::OnBnClickedCheck1)
ON_BN_CLICKED(IDC_BUTTON1, &CTest3YourNameDlg::OnBnClickedButton1)
ON_BN_CLICKED(IDC_BUTTON2, &CTest3YourNameDlg::OnBnClickedButton2)
ON_BN_CLICKED(IDC_CHECK2, &CTest3YourNameDlg::OnBnClickedCheck2)
ON_BN_CLICKED(IDC_CHECK3, &CTest3YourNameDlg::OnBnClickedCheck3)
END_MESSAGE_MAP()
// CTest3YourNameDlg message handlers
BOOL CTest3YourNameDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != nullptr)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
SetWindowText("Test3 - Your Name"); // Set window name
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CTest3YourNameDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialogEx::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CTest3YourNameDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialogEx::OnPaint();
CDC* cdc = this->GetDC(); // Get DC pointer
// Setting all the rectangles to be gray
cdc->FillSolidRect(150, 30, 150, 30, RGB(128, 128, 128));
cdc->FillSolidRect(150, 80, 150, 30, RGB(128, 128, 128));
cdc->FillSolidRect(150, 130, 150, 30, RGB(128, 128, 128));
if(CB1.GetCheck()) // If first is chhecked then set it red
cdc->FillSolidRect(150, 30, 150, 30, RGB(255,0,0));
if(CB2.GetCheck()) // If second is chhecked then set it green
cdc->FillSolidRect(150, 80, 150, 30, RGB(0, 255,0));
if (CB3.GetCheck()) // If third is chhecked then set it blue
cdc->FillSolidRect(150, 130, 150, 30, RGB(0, 0, 255));
}
}
// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CTest3YourNameDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CTest3YourNameDlg::OnBnClickedOk()
{
// TODO: Add your control notification handler code here
CDialogEx::OnOK();
}
void CTest3YourNameDlg::OnBnClickedCheck1()
{
// TODO: Add your control notification handler code here
this->OnPaint(); // Call OnPaint
}
void CTest3YourNameDlg::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here
// Set all check boxes
CB1.SetCheck(1);
CB2.SetCheck(1);
CB3.SetCheck(1);
this->OnPaint(); // Call OnPaint
}
void CTest3YourNameDlg::OnBnClickedButton2()
{
// TODO: Add your control notification handler code here
// Unset all check boxes
CB1.SetCheck(0);
CB2.SetCheck(0);
CB3.SetCheck(0);
this->OnPaint(); // Call OnPaint
}
void CTest3YourNameDlg::OnBnClickedCheck2()
{
// TODO: Add your control notification handler code here
this->OnPaint(); // Call OnPaint
}
void CTest3YourNameDlg::OnBnClickedCheck3()
{
// TODO: Add your control notification handler code here
this->OnPaint(); // Call OnPaint
}
Like if you are satisfied :)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.