PerMalmberg/libcron

Could I get some help with using the library with MFC?

Closed this issue · 1 comments

Hello. I've been using only script languages and I'm pretty new to C++.

I want to make an MFC program on Visual Studio 2017, which repeatedly adds a string to a list box.

I could build libcron.lib, import header files and compile the program without an error, but the scheduler doesn't work as I expected. Am I missing anything or misunderstanding how to use the library?

// MFCApplication3Dlg.cpp
#include "pch.h"
#include "framework.h"
#include "MFCApplication3.h"
#include "MFCApplication3Dlg.h"
#include "afxdialogex.h"

#include <chrono>
#include <libcron/Cron.h>


#ifdef _DEBUG
#define new DEBUG_NEW
#endif

using namespace libcron;
using namespace std::chrono;
using namespace date;

Cron<> c;
BOOL CMFCApplication3Dlg::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

	// TODO: Add extra initialization here

	myList.AddString(_T("TEST0"));

	c.add_schedule("A task", "* * * * * ?", [&](auto&) {
		myList.AddString(_T("TEST1"));
		//expired = true;
	});

	return TRUE;  // return TRUE  unless you set the focus to a control
}

MFCApplication3.zip

I've attached the whole project. I'm sorry if it's way too basic. Any advice is welcome!

Thank you for developing the great library.

Have a look at the tests, they show it is used in addition to the readme-file. I've not opened your solution, but the usual thing people miss that tick() must be called regularly.