// GridDialogExDlg.cpp // // (c)1998-2025 Codejock Software, All Rights Reserved. // // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN // CONSENT OF CODEJOCK SOFTWARE. // // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A // SINGLE COMPUTER. // // CONTACT INFORMATION: // support@codejock.com // http://www.codejock.com // ///////////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "GridDialogEx.h" #include "GridDialogExDlg.h" #include "MessageRecord.h" #ifdef _DEBUG # define new DEBUG_NEW # undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif const UINT_PTR CGridDialogExDlg::m_nAddRecordsTimerId = 0x112233; const int CGridDialogExDlg::m_nMaxRecords = 100; ///////////////////////////////////////////////////////////////////////////// // CGridDialogExDlg dialog CGridDialogExDlg::CGridDialogExDlg(CWnd* pParent /*=NULL*/) : CXTPResizeDialog(CGridDialogExDlg::IDD, pParent) , m_nRecordCounter(0) { //{{AFX_DATA_INIT(CGridDialogExDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CGridDialogExDlg::DoDataExchange(CDataExchange* pDX) { CXTPResizeDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CGridDialogExDlg) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CGridDialogExDlg, CXTPResizeDialog) //{{AFX_MSG_MAP(CGridDialogExDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_WM_DESTROY() ON_BN_CLICKED(IDC_ADD_RECORDS_BUTTON, OnAddRecordsButton) ON_WM_TIMER() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CGridDialogExDlg message handlers BOOL CGridDialogExDlg::OnInitDialog() { CXTPResizeDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. _ASSERTE((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); _ASSERTE(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // Set the default font for all dialog controls. SendMessageToDescendants(WM_SETFONT, (WPARAM)(HFONT)XTPFontManager()->GetFont()); // 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 // subclass the Grid control m_wndGridCtrl.SubclassDlgItem(IDC_GRIDCTRL, this); // add sample columns for (int i = 0; i < 4; i++) { CString strName; strName.Format(_T("Column %d"), i + 1); m_wndGridCtrl.AddColumn(new CXTPGridColumn(i, strName, 280)); } // set the first column as a group column m_wndGridCtrl.ShowGroupBy(); m_wndGridCtrl.GetColumns()->GetGroupsOrder()->Add(m_wndGridCtrl.GetColumns()->GetAt(0)); // add empty header row m_wndGridCtrl.GetHeaderRecords()->Add(new CMessageRecord()); m_wndGridCtrl.ShowHeaderRows(); m_wndGridCtrl.HeaderRowsAllowEdit(TRUE); m_wndGridCtrl.PopulateHeaderRows(); m_wndGridCtrl.GetPaintManager()->SetHeaderRowsDividerStyle(xtpGridFixedRowsDividerOutlook); // define style attributes for the Grid control m_wndGridCtrl.FocusSubItems(TRUE); m_wndGridCtrl.AllowEdit(TRUE); #ifdef _XTP_INCLUDE_CONTROLS // Set control resizing. SetResize(IDC_GRIDCTRL, XTP_ANCHOR_TOPLEFT, XTP_ANCHOR_BOTTOMRIGHT); SetResize(IDOK, XTP_ANCHOR_BOTTOMRIGHT, XTP_ANCHOR_BOTTOMRIGHT); SetResize(IDC_ADD_RECORDS_BUTTON, XTP_ANCHOR_BOTTOMRIGHT, XTP_ANCHOR_BOTTOMRIGHT); // Load window placement LoadPlacement(_T("CGridDialogExDlg")); #endif return TRUE; // return TRUE unless you set the focus to a control } void CGridDialogExDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CXTPResizeDialog::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 CGridDialogExDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (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 { CXTPResizeDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CGridDialogExDlg::OnQueryDragIcon() { return (HCURSOR)m_hIcon; } void CGridDialogExDlg::OnDestroy() { if (0 != m_nRecordCounter) KillTimer(m_nAddRecordsTimerId); // WaitForAddRecordsThread(); CXTPResizeDialog::OnDestroy(); #ifdef _XTP_INCLUDE_CONTROLS // Save window placement SavePlacement(_T("CGridDialogExDlg")); #endif } void CGridDialogExDlg::OnAddRecordsButton() { GetDlgItem(IDC_ADD_RECORDS_BUTTON)->EnableWindow(FALSE); SetTimer(m_nAddRecordsTimerId, 100, NULL); } void CGridDialogExDlg::OnTimer(UINT_PTR nID) { _ASSERTE(m_nAddRecordsTimerId == nID); if (m_nRecordCounter++ < m_nMaxRecords) { CString strItem[4]; for (int j = 0; j < 4; j++) strItem[j].Format(_T("Row - %d, Col - %d"), m_nRecordCounter, j + 1); CMessageRecord* pRecord = new CMessageRecord(strItem[0], strItem[1], strItem[2], strItem[3]); // WPARAM = pointer to a grid record // LPARAM: // LOWORD = record number // HIWORD = records count to add if (NULL != pRecord) { m_wndGridCtrl.SendMessage(WM_ADD_RECORD_EX, (WPARAM)pRecord, MAKELPARAM(m_nRecordCounter, m_nMaxRecords)); m_wndGridCtrl.AdjustScrollBars(); CString strCaption; strCaption.Format(_T("Grid Sample for AddRecordEx [%d of %d]"), m_nRecordCounter, m_nMaxRecords); SetWindowText(strCaption); } } else { GetDlgItem(IDC_ADD_RECORDS_BUTTON)->EnableWindow(); m_wndGridCtrl.AdjustScrollBars(); KillTimer(m_nAddRecordsTimerId); m_nRecordCounter = 0; } } BOOL CGridDialogExDlg::PreTranslateMessage(MSG* pMsg) { if (pMsg->message == WM_KEYDOWN && (pMsg->wParam == VK_ESCAPE || pMsg->wParam == VK_RETURN || pMsg->wParam == VK_TAB)) return FALSE; return CXTPResizeDialog::PreTranslateMessage(pMsg); }