rendered paste body///////////////////// BaseCntrl.cpp ////////////#include "BaseCntrl.h"//-------------------------------------------------------------------------------------------//DEFINITIONS OF BaseCntrl//-------------------------------------------------------------------------------------------BaseCntrl::BaseCntrl(){ //set default wnd style nStyle = WS_CHILD | WS_VISIBLE; //nullify control handle hCntrl = NULL; Width = 100; Height = 30; Top = 0; Left = 0;}BaseCntrl::~BaseCntrl(){ //release font resources back to system if necessary if (hFont) { DeleteObject(hFont); } //if the handle is still valid then destroy the control if (hCntrl) { DestroyWindow(hCntrl); }}void BaseCntrl::ModifyStyle(long lAddStyles, long lRemoveStyles){ if (hCntrl) { long lStyle = GetWindowLong(hCntrl, GWL_STYLE); lStyle |= lAddStyles; lStyle &= ~lRemoveStyles; SetWindowLong(hCntrl, GWL_STYLE, lStyle); }}HWND BaseCntrl::Create(HWND hParent){ //get the application instance from the parent if (!hInst) { hInst = reinterpret_cast<HINSTANCE>(GetWindowLong(hParent, GWL_HINSTANCE)); } //create the control by calling the base class function hCntrl = BaseWnd::Create(hParent); return hCntrl;}void BaseCntrl::SetText(const char* chText){ SetWndCaption(chText); if (hCntrl) { SetWindowText(hCntrl, chText); }}void BaseCntrl::SetText(int iText){ char chNum[10]; _itoa(iText, chNum, 10); SetWndCaption(chNum); if (hCntrl) { SetWindowText(hCntrl, chNum); }}void BaseCntrl::SetFont(const char* chFont){ if (hCntrl) { hFont = CreateFont(18, 8, 0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, chFont); SendMessage(hCntrl, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(0, 0)); }}void BaseCntrl::SetTxtColor(COLORREF crColor){ //SetTextColor(hdcEdit, crColor); //SetBkColor(hdcEdit, GetSysColor(COLOR_WINDOW));}std::string* BaseCntrl::GetText(){ char chLfCr[] = "\r\n"; char* chTxt = NULL; int nLen = static_cast<int>(SendMessage(hCntrl, WM_GETTEXTLENGTH, 0, 0)); //length of text string chTxt = new char[nLen + lstrlen(chLfCr) + 1]; //allocate memory for string //get edit control contents GetWindowText(hCntrl, chTxt, nLen + 1); return new std::string(chTxt);}void BaseCntrl::EnableWindow(bool bEnable){ ::EnableWindow(hCntrl, bEnable);}///////////////////// BaseCntrl.h ////////////#ifndef BaseCntrlH#define BaseCntrlH#include "BaseWnd.h"#include <string>//-------------------------------------------------------------------------------------------//DECLARATION OF BaseCntrl. Class Hierarchy: BaseWnd<-BaseCntrl//-------------------------------------------------------------------------------------------class BaseCntrl : public BaseWnd{private: HFONT hFont;protected: BaseCntrl(); //It's declared in the protected section because no one should virtual ~BaseCntrl(); //create a BaseControl, just subclasses of it void ModifyStyle(long lAddStyles, long lRemoveStyles);public: virtual HWND Create(HWND hParent = NULL); //wnd creation, parent handle param defaults to NULL void SetText(const char* chText); void SetText(int iText); void SetFont(const char* chFont); void SetTxtColor(COLORREF crColor); std::string* GetText(); void EnableWindow(bool bEnable); //Enables or disables the window //variables HWND hCntrl; //handle of the control};#endif