#include <windows.h>
#include "typbrows.h"


BOOL CALLBACK TypeInfoDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	static LPTYPEINFO pTypeInfo ;

	switch (msg)
	{
		case WM_INITDIALOG:
		{
			pTypeInfo = (LPTYPEINFO) lParam ;
			pTypeInfo->AddRef( ) ;

			InitTypeInfo (pTypeInfo, hDlg) ;
			return TRUE ;
		}

		case WM_COMMAND:
		{
			switch (LOWORD(wParam))
			{
				case IDOK:
				case IDCANCEL:
				{
					SendMessage (hDlg, WM_CLOSE, 0,0) ;
					return TRUE ;
				}

				case IDC_LIST1:
				{
					if(HIWORD(wParam) == LBN_SELCHANGE)
					{
						SendDlgItemMessage (hDlg, IDC_LIST2, LB_RESETCONTENT, 0, 0) ;
			  			DWORD dwIndex = SendDlgItemMessage(hDlg, IDC_LIST1, LB_GETCURSEL, 0, 0L);
			  			if(dwIndex != LB_ERR)
			  			{
							SetSelectedMember(pTypeInfo, dwIndex, hDlg);
						}
					}

					return TRUE ;
				}

/*
Click on second list box, find type of selected paramter
*/
				case IDC_LIST2:
				{
					if(HIWORD(wParam) == LBN_SELCHANGE)
					{
			  			DWORD dwFuncIndex = SendDlgItemMessage(hDlg, IDC_LIST1, LB_GETCURSEL, 0, 0L);
			  			DWORD dwParamIndex = SendDlgItemMessage(hDlg, IDC_LIST2, LB_GETCURSEL, 0, 0L);
			  			
						SetSelectedParameter(pTypeInfo, dwFuncIndex, dwParamIndex, hDlg);
					}

					return TRUE ;
				}

				case IDC_DOHELP:
				{
					OLECHAR HelpFileName [128], HelpContextName [128] ; 
					long HelpContext ;
					
					GetDlgItemText (hDlg, IDC_HELPFILE, HelpFileName, sizeof(HelpFileName)) ;
					GetDlgItemText (hDlg, IDC_HELPCONTEXT, HelpContextName, sizeof(HelpContextName)) ;				
					
					HelpContext = _wtol (HelpContextName) ;
				    WinHelp (hDlg, HelpFileName, HELP_CONTEXT, HelpContext) ;
			   		return TRUE ;
				}
			}

			return TRUE ;
		}

		case WM_CLOSE:
		{
			pTypeInfo->Release ;
			DestroyWindow (hDlg) ;
			return TRUE ;
		}
	}

	return FALSE ;
}
