Project Very simple MFD

george7378

DON'T PANIC
Addon Developer
Donator
Joined
Jun 26, 2009
Messages
1,045
Reaction score
0
Points
36
Hi all,

I am trying out C++ by making an MFD.

I want to know how to create the equivalent of a 'Hello World' MFD, i.e - one which just displays some pre-defined text, or maybe an image or similar file.

I am familiarising myself with the layout of MFD C++ files, and was wondering - could you give me an example of the bare minimum code to make such a simple project?

Thanks.
 
I think you might be better starting with a simple vessel, last I checked the MFD's don't really have any good example code / tutorials, though I might be wrong.
 
I found this in my Orbiter SDK:

Code:
// ==============================================================
//                 ORBITER MODULE: DialogTemplate
//                  Part of the ORBITER SDK
//            Copyright (C) 2003 Martin Schweiger
//                   All rights reserved
//
// MFDTemplate.cpp
//
// This module demonstrates how to build an Orbiter plugin which
// inserts a new MFD (multi-functional display) mode. The code
// is not very useful in itself, but it can be used as a starting
// point for your own MFD developments.
// ==============================================================

#define STRICT
#define ORBITER_MODULE
#include "windows.h"
#include "orbitersdk.h"
#include "MFDTemplate.h"

// ==============================================================
// Global variables

int g_MFDmode; // identifier for new MFD mode

// ==============================================================
// API interface

DLLCLBK void opcDLLInit (HINSTANCE hDLL)
{
    static char *name = "MFD Template";   // MFD mode name
    MFDMODESPEC spec;
    spec.name = name;
    spec.key = OAPI_KEY_T;                // MFD mode selection key
    spec.msgproc = MFDTemplate::MsgProc;  // MFD mode callback function

    // Register the new MFD mode with Orbiter
    g_MFDmode = oapiRegisterMFDMode (spec);
}

DLLCLBK void opcDLLExit (HINSTANCE hDLL)
{
    // Unregister the custom MFD mode when the module is unloaded
    oapiUnregisterMFDMode (g_MFDmode);
}

// ==============================================================
// MFD class implementation

// Constructor
MFDTemplate::MFDTemplate (DWORD w, DWORD h, VESSEL *vessel)
: MFD (w, h, vessel)
{
    // Add MFD initialisation here
}

// Destructor
MFDTemplate::~MFDTemplate ()
{
    // Add MFD cleanup code here
}

// Return button labels
char *MFDTemplate::ButtonLabel (int bt)
{
    // The labels for the two buttons used by our MFD mode
    static char *label[2] = {"UP", "DN"};
    return (bt < 2 ? label[bt] : 0);
}

// Return button menus
int MFDTemplate::ButtonMenu (const MFDBUTTONMENU **menu) const
{
    // The menu descriptions for the two buttons
    static const MFDBUTTONMENU mnu[2] = {
        {"Move up", 0, '['},
        {"Move down", 0, ']'}
    };
    if (menu) *menu = mnu;
    return 2; // return the number of buttons used
}


// Repaint the MFD
void MFDTemplate::Update (HDC hDC)
{
    Title (hDC, "MFD Template");
    // Draws the MFD title

    // Add MFD display routines here.
    // Use the device context (hDC) for Windows GDI paint functions.
}

// MFD message parser
int MFDTemplate::MsgProc (UINT msg, UINT mfd, WPARAM wparam, LPARAM lparam)
{
    switch (msg) {
    case OAPI_MSG_MFD_OPENED:
        // Our new MFD mode has been selected, so we create the MFD and
        // return a pointer to it.
        return (int)(new MFDTemplate (LOWORD(wparam), HIWORD(wparam), (VESSEL*)lparam));
    }
    return 0;
}
 
I think you might be better starting with a simple vessel, last I checked the MFD's don't really have any good example code / tutorials, though I might be wrong.


Sample; (inside your orbiter SDK)

\orbiter060929_base\Orbitersdk\samples\CustomMFD

Not sure about any tutorial though,
 
