Step 1: Opening the workplace
Step 2: Adding a menu item
Step 3: Adding a toolbar button
Step 4: Connect the button/menu item to a callback function
Step 5: Writing the function
Step 6: Compile and run
Step 7: Extra features
CWinThread* startNewThread(AFX_THREADPROC pfnThreadProc, LPVOID pParam);
UINT funcName (LPVOID param);
typedef struct Params { char* filename; Color bgcolor; } Params;
void CMeshMakerView::OnMyTutorial() { // initialize the parameters Params* params = new Params; params->filename = strdup("vrml\\demo.wrl"); params->bgcolor.setColor(1.0, 0.0, 0.0); // start the new thread startNewThread(myCode, params); }
UINT myCode (LPVOID param) {
Params *params = (Params*)param;
mesh->openVRMLFile(params->filename);
renderer->setBgColor(params->bgcolor);
renderer->refreshScreen ();
return 0;
}
butState = false;
void CMeshMakerView::OnMyTutorial() { // initialize the parameters Params* params = new Params; if (butState) { params->filename = NULL; params->bgcolor.setColor(1.0, 1.0, 1.0); } else { params->filename = strdup("vrml\\demo.wrl"); params->bgcolor.setColor(1.0, 0.0, 0.0); } butState = ! butState; // start the new thread startNewThread(myCode, params); }
UINT myCode (LPVOID param) {
Params *params = (Params*)param;
if (params->filename) {
mesh->openVRMLFile(params->filename);
LinkedList<Face>* faces = new LinkedList<Face>(); // a list of the new faces to be created
VertexID faceVertices[] = {0, 1, 3};
Face face(faceVertices);
faces->push_back(face);
faceVertices[0] = 3; faceVertices[1] = 1; faceVertices[2] = 2;
face.set(faceVertices);
faces->push_back(face);
LinkedList<FaceID> *newFaces = new LinkedList<FaceID>();
mesh->removeVertexTriangulate(12, faces, newFaces);
}
else {
renderer->setAutoScale();
mesh->startNewModel();
VertexID vid1, vid2, vid3, vid4;
Coord c1(0.0, 0.0, 0.0), c2(-1.5, 0.5, -1.0), c3(0.0, 2.0, 0.0), c4(2.0, 1.0, -2.0);
mesh->addVertex(c1, vid1);
mesh->addVertex(c2, vid2);
mesh->addVertex(c3, vid3);
mesh->addVertex(c4, vid4);
VertexID faceVertices1[] = {vid1, vid2, vid3};
VertexID faceVertices2[] = {vid1, vid3, vid4};
Face face1(faceVertices1);
Face face2(faceVertices2);
FaceID fid1, fid2;
mesh->addFace(face1, fid1);
mesh->addFace(face2, fid2);
}
renderer->setBgColor(params->bgcolor);
renderer->refreshScreen();
return 0;
}
void CMeshMakerView::OnUpdateMyTutorial(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(butState);
pCmdUI->Enable();
}