1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
#include <windows.h>
#include "module.h"
DLLEXPORT MODULE_IMPORT ImportTable = {
{0x00000000, NULL},
{0x00000000, NULL}
};
void FSAPI module_init(void) {}
void FSAPI module_deinit(void) {}
DLLEXPORT MODULE_LINKAGE Linkage = {
0x00000000,
module_init,
module_deinit,
0,
0,
0x0900, // FS2004 version (use 0x0800 for FS2002)
NULL
};
WNDPROC oldWndProc;
HWND hFSimWindow;
#define MENU_ENTRY "My Mo&dule"
#define ID_MY_MENUITEM 40001
LRESULT CALLBACK FSimWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg) {
case WM_NCPAINT:
{
HMENU hMenu, hMyMenu;
hMenu = GetMenu(hwnd);
if (hMenu != NULL) {
int i;
// Look for our menu entry in the main menu.
for (i = 0; i < GetMenuItemCount(hMenu); i++) {
char buf[128];
GetMenuString(hMenu, i, buf, 128, MF_BYPOSITION);
if (strcmp(buf, MENU_ENTRY) == 0) {
// It is already here, we do not need to add it again
break;
}
}
if (i < GetMenuItemCount(hMenu)) {
// It is already here, we do not need to add it again
break;
}
/* Create new menu. NOTE: It seems that this will be
* reached more times, so we cannot save the handle, because
* in such case it could be destroyed and we will not have
* any access to it in the simulator.
*/
hMyMenu = CreateMenu();
AppendMenu(hMyMenu, MF_STRING | MF_ENABLED, ID_MY_MENUITEM, "FlightRecorder");
// add the created menu to the main menu
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT_PTR)hMyMenu, MENU_ENTRY);
}
}
break;
case WM_COMMAND:
if (LOWORD(wParam) == ID_MY_MENUITEM) {
// Add your code here
MessageBox(hwnd, "It works!", "HURA", MB_OK | MB_ICONEXCLAMATION);
return 0;
}
break;
}
// Call the original window procedure to handle all other messages
return CallWindowProc(oldWndProc, hwnd, uMsg, wParam, lParam);
}
/**
* Entry point of the DLL.
*/
BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason) {
case DLL_PROCESS_ATTACH:
hFSimWindow = FindWindow("FS98MAIN", NULL);
oldWndProc = (WNDPROC)SetWindowLong(hFSimWindow, GWL_WNDPROC, (LONG)FSimWindowProc);
break;
}
return TRUE;
} |
Partager