La géométrie s'est également s'amuser à faire des dessins à l'apparence mathématique. Un des classiques dans ce genre, c'est bien sûre dessiner un «Treillis». Voici le code Visual C++ selon une configuration de MFC AppWizard, Simple Document, Multiprocessus léger (Multithread):
#include "afxwin.h"
#include "afxext.h"
#include "afxdtctl.h"
#include "afxcmn.h"
#define IDR_MAINFRAME 128
class CTrellisApp: public CWinApp {
public:
virtual BOOL InitInstance();
};
class CTrellisDoc: public CDocument {
protected:
DECLARE_DYNCREATE(CTrellisDoc)
public:
virtual BOOL OnNewDocument();
};
class CTrellisView: public CView {
protected:
DECLARE_DYNCREATE(CTrellisView)
public:
virtual void OnDraw(CDC* pDC);
};
IMPLEMENT_DYNCREATE(CTrellisDoc, CDocument)
BOOL CTrellisDoc::OnNewDocument() {
if(!CDocument::OnNewDocument()) return FALSE;
return TRUE;
}
IMPLEMENT_DYNCREATE(CTrellisView, CView)
void CTrellisView::OnDraw(CDC* pDC) {
int x=30, y=40, t=240, i;
for (i=0; i<=t; i+=5) {
pDC->MoveTo(x, y+i);
pDC->LineTo(x+i, y+t);
}
}
CTrellisApp theApp;
BOOL CTrellisApp::InitInstance() {
CSingleDocTemplate* pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CTrellisDoc),
RUNTIME_CLASS(CFrameWnd),
RUNTIME_CLASS(CTrellisView));
AddDocTemplate(pDocTemplate);
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
if (!ProcessShellCommand(cmdInfo)) return FALSE;
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
return TRUE;
}
Et le fichier de ressource malheureusement indispensable au démarrage du «Samples»:
#define IDR_MAINFRAME 128
#define APSTUDIO_READONLY_SYMBOLS
#include "afxres.h"
#undef APSTUDIO_READONLY_SYMBOLS
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_FRA)
#ifdef _WIN32
LANGUAGE LANG_FRENCH, SUBLANG_FRENCH
#pragma code_page(1252)
#endif //_WIN32
#ifndef _MAC
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,1
PRODUCTVERSION 1,0,0,1
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040c04b0"
BEGIN
VALUE "Comments", "\0"
VALUE "CompanyName", "Gladir\0"
VALUE "FileDescription", "Application MFC Trellis\0"
VALUE "FileVersion", "1, 0, 0, 1\0"
VALUE "InternalName", "Trellis\0"
VALUE "LegalCopyright", "\0"
VALUE "LegalTrademarks", "\0"
VALUE "OriginalFilename", "Trellis.EXE\0"
VALUE "PrivateBuild", "\0"
VALUE "ProductName", "Samples Trellis\0"
VALUE "ProductVersion", "1, 0, 0, 1\0"
VALUE "SpecialBuild", "\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x40c, 1200
END
END
#endif
IDR_MAINFRAME MENU PRELOAD DISCARDABLE
BEGIN
POPUP "&Fichier"
BEGIN
MENUITEM "&Quitter", ID_APP_EXIT
END
END
#endif
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_FRC)
#ifdef _WIN32
LANGUAGE LANG_FRENCH, SUBLANG_FRENCH_CANADIAN
#pragma code_page(1252)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
1 TEXTINCLUDE DISCARDABLE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#define _AFX_NO_SPLITTER_RESOURCES\r\n"
"#define _AFX_NO_OLE_RESOURCES\r\n"
"#define _AFX_NO_TRACKER_RESOURCES\r\n"
"#define _AFX_NO_PROPERTY_RESOURCES\r\n"
"\r\n"
"#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_FRA)\r\n"
"#ifdef _WIN32\r\n"
"LANGUAGE 12, 1\r\n"
"#pragma code_page(1252)\r\n"
"#endif //_WIN32\r\n"
"#include ""l.fra\\afxres.rc"" // Standard components\r\n"
"#endif\r\n"
"\0"
END
#endif
#endif
#ifndef APSTUDIO_INVOKED
#define _AFX_NO_SPLITTER_RESOURCES
#define _AFX_NO_OLE_RESOURCES
#define _AFX_NO_TRACKER_RESOURCES
#define _AFX_NO_PROPERTY_RESOURCES
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_FRA)
#ifdef _WIN32
LANGUAGE 12, 1
#pragma code_page(1252)
#endif //_WIN32
#include "l.fra\afxres.rc"
#endif
#endif
Voici en terminant un exemple du résultat de se petit programme:
N.B.: Il ne s'agit bien sûr que d'un exemple rapide, car il est très loin d'être certains qu'il s'agit de la meilleure méthode puisque le fichier exécutable prendre 1,3 Mo.
Dernière mise à jour : Samedi, le 7 avril 2018