I was thinking of ending up with something simple to allow you to flick through images or pieces of text in a certain folder, or maybe stream a video file from the net, like NASA TV's constant broadcast.

Maybe if someone could fill out that template I put above so that it displays some text, or maybe allows you to display images or something, if that isn't too complicated in coding.
 
Maybe if someone could fill out that template I put above so that it displays some text, or maybe allows you to display images or something, if that isn't too complicated in coding.
What you describe is not quite simple for someone who have no idea how simple or complex it is.
Do you have any programming experience at all?
The best gain for you would be if you try to get that done yourself, and only ask for guidance after total failure, if there will be one.
 
write hello word in c++ first, then write notepad in c++ and then try your hand at mfd's, it's how i learned java (or rather failed to learn java since i did not enjoy the language)
 
I have the free version of VC++ 2008, and am trying to get a simple .exe to be created. When I enter some C++ code and press build, it doesn't seem to create an exe file. How do I get one?
 
I really recommend you find a good book / tutorial and read it, then come here with questions about stuff you can't figure out your self.
 
I have read a tutorial and I have put some code into VC++ 2008. I have pressed build --> build solution and in the output folder, there is no .exe. How do I create one?
 
You have to setup an appropriate type of project in New. You want Win32 -> Win32 Console Application for this one.
 
I have read a tutorial and I have put some code into VC++ 2008. I have pressed build --> build solution and in the output folder, there is no .exe. How do I create one?

Most probably because of the simple reason that your code cannot compile. I'll try to help you a bit out here:

when you build, there's a build log created. It is usually shown in the lower region of your screen, if you didn't change your UI.

There, at the end it will probably say "X errors found". brows a bit through the build log to find said errors, and correct them. If there are no errors left anymore, your build log will show "0 errors, 1 succeeded" which means that VS could finally make sense of what you wrote and was able to compile it then, and ONLY then, will an exe file be created.

As for how to ask questions about a programming problem, ALWAYS post the relevant messages from you build log and AT LEAST the code it refers to. Better post all the code that could have anything to do with it.

However, this here isn't a C++ forum. I suggest you go to a forum like e.g. codecomments.com, get yourself some tutorials on how to get started with Visual studio, and once you get the hang of it and start to code stuff for orbiter you return here with the problems that are specific to the Orbiter SDK and API. I hope I don't give you the impression of being unfriendly. I'm merely giving you this advice because if you go on posting your questions like above, people will get annoyed and sooner or later unfriendly.
 
Most probably because of the simple reason that your code cannot compile.

Pah... so obvious that I didn't even consider that, which means that we do have to learn a little more before writing Orbiter addons, don't we? :)

I'm merely giving you this advice because if you go on posting your questions like above, people will get annoyed and sooner or later unfriendly.

I second that.
 
Well, I managed to create a speed/distance/time calculator with C++:

Calc1.png


I hope to get onto MFDs later.

I will ask more Qs about C++ as a whole on another forum.
 
Thanks! I'll probably learn a bit more about visual styles next, rather than command prompt.
 
Make sure that you understand everything in the console first. I know that girls won't say that it's sexy, but a lot of GUI toolkits are Object Oriented and it's much easier to understand how to use them once you get inheritance, polymorphism, and the whole treasury of OOP.

I started coding when I was much older than you are now (although still a student, on re-sitting :P), and I was able to do sophisticated things in a matter of just few years and now I even make a (good) living thanks to this. The conclusion is: you don't have to make haste. Take your time and mostly - enjoy your coding by not making any deadlines to yourself. Leave it to your further boss :)
Also, remember that if you write insecure, crashy, and memory leaky addons, you take some informal responsibility for what goes wrong with your users' computers. Another reason to first fully understand coding before publishing, in particular dynamic memory (responsible for memory leaks) and pointers (for crashes).
 
Last edited:
Hi george7378,

look at this i think this is what you are planning to create:

[ame="http://www.orbithangar.com/searchid.php?ID=1407"]BurnTimeCalcMFD (BTC) 1.5[/ame].

sources are included, so you can look how it works :tiphat:
 
Back
Top