/****************************************************************************
   Пример программы на C-- использующей вызовы API-процедур Windows.
   Программа компилируется компилятором C-- v0.217+ с ключом /w32.
****************************************************************************/

?jumptomain NONE
#define _WINBASE_ TRUE
?include "windows.h--"
#include "dmenu.rc"

dword hInst;
dword hWnd;
dword hMenu;
struct MSG	msgStruc;
char classTitle="Menu demo";

void main()
struct WNDCLASSEX WndClassEx;
{
	hInst=GetModuleHandleA(0);
	WndClassEx.cbSize=sizeof(WndClassEx);
	WndClassEx.style=CS_HREDRAW|CS_VREDRAW;
	WndClassEx.lpfnWndProc=#WndProc;
	WndClassEx.cbWndExtra=0;
	WndClassEx.cbClsExtra=0;
	WndClassEx.hInstance=hInst;
	WndClassEx.hIcon=LoadIconA(hInst,IDI_ICON1);
	WndClassEx.hCursor=LoadCursorA(0,IDC_ARROW);
	WndClassEx.hbrBackground=COLOR_WINDOW;
	WndClassEx.lpszMenuName=MyMenu;	//если нет меню то 0
	WndClassEx.lpszClassName=#classTitle;
	WndClassEx.hIconSm=0;
	RegisterClassExA(#WndClassEx); //зарегистрируем класс окна
					// и создадим окно
	hMenu=LoadMenuA(hInst,MyMenu);
	hWnd=CreateWindowExA(WS_EX_OVERLAPPEDWINDOW,#classTitle,"Demo program",
	        WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
					CW_USEDEFAULT,0,EAX,hInst,0);
	ShowWindow(EAX,SW_SHOW); //show window
	UpdateWindow(hWnd); //redraw window
	WHILE(GetMessageA(#msgStruc,0,0,0)){
		TranslateMessage(#msgStruc);
		DispatchMessageA(#msgStruc);
	}
	ExitProcess(0);
}

void messagewin(dword inf,ttle)
{
	MessageBoxA(0,inf,ttle,MB_OK);
}

dword	WndProc(dword hwnd,msg,wPar,lPar)
{
	SWITCH(msg){
		CASE WM_COMMAND:
			SWITCH(wPar){
				CASE ID_OPEN:
					messagewin("You selected open","Open box");
					BREAK;
				CASE ID_SAVE:
					messagewin("You selected save","Save box");
					BREAK;
				default:
					SendMessageA(hwnd,WM_CLOSE,0,0);
					BREAK;
			}
			EAX=0;
			BREAK;
		CASE WM_DESTROY:
			PostQuitMessage(0);
			EAX=0;
			BREAK;
		default:
			DefWindowProcA(hwnd,msg,wPar,lPar);
	}
}
