Category : C Source Code
Archive   : ADDMENU.ZIP
Filename : ADMNUAPP.C
Output of file : ADMNUAPP.C contained in archive : ADDMENU.ZIP
This applicaion is used, with the help of ADMNULIB.DLL, to append two
menu items to the system menu of an application whose menu is invoked.
The menu items are removed when the menu is closed.
**************************************************************************/
#include "windows.h"
#include "AdMnuApp.h"
#include "AdMnuLib.h"
HANDLE hInst;
HMENU hSysMenu;
BOOL bHook = FALSE;
HWND hMainWnd;
int PASCAL WinMain (hInstance, hPrevInstance, lpCmdLine, nCmdShow)
HANDLE hInstance;
HANDLE hPrevInstance;
LPSTR lpCmdLine;
int nCmdShow;
{
MSG msg;
WNDCLASS wc;
HWND hWnd;
if (!hPrevInstance)
{
wc.style = NULL;
wc.lpfnWndProc = MainWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.hbrBackground = GetStockObject (WHITE_BRUSH);
wc.lpszMenuName = "AdMnuAppMenu";
wc.lpszClassName = "AdMnuAppWClass";
if (!RegisterClass (&wc))
return (FALSE);
}
else
{
MessageBox (NULL,
"This application is already loaded.",
"...and Menu for All",
MB_SYSTEMMODAL | MB_OK);
return (FALSE);
}
hWnd = CreateWindow ("AdMnuAppWClass",
"...and Menu for All",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
if (!hWnd)
return (FALSE);
hMainWnd = hWnd;
hSysMenu = GetSystemMenu(hWnd, FALSE);
AppendMenu(hSysMenu, MF_SEPARATOR, 0, NULL);
AppendMenu(hSysMenu, MF_STRING, IDM_START, "&Start Adding");
AppendMenu(hSysMenu, MF_STRING | MF_GRAYED, IDM_STOP, "Stop Adding");
AppendMenu(hSysMenu, MF_SEPARATOR, 0, NULL);
AppendMenu(hSysMenu, MF_STRING, IDM_ABOUT, "&About...");
DeleteMenu (hSysMenu, 4, MF_BYPOSITION);
DeleteMenu (hSysMenu, 3, MF_BYPOSITION);
DeleteMenu (hSysMenu, 2, MF_BYPOSITION);
DeleteMenu (hSysMenu, 0, MF_BYPOSITION);
ShowWindow (hWnd, SW_SHOWMINNOACTIVE);
UpdateWindow (hWnd);
hInst = hInstance;
while (GetMessage (&msg,
NULL,
NULL,
NULL))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return (msg.wParam);
} /* WinMain */
long FAR PASCAL MainWndProc (hWnd, message, wParam, lParam)
HWND hWnd;
unsigned message;
WORD wParam;
LONG lParam;
{
FARPROC lpProcAbout;
switch (message)
{
case WM_QUERYOPEN:
break;
case WM_NEWITEM:
MessageBox (GetFocus (),
"One of the new items has been selected",
"...and Menu for All",
MB_OK | MB_SYSTEMMODAL);
break;
case WM_SYSCOMMAND:
switch (wParam)
{
case IDM_START:
SetHook (hMainWnd);
bHook = TRUE;
EnableMenuItem (hSysMenu, IDM_START, MF_GRAYED);
EnableMenuItem (hSysMenu, IDM_STOP, MF_ENABLED);
break;
case IDM_STOP:
RemoveHook ();
bHook = FALSE;
EnableMenuItem (hSysMenu, IDM_STOP, MF_GRAYED);
EnableMenuItem (hSysMenu, IDM_START, MF_ENABLED);
break;
case IDM_ABOUT:
lpProcAbout = MakeProcInstance (About, hInst);
DialogBox (hInst,
"AboutBox",
hWnd,
lpProcAbout);
FreeProcInstance (lpProcAbout);
break;
default:
return (DefWindowProc (hWnd, message, wParam, lParam));
}
break;
case WM_DESTROY:
if (bHook)
RemoveHook ();
PostQuitMessage (0);
break;
default:
return (DefWindowProc (hWnd, message, wParam, lParam));
}
return (0);
} /* MainWndProc */
BOOL FAR PASCAL About (hDlg, message, wParam, lParam)
HWND hDlg;
unsigned message;
WORD wParam;
LONG lParam;
{
switch (message)
{
case WM_INITDIALOG:
return (TRUE);
case WM_COMMAND:
switch (wParam)
{
case IDOK:
case IDCANCEL:
EndDialog (hDlg, TRUE);
return (TRUE);
default:
break;
} /* switch (wParam) */
} /* switch (message) */
return (FALSE);
} /* About */
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/