#pragma option w32
#pragma option wmb-

#include "windows.h--"
#include "commctrl.h--"

#include "controls.rc"

byte ClassName="SimpleWinClass";
byte AppName="Our First Window";
byte MenuName="FirstMenu";
byte ButtonClassName="button";
byte ButtonText="My First Button";
byte EditClassName="edit";
byte TestString="Wow! I'm in an edit box now";

HWND hwndButton;
HWND hwndEdit;
byte buffer[512];

#define ButtonID 1
#define EditID 2

int main()
{
WNDCLASSEX wc;
MSG	msg;
HWND hwnd;
	InitCommonControls();
	wc.cbSize=sizeof(WNDCLASSEX);
	wc.style=CS_HREDRAW|CS_VREDRAW;
	wc.lpfnWndProc=#WndProc;
	wc.cbClsExtra=wc.cbWndExtra=NULL;
	wc.hInstance=hThisInst;
	wc.hbrBackground=COLOR_BTNFACE+1;
	wc.lpszMenuName=#MenuName;
	wc.lpszClassName=#ClassName;
	wc.hIcon=wc.hIconSm=LoadIcon(NULL,IDI_APPLICATION);
	wc.hCursor=LoadCursor(NULL,IDC_ARROW);
	RegisterClassEx(#wc);
	hwnd=CreateWindowEx(WS_EX_CLIENTEDGE,#ClassName,#AppName,
           WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,
           CW_USEDEFAULT,300,200,NULL,NULL,
           hThisInst,NULL);
	ShowWindow(hwnd,SW_SHOWNORMAL);
	UpdateWindow(hwnd);
	WHILE(GetMessage(#msg,NULL,0,0)){
                TranslateMessage(#msg);
                DispatchMessage(#msg);
	}
	return msg.wParam;
}

dword WndProc(dword hWnd,uMsg,wParam,lParam)
{
	switch(uMsg){
		CASE WM_DESTROY:
			PostQuitMessage(0);
			EAX=0;
			break;
		CASE WM_CREATE:
			hwndEdit=CreateWindowEx(WS_EX_CLIENTEDGE,#EditClassName,NULL,
                        WS_CHILD|WS_VISIBLE|WS_BORDER|ES_LEFT|ES_AUTOHSCROLL,
                        50,35,200,25,hWnd,EditID,hThisInst,NULL);
			SetFocus(hwndEdit);
			hwndButton=CreateWindowEx(NULL,#ButtonClassName,#ButtonText,
                        WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,
                        75,70,140,25,hWnd,ButtonID,hThisInst,NULL);
			break;
		case WM_COMMAND:
			EAX=wParam;
			if(lParam==0){
				SWITCH(AX){
					CASE IDM_HELLO:
						SetWindowText(hwndEdit,#TestString);
						SendMessage(hwndEdit,WM_KEYDOWN,VK_END,NULL);
						BREAK;
					CASE IDM_CLEAR:
						SetWindowText(hwndEdit,NULL);
						BREAK;
					CASE IDM_GETTEXT:
						GetWindowText(hwndEdit,#buffer,512);
						MessageBox(NULL,#buffer,#AppName,MB_OK);
						BREAK;
					default: DestroyWindow(hWnd);
				}
			}
			ELSE{
				IF(AX==ButtonID){
					EAX>>=16;
					IF(AX==BN_CLICKED)
						SendMessage(hWnd,WM_COMMAND,IDM_GETTEXT,0);
				}
			}
			BREAK;
		default:
			DefWindowProc(hWnd,uMsg,wParam,lParam);
	}
}
