.386
.MODEL FLAT,STDCALL
OPTION CASEMAP:NONE
WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD
Include SDI.inc

.CODE
Start:
	Invoke GetModuleHandle, NULL
	MOV hInstance,EAX
	Invoke GetCommandLine
	MOV CommandLine, EAX
	Invoke WinMain, hInstance, NULL, CommandLine, SW_SHOWDEFAULT
	Invoke ExitProcess,EAX
WinMain Proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
Local wc:WNDCLASSEXW
Local msg:MSG
Local hwnd:HWND
	MOV wc.cbSize, SizeOf WNDCLASSEXW
	MOV wc.style, CS_HREDRAW or CS_VREDRAW
	MOV wc.lpfnWndProc, Offset WndProc
	MOV wc.cbClsExtra,NULL
	MOV wc.cbWndExtra,NULL
	PUSH hInst
	POP wc.hInstance
	MOV wc.hbrBackground, COLOR_WINDOW+1
	MOV wc.lpszMenuName, NULL
	MOV wc.lpszClassName, Offset ClassName
	Invoke LoadIcon, NULL, IDI_APPLICATION
	MOV wc.hIcon,EAX
	MOV wc.hIconSm,0
	Invoke LoadCursor, NULL, IDC_ARROW
	MOV wc.hCursor,EAX
	Invoke RegisterClassExW, addr wc
	.if eax==NULL
		Invoke MessageBox, NULL,ADDR szHelpAbout, Offset szAppName, MB_OK
	.endif
	Invoke LoadMenuW, hInst, Offset MenuName
	MOV hMenu,EAX
	Invoke CreateWindowExW, WS_EX_CLIENTEDGE, Offset ClassName, Offset szAppName,\
           WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,\
           CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, hMenu,\
           hInst, NULL
	MOV hwnd,EAX
	Invoke ShowWindow, hwnd, SW_SHOWNORMAL
	Invoke UpdateWindow, hwnd
	.While TRUE
		Invoke GetMessageW, ADDR msg, NULL, 0, 0
		.Break .If (!EAX)
		Invoke TranslateMessage, ADDR msg
		Invoke DispatchMessageW, ADDR msg
	.EndW
	MOV EAX, msg.wParam
	RET
WinMain endp
WndProc Proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
	.If uMsg==WM_DESTROY
		Invoke PostQuitMessage, NULL
	.ElseIf uMsg==WM_COMMAND
		MOV EAX,wParam
		.if lParam==0
			.If AX==IDM_FILE_NEW
				Invoke MessageBox, NULL, ADDR szFileNew, Offset szAppName, MB_OK
			.ElseIf AX==IDM_FILE_OPEN
				Invoke MessageBox, NULL, ADDR szFileOpen, Offset szAppName, MB_OK
			.ElseIf AX==IDM_HELP_ABOUT
				Invoke MessageBox, NULL,ADDR szHelpAbout, Offset szAppName, MB_OK
			.Else
				Invoke DestroyWindow, hWnd
			.EndIf
		.ELSE
			.IF ax==ButtonID 	;Если нажата кнопка, то
				shr eax,16		;сдвигаем EAX на 4 бита вправо, чтобы поместить в AX значение верхнего слова wParam
				.IF ax==BN_CLICKED
                       invoke sha256, addr ButtonClassName, addr ButtonText, addr ButtonText
                .ENDIF
			.EndIf
		.ENDIF	
	.ELSEIF uMsg==WM_CREATE
		invoke CreateWindowExW,NULL, Offset ButtonClassName,Offset ButtonText,\
                        WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON,\
                        75,70,140,25,hWnd,ButtonID,hInstance,NULL
		mov  hwndButton,eax 
	
	.Else
		Invoke DefWindowProc, hWnd, uMsg, wParam, lParam
		RET
	.EndIf
	XOR EAX,EAX
	RET
WndProc EndP

End Start