Esempio n. 1
0
DWORD
main(
    int argc,
    char *argv[],
    char *envp[]
    )
{
    int i;
    HANDLE hMod,x;
    CHAR Buff[256];
    PCHAR s;
    FARPROC f;
    DWORD Version;
    HANDLE Handle;
    DWORD  rc;
    STARTUPINFO StartupInfo;


    GetStartupInfo(&StartupInfo);
    printf("Title %s\n",StartupInfo.lpTitle);


    printf( "TBASE: Entering Test Program\n" );

    assert(GetModuleFileName(0,Buff,256) < 255);
    printf("Image Name %s\n",Buff);
#if 0
    printf( "argc: %ld\n", argc );
    for (i=0; i<argc; i++) {
        printf( "argv[ %3ld ]: '%s'\n", i, argv[ i ] );
        }

    for (i=0; envp[ i ]; i++) {
        printf( "envp[ %3ld ]: %s\n", i, envp[ i ] );
        }

    DbgBreakPoint();

    s = "ync ""Yes or No""";
    printf( "Invoking: '%s'\nResult: %d\n", s, system(s) );

    TestEnvironment();
    for (i=1; i<=256; i++) {
        rc = FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY,
                            NULL,
                            i, NULL, sizeof( Buff ), (va_list *)Inserts );
        if (rc != 0) {
            rc = FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY, NULL,
                                i, Buff, rc, (va_list *)Inserts );
            if (rc != 0) {
                cprintf( "SYS%05u: %s\r\n", i, Buff );
                }
            }
        }

    Handle = CreateFile( "\\config.sys",
                         GENERIC_READ,
                         FILE_SHARE_READ | FILE_SHARE_WRITE,
                         NULL,
                         OPEN_EXISTING,
                         0,
                         NULL
                       );
    if (Handle != INVALID_HANDLE_VALUE) {
        printf( "CreateFile successful, handle = %lX\n", Handle );
        }
    else {
        printf( "CreateFile failed\n" );
        }

    rc = SetFilePointer(Handle, 0, NULL, FILE_END);
    if (rc != -1) {
        printf( "File size = %ld\n", rc );
        }
    else {
        printf( "SetFilePointer failed\n" );
        }

    Version = GetVersion();
    assert( (Version & 0x0000ffff) == 4);
    assert( (Version >> 16) == 0);
#endif
    hMod = LoadLibrary("dbgdll");
    assert(hMod);
    assert(hMod == GetModuleHandle("dbgdll"));

    hMod = LoadLibrary("c:\\nt\\dll\\csr.dll");
    assert(hMod);

    assert(GetModuleFileName(hMod,Buff,256) == strlen("c:\\nt\\dll\\csr.dll")+1);
    assert(_strcmpi(Buff,"c:\\nt\\dll\\csr.dll") == 0 );

    hMod = LoadLibrary("nt\\dll\\csrrtl.dll");
    assert(hMod);

    x = LoadLibrary("csrrtl");
    assert( x && x == hMod);
    assert(FreeLibrary(x));
    assert(FreeLibrary(x));
    hMod = GetModuleHandle("csrrtl");
    assert(hMod == NULL);
    x = LoadLibrary("csrrtl");
    assert( x );
    assert(FreeLibrary(x));

    hMod = LoadLibrary("kernel32");
    assert(hMod);

    f = GetProcAddress(hMod,"GetProcAddress");
    assert(f);
    assert(f == (f)(hMod,"GetProcAddress"));
    assert(f == MakeProcInstance(f,hMod));
    FreeProcInstance(f);
    DebugBreak();
    assert(FreeLibrary(hMod));

//    hMod = LoadLibrary("baddll");
//    assert(!hMod);

    printf( "TBASE: Exiting Test Program\n" );

    return 0;
}
Esempio n. 2
0
void DoFontDetails(HWND hwnd,
                         TCHAR *str, size_t SizeofStr,
                         TCHAR *title, size_t SizeofTitle)
{	
	int        index;
	HWND       hwndChild;
	HCOMPONENT hFontHandle;
	DWORD      dwSize, dwResult;
	HCURSOR    hOldCursor;
#ifndef WIN32
	FARPROC    lpfnDlgProc;
#endif

	if (!(hwndChild = GetDlgItem(hwnd, IDC_FONTLIST)))
	{
		return;
	}

	if ((index = ListBox_GetCurSel(hwndChild)) == LB_ERR)
	{
		return;
	}

  	if (!(hFontHandle =
	     (HCOMPONENT)ListBox_GetItemData(hwndChild, index)))
	{
		return;
	}

	lpPeriphFontInfo = (PeripheralFontInfo *)
	                   HP_GLOBAL_ALLOC_DLL(sizeof(PeripheralFontInfo));
	if (lpPeriphFontInfo IS NULL)
	{
		return;
	}
	dwSize = sizeof(PeripheralFontInfo);

	// From here on out we must dispose of lpPeriphFontInfo.

	// Give 'em the hour glass
	hOldCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
	dwResult = PALGetComponentObject(hPeripheral,
	                                 hFontHandle,
	                                 OT_PERIPHERAL_FONT_INFO, 0,
	                                 lpPeriphFontInfo,
	                                 &dwSize);
	// Back to previous cursor
	SetCursor(hOldCursor);

	if (dwResult IS RC_BAD_HANDLE)
	{
		enum RetryStati RetryStatus;
		int  oldIndex = index;

		// Bad handle...enumerate again.

		RetryStatus = RetryAndSelectString(hwndChild,
		                                   &index,
						   &hFontHandle);

		if (RetryStatus IS RetrySuccess)
		{

			// Give 'em the hour glass
			hOldCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
			dwResult = PALGetComponentObject(hPeripheral,
			                          hFontHandle,
			                          OT_PERIPHERAL_FONT_INFO,
			                          0,
			                          lpPeriphFontInfo,
			                          &dwSize);
			// Back to previous cursor
			SetCursor(hOldCursor);
		}
		else // not found or some other failure
		{
			index = oldIndex;

			// if the listbox is now empty, disable both buttons
			// index is set where the selected font was and
			// WARNING WARNING it may be out of bounds!

			SelectNextBest(hwndChild, index);
			dwResult = RC_FAILURE;
			// Don't put up the details sheet.

		} // not found or some other failure
	} // if (dwResult IS RC_BAD_HANDLE)

	if (dwResult ISNT RC_SUCCESS)
	{
		HP_GLOBAL_FREE(lpPeriphFontInfo);
		lpPeriphFontInfo = NULL;
		LoadString(hInstance, IDS_FONT_INFO_FAILED, str, SizeofStr);
		LoadString(hInstance, IDS_PRTR_TITLE, title, SizeofTitle);
		MessageBox(GetParent(hDisk), str, title, MB_OK);
		return;
	}

#ifdef WIN32
  	DialogBox(hInstance, MAKEINTRESOURCE(IDD_FONT_DETAILS), hwnd,
	          (DLGPROC)FontDetailsProc);
#else
	hFontDialog = GetWindowFont(GetFirstChild(hwnd));
	lpfnDlgProc = MakeProcInstance((FARPROC)FontDetailsProc, hInstance);
	EnableWindow(GetParent(hwnd), FALSE);
  	DialogBox(hInstance, MAKEINTRESOURCE(IDD_FONT_DETAILS), hwnd,
	          (DLGPROC)lpfnDlgProc);
	EnableWindow(GetParent(hwnd), TRUE);
  	FreeProcInstance(lpfnDlgProc);
  	SetActiveWindow(GetParent(hwnd));
#endif		  	
	HP_GLOBAL_FREE(lpPeriphFontInfo);
	lpPeriphFontInfo = NULL;
} // DoFontDetails
Esempio n. 3
0
static void fillInfoBoxes( HWND hwnd )
{
    FONTENUMPROC    lpEnumFam;
    int             index;
    HDC             hdc;
    char            typeface[LF_FACESIZE + 1];
    char            size[8];
    long            isTrueType = 0;
    char            oldSize[8], oldStyle[40];
    static int      vPitchSizes[] = { 8, 9, 10, 11, 12, 14, 16, 18,
                                      20, 22, 24, 26, 28, 36, 48, 72 };

    hwnd = hwnd;

    index = SendMessage( hwndStyle, LB_GETCURSEL, 0, 0L );
    if( index != LB_ERR ) {
        SendMessage( hwndStyle, LB_GETTEXT, index, (LONG)oldStyle );
    } else {
        oldStyle[0] = 0;
    }
    index = SendMessage( hwndSize, CB_GETCURSEL, 0, 0L );
    if( index != CB_ERR ) {
        SendMessage( hwndSize, CB_GETLBTEXT, index, (LONG)oldSize );
    } else {
        oldSize[0] = 0;
    }

    SendMessage( hwndStyle, LB_RESETCONTENT, 0, 0L );
    SendMessage( hwndSize, CB_RESETCONTENT, 0, 0L );
    NStyles = NSizes = 0;

    index = SendMessage( hwndTypeface, LB_GETCURSEL, 0, 0L );
    if( index == LB_ERR ) {
        return;
    }

    fillStyleBox();

    SendMessage( hwndTypeface, LB_GETTEXT, index, (LONG)typeface );
    lpEnumFam = (FONTENUMPROC) MakeProcInstance( (FARPROC) EnumFamInfo, InstanceHandle );
    hdc = GetDC( EditContainer );
    EnumFontFamilies( hdc, typeface, lpEnumFam, (LONG)(&isTrueType) );
    ReleaseDC( EditContainer, hdc );
    FreeProcInstance( (FARPROC) lpEnumFam );

    if( isTrueType ) {
        /* suggest a few truetype point values
        */
        int nelements = sizeof( vPitchSizes ) / sizeof( vPitchSizes [0] );
        if( NSizes ) {
            SendMessage( hwndSize, CB_RESETCONTENT, 0, 0L );
            NSizes = 0;
        }
        for( index = 0; index < nelements; index++ ) {
            sprintf( size, "%d", vPitchSizes[index] );
            if( SendMessage( hwndSize, CB_FINDSTRINGEXACT, -1, (LONG)size ) == CB_ERR ) {
                SendMessage( hwndSize, CB_INSERTSTRING, NSizes, (LONG)size );
                NSizes++;
            }
        }
    }

    if( oldStyle[0] ) {
        index = SendMessage( hwndStyle, LB_SELECTSTRING, -1, (LONG)oldStyle );
        if( index == LB_ERR ) {
            SendMessage( hwndStyle, LB_SETCURSEL, 0, 0L );
        }
    }
    if( oldSize[0] ) {
        index = SendMessage( hwndSize, CB_SELECTSTRING, -1, (LONG)oldSize );
        if( index == CB_ERR ) {
            SendMessage( hwndSize, CB_SETCURSEL, 0, 0L );
        }
    }
}
Esempio n. 4
0
BOOL WdeLoadMSCustomControls ( WdeCustLib *lib )
{
    WdeCustInfoProc  info_proc;
    WdeCustStyleProc style_proc;
    WdeCustFlagsProc flags_proc;
    HWND             dialog_owner;
    DLGPROC          proc_inst;
    HINSTANCE        app_inst;
    BOOL             ok;

    dialog_owner  = WdeGetMainWindowHandle();

    app_inst = WdeGetAppInstance();

    proc_inst = (DLGPROC) MakeProcInstance ( (FARPROC) WdeLoadCustProc,
                                             app_inst );

    ok = JDialogBoxParam( app_inst, "WdeLoadCustom", dialog_owner,
                          proc_inst, (LPARAM) lib );

    FreeProcInstance ( (FARPROC) proc_inst );

    if ( ok == -1 ) {
        WdeWriteTrail("WdeLoadMSCustomControls: Dialog not created!");
        return ( FALSE );
    }

    if ( !ok ) {
        return ( FALSE );
    }

    if ( !HIWORD((uint_32)lib->info_name) ) {
        if ( !WdeQueryUnsafeMSLoad () ) {
            WdeWriteTrail("WdeLoadMSCustomControls: "
                          "User aborted unsafe load!");
            return ( FALSE );
        }
    }

    info_proc = (WdeCustInfoProc)
        GetProcAddress ( lib->inst, lib->info_name );
    style_proc = ( WdeCustStyleProc )
        GetProcAddress ( lib->inst, lib->style_name );
    flags_proc = ( WdeCustFlagsProc )
        GetProcAddress ( lib->inst, lib->flags_name );

    if ( !info_proc || !style_proc || !flags_proc ) {
        WdeWriteTrail("WdeLoadMSCustomControls: "
                          "Could not get proc address of ordinal!");
        return ( FALSE );
    }

    if ( !WdeCreateAndAddCustControl ( lib, info_proc,
                                       style_proc, flags_proc ) ) {
        WdeWriteTrail("WdeLoadMSCustomControls: Control not added to list!");
        return ( FALSE );
    }

    WdeMemValidate ( lib );

    return ( TRUE );
}
Esempio n. 5
0
//*************************************************************************
// cmAbout -- invoke the "About" dialog.  Its return code is ignored, since
// the About dialog doesn't return anything to the program.
//*************************************************************************
void cmAbout(void)
{
    lpDlgProc = (DLGPROC) MakeProcInstance( (FARPROC) DlgBoxProc, hInst);
    DialogBox(hInst, "About", hwnd, lpDlgProc);
    FreeProcInstance ( (FARPROC) lpDlgProc );
}  // end of cmAbout()
Esempio n. 6
0
/*--------------------------------------------------------------------------
 * Function: _tdb_DoAssertDlg
 * Expects:  char FAR *  lpszTest
 *           char FAR *  lpszReason
 *           char FAR *  lpszFilename
 *           uLONG       ulLineNo
 *           uLONG       ulCount
 *           void FAR *  lpvData
 *           uLONG       ulFormat
 * Returns:  int         iUserSelection
 * Purpose:  Setup and run the Macintosh Assertion Dialog
 * History:  10/28/94  MGD - Initial Revision
 *--------------------------------------------------------------------------
 */
TDBAPI( int ) _tdb_DoAssertDlg( LPSZ lpszTest, LPSZ lpszReason, LPSZ lpszFilename, uLONG ulLineNo, uLONG ulCount, LPVOID lpvData, uLONG ulFormat )
{
	int iUserSelection = ID_OK;

	//	In order to prevent possible nesting of DoAssertDlg. Only enter this section
	//		if we are not currently displaying an Assert.  In a true pre-emptive multi-threaded app
	//		there is a small chance that we may execute the test and be paged out before setting
	//		the boolean, but it is a small enough change that I am not going to worry about it for now.
	if ( !fInDoAssertDialog )
	{
		fInDoAssertDialog = TRUE;
		if (_hDlgTemplate)
			{
			// Hey, Dude!
			DLGVALS	dlgVals;
			FARPROC	lpDlgTest	= MakeProcInstance( (FARPROC) _tdb_AssertDlgProc, g_tdb_hinstApp );
			dlgVals.lpszTest		= lpszTest? lpszTest : _szEmpty;
			dlgVals.lpszReason	= lpszReason? lpszReason : _szEmpty;
			dlgVals.lpszFilename	= lpszFilename? lpszFilename : _szUnknown;
			dlgVals.ulLineNo		= ulLineNo;
			dlgVals.ulCount		= ulCount;
			dlgVals.lpvData		= lpvData;
			dlgVals.ulFormat		= ulFormat;
			dlgVals.hStackData	= g_tdb_hStackData;
			iUserSelection			= DialogBoxIndirectParam( g_tdb_hinstApp, _hDlgTemplate, g_tdb_hwndApp, lpDlgTest, (LPARAM)&dlgVals);
			FreeProcInstance(lpDlgTest);
		}
		else
		{
			int			iret;
			int			iApproxMessageSize;	//	To count the potential size of the message to make sure I
														//	don't overflow the szMessageBufferSize
			sBYTE FAR*	szBuf;

			iApproxMessageSize	= wsprintf( _szMessageBoxBuffer, "%s%s\n%s%ld\n\n", _szFile, lpszFilename, _szLineNo, ulLineNo );
			szBuf						= _szMessageBoxBuffer + iApproxMessageSize;
			iApproxMessageSize	+= _fstrlen( lpszReason );
			iApproxMessageSize	+= 256;	//	256 is an unofficial size for the amount of data that will
												//	be visible in an Assert as extra data

			//	If there is any data to add and a rough calculation implies that the data will fit
			//	in the buffer, include it. Otherwise, don't include it
			if ((ulCount > 0) && (iApproxMessageSize<MESSAGE_BUFFER_SIZE))
			{
				switch (ulFormat)
				{
					case 'b':
					case 'B':
						_FormatBytes((sBYTE FAR*)lpvData, ulCount, szBuf);
						break;
			
					case 'w':
					case 'W':
						_FormatWords((sBYTE FAR*)lpvData, ulCount, szBuf);
						break;
			
					case 'l':
					case 'L':
						_FormatLongs((sBYTE FAR*)lpvData, ulCount, szBuf);
						break;
			
					case 's':
					case 'S':
						_FormatCStr((sBYTE FAR*)lpvData,  szBuf);
						break;
			
					case 'p':
					case 'P':
						_FormatPStr((sBYTE FAR*)lpvData, szBuf);
						break;
				}
				_fstrcat( _szMessageBoxBuffer, _szCRLF );
				_fstrcat( _szMessageBoxBuffer, _szCRLF );
			}

			//	Add the Reason to the buffer
			_fstrcat( _szMessageBoxBuffer, lpszReason );
			iret = MessageBox(NULL, _szMessageBoxBuffer, ((lpszTest)? lpszTest : _szAssertFailed), MB_YESNOCANCEL | MB_TASKMODAL);

			switch (iret)
			{
				case IDYES:
					iUserSelection = ID_OK;
					break;
				case IDNO:
					iUserSelection = ID_TERMINATE;
					break;
				default:
					iUserSelection = ID_DEBUGGER;
					break;
			}
		}
		fInDoAssertDialog = FALSE;
	}

	return iUserSelection;
}
Esempio n. 7
0
HWND DialogStart( int iModeless, HINSTANCE hInstance, HWND hWndParent, ITEMID idDlgIn, DLGPROC lpDlgControl )
/***********************************************************************/
{
	int iResult;
	DLGPROC lpProc;
	HWND hDlg;
	BOOL bOnBottom;

	if ( bOnBottom = (iModeless < 0) )
		iModeless = -iModeless;
	iModeless &= 1;

	/***********************************************************************/
	/*	Used to bring up all of our dialog boxes whether modal or modeless */
	/***********************************************************************/

	/* If the dialog box is in our modeless window list, */
	/* Expose it if hidden or covered */
	if ( hDlg = DialogGet( idDlgIn ) )
	{
		DialogShow( idDlgIn );
		/* Return the window handle */
		return( hDlg );
	}

	/* Otherwise we need to create a new one... */
	lpProc = (DLGPROC)MakeProcInstance( (FARPROC)lpDlgControl, hInstance );

	/* If the caller wants modeless, */
	/* create it and enter its handle into the list */
	if ( iModeless )
	{
		hDlg = CreateDialogParam( hInstance, MAKEINTRESOURCE(idDlgIn), hWndParent,
		  lpProc, (LPARAM)idDlgIn);

		if (!hDlg)
		{ // This should never happen, so warn the developer
			Print( "Error loading window %d", idDlgIn );
			return( NULL );
		}

		DialogSet( idDlgIn, hDlg, lpProc );
		SetWindowPos( hDlg,
			( bOnBottom ? HWND_BOTTOM : HWND_TOP ),
			0, 0, /* Same location */
			0, 0, /* Same size */
			SWP_NOMOVE | SWP_NOSIZE /* Flags */ );
		/* Return the new window handle */
		return( hDlg );
	}

	/* If the caller wants modal, */
	/* let windows take care of the whole matter right now */
	else
	{
	//	EnableOverlappedWindow( hWndParent, NO );
		EnableWindow(hWndParent, FALSE);
		idLastModal = idDlgIn;

		iResult = DialogBoxParam( hInstance, MAKEINTRESOURCE(idDlgIn), hWndParent,
		  lpProc, (LPARAM)idDlgIn );

		idLastModal = NULL;
		EnableWindow(hWndParent, TRUE);
//		EnableOverlappedWindow( hWndParent, YES );
		SetFocus( hWndParent );
		FreeProcInstance((FARPROC)lpProc);
		/* Return the user's response to the modal box */
		return( (HWND)iResult );
	}
}
Esempio n. 8
0
int OpenImage (int nFlags, LONG lParam)
{
    FARPROC   lpfnOpenDlg;
    int       hInFile = 0;                   
    int       nError = EC_ERROR;             
    int       nFileType;                
    OFSTRUCT  Of;
    ATOM  Atom;
    WORD  wBytes;
    int         hTempFile;
    int         nErr = FALSE;

    /*  First get szOpenFileName filled in   */

    switch (nFlags)
    {
        case SCAN_OPEN:
            CleanFiles ();
            Atom = (ATOM) LOWORD (lParam);
            wBytes = GlobalGetAtomName (Atom, szOpenFileName, 128);
            GlobalDeleteAtom (Atom);
            GetNameFromPath ((LPSTR) szImageName, (LPSTR) szOpenFileName);
            bIsCurrTemp = FALSE;
            bImageModified = FALSE;
        break;

        case USER_OPEN:
    //      CleanFiles ();  BUG HERE????
            lpfnOpenDlg = MakeProcInstance ((FARPROC)OpenDlgProc, hInstIP);
            hInFile = DialogBox (hInstIP, "FILEDLG", hWndIP, lpfnOpenDlg);
            FreeProcInstance (lpfnOpenDlg);
            if (hInFile)
            {
                CleanFiles ();          // Put here instead of before call to dialog
                _lclose (hInFile);      // Kludge..

                /*  Always get image name from path.  Optionally also update the szOpenDir  */

                GetNameFromPath ((LPSTR) szImageName, (LPSTR) szOpenFileName);

                if (szOpenFileName [1] == ':')  // Look for A: or B:, if neither, remember open drive/directory
                {
                    if (! (szOpenFileName [0] == 'A' || szOpenFileName[0] == 'B' || szOpenFileName[0] == 'a' || szOpenFileName[0] == 'b'))
                    {
                        SeparateFile ((LPSTR) szOpenDir, (LPSTR) szImageName, (LPSTR)szOpenFileName);
                        _fstrcpy ((LPSTR) szSaveDir, (LPSTR) szOpenDir);
                    }
                }

                bIsCurrTemp = FALSE;


            }
            else
                nErr = USER_ABANDON;
            bImageModified = FALSE;
        break;

        case COMMAND_LINE_OPEN:
            CleanFiles ();
            _fstrcpy ((LPSTR)szOpenFileName, (LPSTR) lParam);
            GetNameFromPath ((LPSTR) szImageName, (LPSTR) szOpenFileName);
            bIsCurrTemp = FALSE;
            bImageModified = FALSE;
        break;

        case TOOLS_OPEN:
            _fstrcpy ((LPSTR)szOpenFileName, (LPSTR) lParam);
            bIsCurrTemp = TRUE;
        break;

        case OIC_OPEN:
        case AUTO_CONVERT_OPEN:
            _fstrcpy ((LPSTR)szOpenFileName, (LPSTR) lParam);
            bIsCurrTemp = TRUE;
            bImageModified = FALSE;
        break;

        case CLIPBOARD_OPEN:
            CleanFiles ();
            Atom = (ATOM) LOWORD (lParam);
            wBytes = GlobalGetAtomName (Atom, szOpenFileName, 128);
            GlobalDeleteAtom (Atom);
            _fstrcpy ((LPSTR) szImageName, (LPSTR) "Untitled");
            bIsCurrTemp = TRUE;
            bImageModified = FALSE;
        break;

        case GENERIC_OPEN:
        case UNDO_OPEN:
            _fstrcpy ((LPSTR)szOpenFileName, (LPSTR) lParam);
        break;

    }

    if (nErr != 0)
        return (nErr);

    hInFile = OpenFile ((LPSTR)szOpenFileName, (LPOFSTRUCT)&Of, OF_READWRITE);

    if (hInFile <= 0)
    {
        if (hInFile == 0)
        hInFile = IDCANCEL;
        nError = hInFile;
        return (nError);
    }

    /* Identify and Import File    */

    if (image_active)
    {
        _fstrcpy ((LPSTR) szTempPath,  (LPSTR) szOpenFileName);     // Store it somewhere

        SendMessage (hWndDisplay, WM_CLOSE, 0, 0);    // Close that baby down!

        if (nFlags == USER_OPEN)                      // So we don't re-display dialog
            nFlags = COMMAND_LINE_OPEN;
        else
            if (nFlags == CLIPBOARD_OPEN)
                nFlags = GENERIC_OPEN;                   

        _lclose (hInFile);

        PostMessage (hWndIP, WM_SHOWIMAGE, nFlags, (LONG) (LPSTR) szTempPath); // Re-prime the pump

        return (0);
    }

    _fstrcpy ((LPSTR) szCurrFileName, (LPSTR) szOpenFileName);  // For having UNDO cap.  5/91

    _llseek (hInFile, 0L, 0);

    nFileType = IdentFormat (hInFile, (LPSTR) szOpenFileName);
    if (nFileType < 0)
    {
        /* File type unknown    */

        _lclose (hInFile);
        hImportFile = 0; 
        return (nFileType);
    }

        switch (nFileType)
        {
            case IDFMT_CCPI:
            {
                char Buffer [128];

                GetTempFileName (0, (LPSTR) "OIC", 0, (LPSTR) Buffer);
                #ifndef DECIPHER
                /* If file type is compressed cpi, decompress first, then re-open     */
                hTempFile = DecompressCPI (hInFile ,(LPSTR) Buffer);
                if (hTempFile > 0)
                {
                    _lclose (hInFile);
                    return (OpenImage (OIC_OPEN, (LONG) (LPSTR) Buffer));
                }
                else
                    return (hTempFile);
    
            }
                #else
            return (EC_UFILETYPE);
                #endif
            break;
    
            case IDFMT_WMF:
            {
                char Buffer [128];
                WORD Retval;

                wUserImportType = (WORD) nFileType;
                GetTempFileName (0, (LPSTR) "WMF", 0, (LPSTR) Buffer);
                Retval = wmfImportMetaFile (hWndIP, hInFile, (LPSTR) Buffer);
                if (Retval == 0)
                {
                    _lclose (hInFile);
                    return (OpenImage (OIC_OPEN, (LONG) (LPSTR) Buffer));
                }
                else
                    return (USER_ABANDON);
    
            }
            break;

            case IDFMT_CPI:
            break;
    
            default:
    
            if (bDoDisplay)           // If we are going to actually display the thing, we may need to do some stuff first..
            if (bAutoConvert)
            {
                /*  Now if opened image is not CPI, save as CPI and re-open as CPI  */
    
                if (wImportType != IDFMT_CPI)
                    if (bAutoConvert)
                    {
                        wUserImportType = (WORD) nFileType;
                        hImportFile = hInFile;
                        SetState (IMPORT_TYPE, nFileType);  
                        nError = ImportFile();
                        if (nError != 0)
                            return (nError);
                        else
                            return (DoSave (SAVE_TO_CPI)); 
                    }
            }
            break;
        }

    hImportFile = hInFile;      
    SetState (IMPORT_TYPE, nFileType);  
    if (! wUserImportType)
        wUserImportType = wImportType;
    nError = ImportFile();

    if (nError >= 0)
        if (! bDoDisplay)
            PostMessage (hWndIP, WM_COMMAND, IDM_SAVE, 0L);

    return (nError);
}
Esempio n. 9
0
/*
 * StatDialog - show task status
 */
BOOL FAR PASCAL StatDialog( HWND hwnd, UINT msg, UINT wparam,
                                    DWORD lparam )
{
    WORD        cmd;
    FARPROC     fp;

    fp = fp;
    lparam = lparam;
    switch( msg ) {
    case WM_INITDIALOG:
        InitStatDialog( hwnd );
        oldIntData = IntData;
        return( TRUE );
        break;
    case WM_VSCROLL:
        ScrollAsmDisplay( hwnd, wparam, &currAddr, &firstAddr,
                        STAT_DISASM_1, STAT_DISASM_8, STAT_SCROLL );
        break;
    case WM_USER:
        /* an owned window is being destroyed make sure
         * Windows doesn't take the focus away from us*/
        SetFocus( hwnd );
        break;
    case WM_CLOSE:
        PostMessage( hwnd, WM_COMMAND, STAT_CANCEL, 0L );
        return( TRUE );
    case WM_COMMAND:
        cmd = LOWORD( wparam );
        switch( cmd ) {
#ifndef __NT__
        case STAT_SEG_MAP:
            fp = MakeProcInstance( SegMapDlgProc, Instance );
            JDialogBox( Instance, "SEG_MAP_DLG", hwnd, fp );
            FreeProcInstance( fp );
            break;
        case STAT_STACK_TRACE:
            StartStackTraceDialog( hwnd );
            break;
#else
        case STAT_SEG_MAP:
            {
                HANDLE                  hdl;
                DuplicateHandle(
                            GetCurrentProcess(),
                            processHdl,
                            GetCurrentProcess(),
                            &hdl,
                            0,
                            FALSE,
                            DUPLICATE_SAME_ACCESS );
                WalkMemory( hwnd, hdl, processID );
            }
            break;
#endif
        case STAT_SYMBOLS:
            StatShowSymbols = !StatShowSymbols;
            CheckDlgButton( hwnd, STAT_SYMBOLS, ( StatShowSymbols ) ? BST_CHECKED : BST_UNCHECKED );
            DisplayAsmLines( hwnd, &currAddr, &firstAddr, STAT_DISASM_1,
                        STAT_DISASM_8, STAT_SCROLL );
            break;
        case STAT_APPLY:
            GetStatRegisters( hwnd );
            InitStatDialog( hwnd );
            return( TRUE );
        case IDCANCEL:
            IntData = oldIntData;
            EndDialog( hwnd, 0 );
            return( TRUE );
        case IDOK:
            GetStatRegisters( hwnd );
            EndDialog( hwnd, 0 );
            return( TRUE );
        }
    }
    return( FALSE );

} /* StatDialog */
Esempio n. 10
0
BOOL ExportImageDLL( LPSTR lpExportFile )
{
	HMODULE   hModule;
	FARPROC  lpClockCursor = NULL;
	FARPROC  lpDataPointer = NULL;
	EXPORTPROC    lpStartProc;
	EXPORTPROC    lpProcessProc;
	EXPORTPROC    lpEndProc;
	LPFRAME  lpFrame;

	EXPPARMS parms;
	BOOL     fSuccess = FALSE;
	LPIMAGE lpImage;

	lpImage = GetActiveImage();

	if (!lpImage)
		goto Exit;

	lpFrame = ImgGetBaseEditFrame(lpImage);

	if (!lpFrame)
		goto Exit;

	if (!(hModule = (HMODULE)AstralLoadLibrary(lpExportFile)))
		goto Exit;

	lpStartProc   = (EXPORTPROC)GetProcAddress(hModule, "_ExportStart");
	lpProcessProc = (EXPORTPROC)GetProcAddress(hModule, "_ExportProcess");
	lpEndProc     = (EXPORTPROC)GetProcAddress(hModule, "_ExportEnd");

	if ( !lpStartProc || !lpProcessProc || !lpEndProc )
		goto Exit;

	iExportXSize = FrameXSize( lpFrame );
	iExportYSize = FrameYSize( lpFrame );
	iExportDepth = FrameDepth( lpFrame );
	iExportResolution = FrameResolution( lpFrame );

	lpClockCursor = MakeProcInstance( (FARPROC)ExportClockCursor, PictPubApp.Get_hInstAstral() );
	lpDataPointer = MakeProcInstance( (FARPROC)ExportDataPointer, PictPubApp.Get_hInstAstral() );

	AllocLines( &lpExportBuffer, 1, iExportXSize, max(1, iExportDepth));

	parms.hInstance      = PictPubApp.Get_hInstAstral();
	parms.hWnd           = GetActiveWindow();
	parms.lpszFileName   = lpImage->CurFile;
	parms.XSize          = iExportXSize;
	parms.YSize          = iExportYSize;
	parms.Depth          = iExportDepth;
	parms.Resolution     = iExportResolution;
	parms.StatusCallback = (LPROC)lpClockCursor;
	parms.DataPointer    = (LPTRPROC)lpDataPointer;

	if (!lpClockCursor || !lpDataPointer || !lpExportBuffer)
		goto Exit;


	if ((*lpStartProc)((LPEXPPARMS)&parms))
	{
		MessageStatus( IDS_PLEASEWAIT );
		if ((*lpProcessProc)((LPEXPPARMS)&parms))
		{
			fSuccess = TRUE;
			(*lpEndProc)((LPEXPPARMS)&parms);
		}
	}

Exit:

	if (lpClockCursor)
		FreeProcInstance((FARPROC)lpClockCursor);

	if (lpDataPointer)
		FreeProcInstance((FARPROC)lpDataPointer);

	if (lpExportBuffer)
		FreeUp(lpExportBuffer);

	lpExportBuffer = NULL;

	if (hModule)
		FreeLibrary(hModule);

	MessageStatus( 0 );

	return(fSuccess);
}
Esempio n. 11
0
void grabber( LPSTR lpExtName, int port, HINSTANCE hInstance, HWND hWindow )
{

	HWND hWnd;
/*
	special conditions:
		hand scan interface --	
			with hand scanners the dialog box has a scan
			frame which gets filled with image data.  the
			dialog box must remain up during reads, so we
			use the exported frame_open, cacheptr, and
			frame_close to create the frame instead of 
			device reads.  Devopen just returns devcaps,
			devstart does everything else.
	
		special willow gs --	
			the gs board has 4 different buffers, which
			contain the following: 0-even pix/even lines,
			1-odd pix/even lines, 2-even pix/odd lines,
			3-odd pix/odd lines.
			each call to devread will layer the data so
			that the buffers will be combined correctly.
	
	Device Requirements Byte Decoding:

		XXXXXXX1b =  need to take over display
		XXXXXXX0b =  no need to take over display
		XXXXXX1Xb =  special willow gs read
		XXXXXX0Xb =  no special read 
		XXXX00XXb =  image depth, special case palette color 8-bit
		XXXX01XXb =  depth == 1
		XXXX10XXb =  depth == 2
		XXXX11XXb =  depth == 3
		X1XXXXXXb = special hand scan i/f 
		X0XXXXXXb = standard grab i/f
		XX1XXXXXb = don't free DLL after exit
		XX0XXXXXb = free DLL after exit 
		1XXXXXXXb = putting data from cache to external device
		0XXXXXXXb = putting data from external device into cache
		*/

	BYTE devreq; // device requirements
	LPFRAME lpFrame, lpOldFrame;
	BYTE depth;
	int lncnt,Datatype;
	HMODULE hDLL;
	LPIMAGE lpImage;

	if ( !(hDLL = (HMODULE)LoadGrabberLibrary(lpExtName)) ) {
		Message( IDS_EBADDRIVER, NULL );
		return;
	}

	if ( !(lpImage = GetActiveImage()))
		lpFrame = NULL;
	else
		lpFrame = ImgGetBaseEditFrame(lpImage);

   lpfnDevName     = (DEVNAMEPROC)GetProcAddress(hDLL, MAKEINTRESOURCE(301));
   lpfnDevOpen     = (DEVOPENPROC)GetProcAddress(hDLL, MAKEINTRESOURCE(302));
   lpfnDevCall     = (DEVCALLPROC)GetProcAddress(hDLL, MAKEINTRESOURCE(303));
   lpfnDevClose    = (DEVCLOSEPROC)GetProcAddress(hDLL, MAKEINTRESOURCE(304));
   lpfnAcquireProc = (DLGPROC)GetProcAddress(hDLL, MAKEINTRESOURCE(305));

	/* get device's intentions -- is this a put to or read from cache */
	DevInfo.hInst = hInstance;  /* set the data structures */
	DevInfo.hPw = hWindow;
	DevInfo.bFile_is_open = ( lpFrame != NULL );

	if(DevInfo.bFile_is_open)
		{
		DevInfo.bImg_type = (lpImage->DataType==IDC_SAVECT ? TRUE : FALSE);
		/* pass the current filename */
		lstrcpy(DevInfo.cfname, lpImage->CurFile); 
		}

	if(!DevOpen(&DevInfo)) {
		DevCall(DEV_MSG, (LPTR)&DevMsg);
		
		/* if MsgNo == 0, then user cancelled */
		if(DevMsg.MsgNo) {
			if(DevMsg.MsgNo > 0) {
				Message( DevMsg.MsgNo );
			} else {
				/* print the driver's message */
				Print("%ls", (LPTR)DevMsg.szMsg);
			}
		}
		return; 
	}

	bKeepDLL = (DevInfo.device_caps & 0x20);
	devreq = DevInfo.device_caps;
	
	/* doing a put cache to an external device */
	if(!(devreq & 0x80)) {
		/* fill up the device info data structure */
		DevInfo.npix = FrameXSize( lpFrame );
		DevInfo.nlin = FrameYSize( lpFrame );
		DevInfo.bpl =  FrameXSize( lpFrame );
		DevInfo.xres = DevInfo.yres = FrameResolution( lpFrame );
		DevInfo.bpp = 8;
	} else {
		DevInfo.port = port; /* set the port for devices which require it */
#ifndef WIN32
		DevInfo.vgaaddr = GetA000H(); /* set the VGA buffer address */
#endif
	}

	/* see if we need to take over display */
	if(devreq & 1) {
		/* Hide the Cursor */
		ShowCursor( FALSE );

		/* Create the acquire window: it doesn't have the visable bit set */
		AstralDlg( YES, hInstance, hWindow, IDD_GRAB, AcquireProc);
		AstralDlgShow( IDD_GRAB );

		/* Enter the picture window command processor */
		SetCapture( AstralDlgGet( IDD_GRAB ) );

		/* set the data structures */
		DevInfo.hInst = hInstance;  
		DevInfo.hPw   = AstralDlgGet( IDD_GRAB );

		/* call display driver disable */
#ifndef WIN32
		PicwinOn((LPSTR)palette1);
#endif
	}

	if(devreq & 0x40) { // devstart does everything
		DevInfo.FpPtr = (LPTRPROC)MakeProcInstance(
			(FARPROC)grabber_frame_ptr, DevInfo.hInst);

		DevInfo.FoPtr = (LPTRPROC)MakeProcInstance(
			(FARPROC)grabber_frame_open, DevInfo.hInst);

		DevInfo.FsPtr = (LPTRPROC)MakeProcInstance(
			(FARPROC)grabber_frame_set, DevInfo.hInst);

		DevInfo.FcPtr = (LPROC)MakeProcInstance(
			(FARPROC)grabber_frame_close, DevInfo.hInst);

		DevInfo.CcPtr = (LPROC)MakeProcInstance(
			(FARPROC)grabber_AstralClockCursor, DevInfo.hInst);
	}

	DevInfo.bLineArtAsGray = Control.LineArtAsGray;
 
	if(!DevCall(DEV_START, (LPTR)&DevInfo)) { /* if get, fill struct */
		back_to_windows(devreq & 1); /* restore if true */

		DevCall(DEV_MSG, (LPTR)&DevMsg);

		/* if MsgNo == 0, then user cancelled */
		if(DevMsg.MsgNo) {
			if(DevMsg.MsgNo > 0) {
				Message( DevMsg.MsgNo );
			} else {
				/* print the driver's message */
				Print("%ls", (LPTR)DevMsg.szMsg);
			}
		}

		if(devreq & 0x40) { // devstart does everything
			FreeProcInstance((FARPROC)DevInfo.FpPtr);
			FreeProcInstance((FARPROC)DevInfo.FoPtr);
			FreeProcInstance((FARPROC)DevInfo.FsPtr);
			FreeProcInstance((FARPROC)DevInfo.FcPtr);
			FreeProcInstance((FARPROC)DevInfo.CcPtr);
		}

		DevClose(); /* close the device */
		return;
	}

	/* DEV_START returned ok, now get or put image data if not done */

	if((devreq & 0xc0) == 0x80) { // putting data into the cache with devreads
		if(((devreq & 4) == 4) || ((devreq & 0x0c) == 0)) {
			depth = 1;
		} else {
			if((devreq & 8) == 8) {
				depth = 2;
			} else {
				if((devreq & 0x0c) == 0x0c) {
					depth = 3;
				}
			}
		}

		lpOldFrame = frame_set( NULL );
	
		if(!(lpFrame = FrameOpen(
				(FRMDATATYPE)depth,DevInfo.npix,DevInfo.nlin,DevInfo.xres))) {

			back_to_windows(devreq & 1); /* Restore if true */
	
			FrameError(IDS_EIMAGEOPEN);
			return;
		}
	
		frame_set(lpFrame);
	
		if(!(devreq & 2))	{
			for ( lncnt=0; lncnt<DevInfo.nlin; lncnt++ ) {
				DevData.ImageAddress = FramePointer(lpFrame, 0, lncnt, YES);
				if(!DevCall(DEV_READ, (LPTR)&DevData)) {
		         back_to_windows(devreq & 1); /* Restore if true */
					DevCall(DEV_MSG, (LPTR)&DevMsg);
	
					/* if MsgNo == 0, then user cancelled */
					if(DevMsg.MsgNo) {
						Print("Unable to get data from device");
					} else {
						DevInfo.nlin = lncnt;  // hand scanner, get total lines
					}
					return;
				}
			}
		} else { /* special willow gs reader */
	
			/* read even bytes, even lines */
			for ( lncnt=0; lncnt<DevInfo.nlin; lncnt+=2 ) {
				DevData.ImageAddress = FramePointer(lpFrame, 0, lncnt, YES);
				if(!DevCall(DEV_READ0, (LPTR)&DevData)) {
					back_to_windows(devreq & 1); /* Restore if true */
					Print("Unable to get data from device");
					return;
				}
			}
	
			/* read odd bytes, even lines */
			for ( lncnt=0; lncnt<DevInfo.nlin; lncnt+=2 ) {
				DevData.ImageAddress = FramePointer(lpFrame, 1, lncnt, YES);
				if(!DevCall(DEV_READ1, (LPTR)&DevData)) {
					back_to_windows(devreq & 1); /* Restore if true */
					Print("Unable to get data from device");
					return;
				}
			}
	
			/* read even bytes, odd lines */
			for ( lncnt=1; lncnt<DevInfo.nlin; lncnt+=2 ) {
				DevData.ImageAddress = FramePointer(lpFrame, 0, lncnt, YES);
				if(!DevCall(DEV_READ2, (LPTR)&DevData)) {
					back_to_windows(devreq & 1); /* Restore if true */
					Print("Unable to get data from device");
					return;
				}
			}
	
			/* read odd bytes, odd lines */
			for ( lncnt=1; lncnt<DevInfo.nlin; lncnt+=2 ) {
				DevData.ImageAddress = FramePointer(lpFrame, 1, lncnt, YES);
				if(!DevCall(DEV_READ3, (LPTR)&DevData)) {
					back_to_windows(devreq & 1); /* Restore if true */
					Print("Unable to get data from device");
					return;
				}
			}
		}
		
		FrameClose( lpOldFrame );
	
		back_to_windows(devreq & 1); /* Restore if true */
	
		if(DevInfo.bpp == 1) {
			Datatype = IDC_SAVELA;
		} else {
			if(DevInfo.bpp == 8) {
				Datatype = IDC_SAVECT;
			} else {
				Datatype = IDC_SAVE24BITCOLOR;
			}
		}
	
		/* Setup the new image and bring up the new image window */
        LPIMAGE lpNewImage = CreateImage(NULL, lpFrame, NULL, 
           NULL, Control.DefaultFileType, Datatype, 
           IMG_DOCUMENT, NULL);
        if (lpNewImage)
        {
            if (PictPubApp.OpenDocumentFile((LPSTR)lpNewImage->CurFile,
               lpNewImage))         
            {
               	/* only version of image is in the cache */
            	/* so insure user is asked about saving when done */
                lpNewImage->fChanged = TRUE;
            }
            else
                DestroyImage(lpNewImage);
        }
	
		DevClose(); /* close the device */
	} else {
        LPIMAGE lpNewImage = NULL;

		/* enable the frame created by DevStart */
		lpFrame = frame_set(NULL);

		/* putting data to external device with DevWrites */
		if((devreq & 0xc0) == 0) {
			for ( lncnt=0; lncnt<DevInfo.nlin; lncnt++ ) {
				AstralClockCursor( lncnt, DevInfo.nlin, NO );
				DevData.ImageAddress = FramePointer(lpFrame, 0, lncnt, NO);
				if(!DevCall(DEV_WRITE, (LPTR)&DevData)) {
					Print("Unable to put data to device");
					return;
				}
			}
		} else {
			/* devstart has created a frame with image data */
			FreeProcInstance((FARPROC)DevInfo.FpPtr);
			FreeProcInstance((FARPROC)DevInfo.FoPtr);
			FreeProcInstance((FARPROC)DevInfo.FsPtr);
			FreeProcInstance((FARPROC)DevInfo.FcPtr);

			if(DevInfo.bpp == 1) {
				Datatype = IDC_SAVELA;
			} else {
				if(DevInfo.bpp == 8) {
					Datatype = IDC_SAVECT;
				} else {
					Datatype = IDC_SAVE24BITCOLOR;
				}
			}

			back_to_windows(devreq & 1); /* Restore if true */

			/* enable the frame created by DevStart */
			lpFrame = frame_set(NULL);

			/* DevInfo.nlin returns the actual line count */
			if(FrameYSize(lpFrame) <= DevInfo.nlin) {
				/* Setup the new image and bring up the new image window */
            {
                lpNewImage = CreateImage(NULL, lpFrame, NULL, 
                   NULL, Control.DefaultFileType, Datatype, 
                   IMG_DOCUMENT, NULL);
                if (lpNewImage)
                {
                    if (!PictPubApp.OpenDocumentFile((LPSTR)lpNewImage->CurFile,
                       lpNewImage))         
                    {
                        DestroyImage(lpNewImage);
                        lpNewImage = NULL;
                    }
                }
            }

			} else {
				/* create a new frame of the right size and copy  */
				/* the right number of lines to it */

				lpOldFrame = FrameOpen(
					FrameType(lpFrame),
					FrameXSize(lpFrame), 
					DevInfo.nlin,
					FrameResolution(lpFrame));

				AstralCursor( IDC_WAIT );

				for(lncnt=0; lncnt<DevInfo.nlin; lncnt++) {
					FrameCopyLine(lpFrame, lpOldFrame, lncnt);
				}

				FrameClose(lpFrame);
				lpFrame = lpOldFrame;
				AstralCursor( NULL );
				/* Setup the new image and bring up the new image window */
                lpNewImage = CreateImage(NULL, lpFrame, NULL, 
                   NULL, Control.DefaultFileType, Datatype, 
                   IMG_DOCUMENT, NULL);
                if (lpNewImage)
                {
                    if (!PictPubApp.OpenDocumentFile((LPSTR)lpNewImage->CurFile,
                       lpNewImage))         
                    {
                        DestroyImage(lpNewImage);
                        lpNewImage = NULL;
                    }
                }

			}
			/* only version of image is in the cache */
			/* so insure user is asked about saving when done */
            if (lpNewImage)    
                lpNewImage->fChanged = TRUE;

			DevClose(); /* close the device */
		}
	}
}
Esempio n. 12
0
int AstralImageImport( LPSTR lpInFile, LPSTR lpProfile, int nFileType )
//////////////////////////////////////////////////////////////////////////
{
    OFSTRUCT ofstruct;

    HINSTANCE hDLL              = NULL;
    HINSTANCE hSrcLibrary       = NULL;
    HINSTANCE hDstLibrary       = NULL;
    HINSTANCE hImportSetupData  = NULL;
    HINSTANCE hExportSetupData  = NULL;

    CREATESETUP  lpfnCreateSetup    = NULL;
    DESTROYSETUP lpfnDestroySetup   = NULL;
    IMPORTPROC   lpfnImportProc     = NULL;

    IMPORT_OPTIONS   Options;
    EXPORT_OPTIONS   Export;

    int error = IMPORT_NOERROR;

    FNAME szFilterPath;
    FNAME szOutFile; 
    FNAME szTempFile;
    FNAME szINIPath;
    char szFilter[13]; 
    char szINI[13]; 

    ProgressBegin( 1, PROGRESS_ID( IDS_UNDOIMPORTIMAGE ));

    szFilterPath[0] = szOutFile[0] = szTempFile[0] = szINIPath[0] = 0;
    szFilter[0] = szINI[0] = 0; 

    if( !nFileType || 
         nFileType < IDN_FIRSTIMPORTFILETYPE || 
         nFileType > IDN_LASTIMPORTFILETYPE )
    {
        error = IMPORT_INVALIDFILE_ERROR;
        goto ImportAbort;
    }

    // load ISGDI9.DLL explicitly
    GetModuleFileName( PictPubApp.Get_hInstAstral(), szFilterPath, sizeof( szFilterPath ));
    *strrchr( szFilterPath, '\\' ) = '\0';        
    lstrcat( szFilterPath, "\\" );
    lstrcat( szFilterPath, FILTER_DRIVER );

    hDLL = LoadLibrary( szFilterPath );

#ifdef WIN32
    if( hDLL == NULL )
#else
    if( hDLL < HINSTANCE_ERROR )
#endif
    {
        error = IMPORT_DLLLOAD_ERROR;
        goto ImportAbort;
    }

    // get filter and profile names
    GetImportFilter( nFileType, szFilter, szINI );

    // get location of filters
    GetExtNamePath( szFilterPath, IDN_IMPORTFILTERS );

    // set import filter path
    lstrcat( szFilterPath, szFilter );  

    if( OpenFile( szFilterPath, &ofstruct, OF_EXIST ) == HFILE_ERROR ) 
    {
        error = IMPORT_SRCLIBLOAD_ERROR;
        goto ImportAbort;
    }

    // set import filter profile path
    if( Control.bNetworkInstall )       // use pouch path
    {
        GetIniPath( szINIPath );
    }
    else                               // use filters directory
    {
        GetExtNamePath( szINIPath, IDN_IMPORTFILTERS );
    }
    lstrcat( szINIPath, szINI );  

#ifdef WIN32
    if(( hSrcLibrary = LoadLibrary( szFilterPath )) != NULL )
#else
    if(( hSrcLibrary = LoadLibrary( szFilterPath )) >= HINSTANCE_ERROR )
#endif
    {
        lpfnCreateSetup     = 
                ( CREATESETUP )GetProcAddress( hSrcLibrary, "CreateSetup" );
        hImportSetupData    = 
                ( HINSTANCE )( *lpfnCreateSetup )( hSrcLibrary, szINIPath, NULL, NULL );
    }
    else
    {
        error = IMPORT_SRCLIBLOAD_ERROR;
        goto ImportAbort;
    }

    // set export filter path 
    *strrchr( szFilterPath, '\\' ) = '\0';        
    lstrcat( szFilterPath, "\\" );
    lstrcat( szFilterPath, EXPORT_FILTER );

    if( OpenFile( szFilterPath, &ofstruct, OF_EXIST ) == HFILE_ERROR ) 
    {
        error = IMPORT_DSTLIBLOAD_ERROR;
        goto ImportAbort;
    }

#ifdef WIN32
    if(( hDstLibrary = LoadLibrary( szFilterPath )) != NULL )
#else
    if(( hDstLibrary = LoadLibrary( szFilterPath )) >= HINSTANCE_ERROR )
#endif
    {
        lpfnCreateSetup     = 
                ( CREATESETUP )GetProcAddress( hDstLibrary, "CreateSetup" );
        hExportSetupData    = 
                ( HINSTANCE )( *lpfnCreateSetup )( hDstLibrary, lpProfile, NULL, NULL );
    }
	else
    {
        error = IMPORT_DSTLIBLOAD_ERROR;
        goto ImportAbort;
    }

    memset( &Export, 0, sizeof( EXPORT_OPTIONS ));

    Export.GetSet_Status   = 
        ( GETSET_STATUS )MakeProcInstance(( FARPROC )GetSet_DialogStatus, PictPubApp.Get_hInstAstral());

    if( Export.GetSet_Status == NULL )
    {
        error = IMPORT_IMPORTFILE_ERROR;
        goto ImportAbort;
    }

    *strrchr( szFilterPath, '\\' ) = '\0';        
    *strrchr( szINIPath, '\\' ) = '\0';        

    memset( &Options, 0, sizeof( IMPORT_OPTIONS ));

    Options.hInputData     = hImportSetupData;      // Handle to import data
    Options.hOutputData    = hExportSetupData;      // Handle to export data
    Options.lpszDriverPath = szFilterPath;          // Driver DLL directory
    Options.lpszFontPath   = szFilterPath;          // Font file directory
    Options.lpExport       = &Export;

    // set temp file directory
    if( Control.bNetworkInstall )
        Options.lpszWorkPath   = szINIPath;         
    else
        Options.lpszWorkPath   = szFilterPath;         

    lstrcpy( szOutFile, Options.lpszWorkPath );     
    lstrcat( szOutFile, "\\" ); 

    // create temp file name
    lstrcpy( szTempFile, "PP" );
    GetTempFilename( szTempFile, ".TIF" );
    lstrcat( szOutFile, szTempFile );    

    lpfnImportProc = ( IMPORTPROC )GetProcAddress( hSrcLibrary, "ImportFile" );

    if( !( error = (( *lpfnImportProc )( NULL, EXPORT_FILTER, szOutFile, lpInFile, ( LPSTR )&Options ))))    
        lstrcpy( lpInFile, szOutFile );
    else
        FileDelete( szOutFile );        // get rid of temp file in case of error

    if( Export.GetSet_Status != NULL )
        FreeProcInstance(( FARPROC )Export.GetSet_Status );
    
ImportAbort:

#ifdef WIN32
    if( hDstLibrary != NULL )
#else
    if( hDstLibrary >= HINSTANCE_ERROR )
#endif
    {
        lpfnDestroySetup = ( DESTROYSETUP )GetProcAddress( hDstLibrary, "DestroySetup" );
        ( *lpfnDestroySetup )( hExportSetupData );

        FreeLibrary( hDstLibrary );
    }

#ifdef WIN32
    if( hSrcLibrary != NULL )
#else
    if( hSrcLibrary >= HINSTANCE_ERROR )
#endif
    {
        lpfnDestroySetup = ( DESTROYSETUP )GetProcAddress( hSrcLibrary, "DestroySetup" );
        ( *lpfnDestroySetup )( hImportSetupData );

        FreeLibrary( hSrcLibrary );
    }

#ifdef WIN32
    if( hDLL != NULL )
#else
    if( hDLL >= HINSTANCE_ERROR )
#endif
    {
        FreeLibrary( hDLL );
    }

    ProgressEnd();

    switch( error )
    {
        case IMPORT_NOERROR:
            break;

        case IMPORT_INVALIDFILE_ERROR:              // type not supported
            Message( IDS_INVALIDIMPORTFILE_ERROR );
            break;

        case IMPORT_SRCLIBLOAD_ERROR:               // error loading import filter
            Message( IDS_IMPORTLIBLOAD_ERROR );
            break;

        case IMPORT_DSTLIBLOAD_ERROR:               // error loading export filter
            Message( IDS_EXPORTLIBLOAD_ERROR );
            break;

        case IME_INVALID_FILE_TYPE:                 // incorrect file format
            Message( IDS_INVALIDIMPORTFILE_TYPE );
            break;

        case IME_INVALID_FILE_VERSION:              // unsupported file version
            Message( IDS_INVALIDIMPORTFILE_VERSION );
            break;

        case IME_MEMORY:                            // insufficient memory
            Message( IDS_EMEMALLOC );
            break;

        case IMPORT_DLLLOAD_ERROR:
        case IMPORT_IMPORTFILE_ERROR:               // non-specific error from app
        default:                                    // non-specific error from filter
            Message( IDS_IMPORTFILE_ERROR );    
            break;
    }
    return error;
}
Esempio n. 13
0
int PASCAL WinMain( HINSTANCE currinst, HINSTANCE previnst, LPSTR cmdline, int cmdshow)
{
    char        *ptr;
    char        *dst;
    FARPROC     enumproc;

    currinst = currinst;
    previnst = previnst;
    cmdshow = cmdshow;

    ptr = cmdline;

    // read the path
//    while( isspace( *ptr ) ) ptr++;
//    dst = AppName;
//    while( !isspace( *ptr ) ) {
//      *dst = *ptr;
//      dst++;
//      ptr++;
//    }
//    *dst = '\0';

    // read the classname
    while( isspace( *ptr ) ) ptr++;
    dst = ClassName;
    while( !isspace( *ptr ) ) {
        *dst = *ptr;
        dst++;
        ptr++;
    }
    *dst = '\0';

    // read the Window Caption
    while( isspace( *ptr ) ) ptr++;
    if( *ptr == '"' ) {
        ptr++;
        dst = Caption;
        while( *ptr != '"' ) {
            *dst = *ptr;
            dst++;
            ptr++;
        }
        *dst = '\0';
    }
    ptr++;
    CaptionLen = strlen( Caption );
    while( isspace( *ptr ) ) ptr++;

    TheWindow = NULL;
    enumproc = MakeProcInstance( (FARPROC)EnumProc, currinst );
    EnumWindows( (WNDENUMPROC)enumproc, 0 );
    FreeProcInstance( enumproc );

    if( TheWindow == NULL ) {
        WinExec( ptr, SW_SHOW );
    } else {
        #ifdef __NT__
            SetForegroundWindow( TheWindow );
        #else
            ShowWindow( TheWindow, SW_RESTORE );
            SetWindowPos( TheWindow, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
        #endif
    }
    return( 1 );
}
Esempio n. 14
0
int CALLBACK EnumFontsEnumFunc( const LOGFONT FAR *lf, const TEXTMETRIC FAR *tm, DWORD ftype, LPARAM data )
#endif
{
#ifdef __WINDOWS_386__
    const LOGFONT __far    *lf = MK_FP32( (void *)_lf );
    tm = tm;
#elif defined( __WINDOWS__ )
    const LOGFONT FAR      *lf = (const LOGFONT FAR *)elf;
//    const TEXTMETRIC FAR *tm = (const TEXTMETRIC FAR *)ntm;
    ntm = ntm;
#else
    tm = tm;
#endif
    ftype = ftype;
    data = data;

    /*
     * Something has happened in the font world and Windows font mapper since
     * the original source was written, it checked only for Courier. All the
     * font names below are verified as good monospaced fonts. Check for the
     * best fonts first, so that the system picks the best if enumerated first.
     * Changed the test to == 0, because it is easier to read and understand.
     */
#if defined( __NT__ )
    if( FARstricmp( lf->lfFaceName, "andale mono" ) == 0 ||
        FARstricmp( lf->lfFaceName, "lucida console" ) == 0 ||
        FARstricmp( lf->lfFaceName, "vera sans mono" ) == 0 ||
        FARstricmp( lf->lfFaceName, "courier new" ) == 0 ||
        FARstricmp( lf->lfFaceName, "courier" ) == 0 ) {
#else
    if( FARstricmp( lf->lfFaceName, "courier new" ) == 0 ||
        FARstricmp( lf->lfFaceName, "courier" ) == 0 ) {
#endif
        courierFont = CreateFont( 13, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, lf->lfCharSet,
                                  OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
                                  lf->lfPitchAndFamily, lf->lfFaceName );
        return( 0 );
    }
    return( 1 );

} /* EnumFunc */

/*
 * getCourierFont - find a mono font
 */
static void getCourierFont( HANDLE inst )
{
    LOGFONT     logfont;
    FARPROC     fp;
    HDC         hdc;

    inst = inst;        /* shut up the compiler for NT */
    hdc = GetDC( HWND_DESKTOP );
    fp = MakeFontEnumProcInstance( EnumFontsEnumFunc, inst );
#if defined( __WINDOWS__ ) && defined( _M_I86 )
    EnumFonts( hdc, NULL, (OLDFONTENUMPROC)fp, 0 );
#else
    EnumFonts( hdc, NULL, (FONTENUMPROC)fp, 0 );
#endif
    FreeProcInstance( fp );
    ReleaseDC( (HWND)NULL, hdc );

    if( courierFont == NULL ) {
        courierFont = GetStockObject( ANSI_FIXED_FONT );
        GetObject( courierFont, sizeof( LOGFONT ), (LPSTR)&logfont );
        courierFont = CreateFontIndirect( &logfont );
    }

} /* getCourierFont */
/* Function: WndProc()
Process application messages for main window*/
LONG FAR PASCAL WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM,lParam)
{
	FARPROC lpfnProc;
	int nAddrSize=sizeof(SOCKADDR);
	WORD WSAEvent, WSAErr;
	HMENU hMenu;
	int nRet;
	switch(msg)
	{
	case WSA_ASYNC:
		WSAEvent=WSAGETSELECTEVENT(lParam);
		WSAErr=WSAGETSELECTERROR(lParam);
		if(WSAErr)
		{
			/*error in async notification message*/
			WSAperror(WSAErr,"FD_READ");
		}
		switch(WSAEvent)
		{
		case FD_READ:
			/*receive the available data*/
			nRet=recvfrom(hSock,(char FAR *)achInBuf,BUF_SIZE,0,(struct sockaddr *)&stRmtName,&nAddrSize);
			/*display error if 'receive' failed*/
			if((nRet==SOCKET_ERROR)&&(WSAErr))
			{
				WSAperror(WSAErr,"recvfrom( )");
				break;
			}
			if(bReceiving) {
				achInbuf[nRet-2]=0; /*remove CR/LF */
			/*display the data received*/
			wsprintf((LPSTR)achOutBuf, "%s : %s", inet_ntoa(stRmtName.sin_addr),(LPSTR)achInBuf);
			MessageBox(hwnd,(LPSTR)achOutBuf,"Daytime",MB_OK|MB_ICONASTERISK);
			/*remove the timeout alert*/
			KillTimer(hwnd,TIMEOUT_ID);
			/*reset socket state*/
			bReceiving=FALSE;
		}
			else
			{
				time_t stTime;
				time(&stTime);
				wsprintf(achOutBuf,"%s",ctime(&stTime));
				nRet=sendto(hSock,achOutbuf,strlen(achOutBuf),0,(LPSOCKADDR)&stRmtName,sizeof(SOCKADDR));
				if(nRet==SOCKET_ERROR)
					WSAperror(WSAGetLastError( ), "sendto( )");
			}
			break;
		default:
			break;
		}
		/*end of switch(WSAEvent)*/
		break;
	case WM_COMMAND:
		switch(wParam)
		{
		case IDM_OPEN:
			if(hSock!=INVALID_SOCKET)
			{
				nRet=closesocket(hSock);
				hSock=INVALID_SOCKET;
			}
			if(nRet==SOCKET_ERROR)
				WSAperror(WSAGetLastError( ),"socket( )");
			/*get UDP socket*/
			hSocket=socket(AF_INET,SOCK_DGRAM,0);
			if(hSock==INVALID_SOCKET)
			{
				WSAperror(WSAGetLastError( ), "socket( )");
			}
			else
			{
				int okay=TRUE;
				/*request async notification for data arrival*/
				nRet=WSAAsyncSelect(hSock,hwnd,WSA_ASYNC,FD_READ);
				if(nRet==SOCKET_ERROR)
				{
					WSAperror(WSAGetLastError( ), "WSAAsyncSelect( )");
					okay=FALSE;
				}
				/*name the socket to receive requests as a server*/
				stlclName.sin_family=PF_INET;
				stLclName.sin_port=htons(IPPORT_DAYTIME);
				stLclName.sin_addr.sin_addr=INADDR_ANY;
				nRet=bind(hSock,(LPSOCKADDR)&stLclName,sizeof(struct sockaddr));
				if(nRet==SOCKET_ERROR)
				{
					WSAperror(WSAGetLastError( ), "bind( )");
					okay=FALSE;
				}
				if(ok)
				{
					wsprintf((LPSTR)achOutBuf,"Socket %d,named and registered for FD_READ",hSock);
					MessageBox(hwnd,(LPSTR)achOutBuf,"Ready to send or receive",MB_OK | MB_ICONASTERISK);
				}
			}
			break;
			/*note: the SendTo menu command sends the IDM_SENDTO message to AU_TIME*/
		case IDM_SENDTO:
			/*creating dialog box to prompt for destination host */
			lpfnProc=MakeProcInstance((FARPROC)DestDlgProc,hInst);
			nRet=DialogBox(hInst,"DESTINATIONLG",hwndMain,lpfnProc);
			FreeProcInstance((FARPROC) lpfnProc);
			/*checking destination address*/
			stRmtName.sin_addr.s_addr=GetAddr((LPSTR)szHost);
			if(stRmtName.sin_addr.s_addr==INADDR_ANY)
			{
				if(nRet!=-1)
					MessageBox(hwnd,"Need a destination host to send to","unable to connect!",MB_OK | MB_ICONASTERISK);
			}
			else
			{
				if(!SetTimer(hwnd,TIMEOUT_ID,TIMEOUT_PERIOD,NULL))
					MessageBox(hwnd,"Set timer failed","Error", MB_OK | MB_ICONASTERISK);
				/*set socket state... for a response as a client */
				bReceiving=TRUE;
				/*send a dummy datagram to daytime port..to request daytime response*/
				stRmtName.sin_family=PF_INET;
				stRmtName.sin_port=htons(IPPORT_DAYTIME);
				nRet=sendto(hSock,(char FAR *)achOutBuf,1,0,(LPSOCKADDR)&stRmtName,sizeof(SOCKADDR));
				if(nRet==SOCKET_ERROR)
					WSAperror(WSAGetLastError( ),"sendto( )");
			}
			break;
			/*the options menu allows the user to enable or disable broadcasts which sends IDM_BROADCAST message to AU_TIME */
		case IDM_BROADCAST:
			/* calls setsockopt() SO_BROADCAST to enable or disable*/
			hMenu=GetMenu(hwnd);
			bBroadcast=!CheckMenuItem(hMenu,IDM_BROADCAST,(bBroadcast ? MF_UNCHECKED : MF_CHECKED));
			nRet=setsockopt(hSock,SOL_SOCKET,SO_BROADCAST,(LPSTR)&bBroadcast,sizeof(BOOL));
			if(nRet==SOCKET_ERROR)
			WSAperror(WSAGetLastError( ),"setsockopt( )");
			break;
		case IDM_ABOUT:
			lpfnProc=MakeProcInstance((FARPROC)DlgAbout,hInst);
			DialogBox (hInst,"About",hwnd,lpfnProc);
			FreeProcInstance((FARPROC) lpfnProc);
			break;
		case IDM_EXIT:
			PostMessage(hwnd,WM_CLOSE,0,0L);
			break;
		default:
			return(DefWindowProc(hwnd,msg,wParam,lParam));
		} /*end of case WM_COMMAND*/
		break;
	case WM_TIMER:
		/*timeout occured*/
		bReceiving=FALSE; /*reset state*/
		KillTimer(hwnd,TIMEOUT_ID); /*release timer*/
		MessageBox(hwnd,"no response from daytime server", "Timeout", MB_OK | MB_ICONASTERISK);
		break;
	case WM_QUERYENDSESSION:
	case WM_CLOSE:
		/*closing the socket...bye bye */
		if(!SendMessage(hwnd,WM_COMMAND,IDM_CLOSE,1L))
			DestroyWindow(hwnd);
		/*release timer if active*/
		if(bReceiving)
			KillTimer(hwndMain,TIMEOUT_ID);
		break;
	case WM_CREATE:
		/*center dialog box*/
		CenterWnd(hwnd, NULL, TRUE);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return(DefWindowProc(hwnd,msg,wParam,lParam));
		}
		/*end of switch(msg)*/
		return 0;
		}
Esempio n. 16
0
/*
 * AboutProc - callback routine for settings dialog
 */
WINEXPORT INT_PTR CALLBACK AboutProc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
{
    char        buff[256];
    LPABOUTINFO pai;

    lparam = lparam;

    switch( msg ) {
    case WM_INITDIALOG:
        pai = (LPABOUTINFO)lparam;
        if( pai->title != NULL ) {
            SetWindowText( hwnd, pai->title );
        }
        if( pai->name != NULL ) {
            sprintf( buff, banner1p1( "%s" ), pai->name );
            SetDlgItemText( hwnd, ABOUT_NAME, buff );
        }
        if( pai->version != NULL ) {
            SetDlgItemText( hwnd, ABOUT_VERSION, pai->version );
        }
        if( pai->first_cr_year != NULL ) {
#if defined( __WATCOMC__) && !defined( __ALPHA__ )
            if( _fstrcmp( pai->first_cr_year, CURR_YEAR ) ) {
#else
            if( strcmp( pai->first_cr_year, CURR_YEAR ) ) {
#endif
                sprintf( buff, banner2a( "%s" ), pai->first_cr_year );
            } else {
                strcpy( buff, banner2a( "1984" ) );
            }
            SetDlgItemText( hwnd, ABOUT_COPYRIGHT, buff );
        }
#if defined( __WINDOWS__ ) || defined( __WINDOWS_386__ )
        {
            DWORD       flags;
            DWORD       kfree;
            WORD        pcfree;
            SYSHEAPINFO shi;
            char        work[16];
            char        info[50];

            flags = GetWinFlags();
            if( flags & WF_ENHANCED ) {
                CopyRCString( ABT_386_ENH, info, sizeof( info ) );
            } else {
                CopyRCString( ABT_STD_MODE, info, sizeof( info ) );
            }
            SetDlgItemText( hwnd, ABOUT_INFO1, info );
            kfree = GetFreeSpace( 0 ) / 1024L;
            ltoa( kfree, work, 10 );
            RCsprintf( buff, ABT_MEM_X_KB_FREE, (LPSTR)work );
            SetDlgItemText( hwnd, ABOUT_INFO2, buff );

            shi.dwSize = sizeof( shi );
            if( SystemHeapInfo( &shi ) ) {
                pcfree = shi.wGDIFreePercent;
                if( pcfree > shi.wUserFreePercent )
                    pcfree = shi.wUserFreePercent;
                RCsprintf( buff, ABT_SYS_RESOURCES_FREE, pcfree );
            } else {
                CopyRCString( ABT_SYS_RESOURCES_N_A, buff, sizeof( buff ) );
            }
            SetDlgItemText( hwnd, ABOUT_INFO3, buff );
        }
#else
        {
            SYSTEM_INFO         si;
            MEMORYSTATUS        ms;

            GetSystemInfo( &si );
            switch( si.dwProcessorType ) {
            case PROCESSOR_INTEL_386:
                CopyRCString( ABT_RUNNING_ON_386, buff, sizeof( buff ) );
                break;
            case PROCESSOR_INTEL_486:
                CopyRCString( ABT_RUNNING_ON_486, buff, sizeof( buff ) );
                break;
            case PROCESSOR_INTEL_PENTIUM:
                CopyRCString( ABT_RUNNING_ON_586, buff, sizeof( buff ) );
                break;
            case PROCESSOR_MIPS_R4000:
            case PROCESSOR_ALPHA_21064:
            default:
                buff[0] = '\0';
                break;
            }
            SetDlgItemText( hwnd, ABOUT_INFO1, buff );

            ms.dwLength = sizeof( ms );
            GlobalMemoryStatus( &ms );
            RCsprintf( buff, ABT_VIRT_MEM,
                       (ms.dwAvailPhys + ms.dwAvailPageFile) / 1024L );
            SetDlgItemText( hwnd, ABOUT_INFO2, buff );
            RCsprintf( buff, ABT_MEM_LOAD, ms.dwMemoryLoad );
            SetDlgItemText( hwnd, ABOUT_INFO3, buff );

        }
#endif
        return( TRUE );
#ifndef NOUSE3D
    case WM_SYSCOLORCHANGE:
        CvrCtl3dColorChange();
        break;
#endif
    case WM_CLOSE:
        EndDialog( hwnd, 0 );
        break;
    case WM_COMMAND:
        switch( LOWORD( wparam ) ) {
        case IDOK:
        case IDCANCEL:
            EndDialog( hwnd, 0 );
            break;
        }
    }
    return( FALSE );

} /* AboutProc */

/*
 * DoAbout - show the startup dialog
 */
void DoAbout( LPABOUTINFO ai )
{
    FARPROC     proc;

    proc = MakeDlgProcInstance( AboutProc, ai->inst );
    DialogBoxParam( ai->inst, "About", ai->owner, (DLGPROC)proc, (LPARAM)ai );
    FreeProcInstance( proc );

} /* DoAbout */
Esempio n. 17
0
long WINAPI MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    FARPROC lpProcAbout;

    switch (message) {
    case WM_COMMAND:
        switch (wParam) {
        case IDM_ABOUT:
            lpProcAbout = MakeProcInstance((FARPROC)About, hInst);
            DialogBox(hInst, "AboutBox", hWnd, (DLGPROC)lpProcAbout);
            FreeProcInstance(lpProcAbout);
            break;
        /* RCS menu commands */
        case IDM_CHECKIN:
            RCSCheckin( Cookie, "foo.c", "", "" );
            break;
        case IDM_CHECKOUT:
            RCSCheckout( Cookie, "foo.c", "", "" );
            break;
        case IDM_RUNSHELL:
            RCSRunShell( Cookie );
            break;
        case IDM_SET_MKS_RCS:
            RCSSetSystem( Cookie, MKS_RCS );
            if( RCSQuerySystem( Cookie ) == MKS_RCS ) {
                SetWindowText( hwnd, "MKS RCS" );
            } else {
                SetWindowText( hwnd, "error setting RCS system" );
            }
            break;
        case IDM_SET_MKS_SI:
            RCSSetSystem( Cookie, MKS_SI );
            if( RCSQuerySystem( Cookie ) == MKS_SI ) {
                SetWindowText( hwnd, "MKS SI" );
            } else {
                SetWindowText( hwnd, "error setting RCS system" );
            }
            break;
        case IDM_SET_PVCS:
            RCSSetSystem( Cookie, PVCS );
            if( RCSQuerySystem( Cookie ) == PVCS ) {
                SetWindowText( hwnd, "PVCS" );
            } else {
                SetWindowText( hwnd, "error setting RCS system" );
            }
            break;
        case IDM_SET_WPROJ:
            RCSSetSystem( Cookie, WPROJ );
            if( RCSQuerySystem( Cookie ) == WPROJ ) {
                SetWindowText( hwnd, "WPROJ" );
            } else {
                SetWindowText( hwnd, "error setting RCS system" );
            }
            break;
        case IDM_SET_GENERIC:
            RCSSetSystem( Cookie, GENERIC );
            if( RCSQuerySystem( Cookie ) == GENERIC ) {
                SetWindowText( hwnd, "GENERIC" );
            } else {
                SetWindowText( hwnd, "error setting RCS system" );
            }
            break;
        case IDM_SET_PERFORCE:
            RCSSetSystem( Cookie, PERFORCE );
            if( RCSQuerySystem( Cookie ) == PERFORCE ) {
                SetWindowText( hwnd, "Perforce" );
            } else {
                SetWindowText( hwnd, "error setting RCS system" );
            }
            break;
        case IDM_QUERY_SYS:
            switch( RCSQuerySystem( Cookie ) ) {
                case NO_RCS: SetWindowText( hwnd, "none" ); break;
                case MKS_RCS: SetWindowText( hwnd, "mksrcs" ); break;
                case MKS_SI: SetWindowText( hwnd, "mkssi" ); break;
                case PVCS: SetWindowText( hwnd, "pvcs" ); break;
                case GENERIC: SetWindowText( hwnd, "GENERIC" ); break;
                case WPROJ: SetWindowText( hwnd, "wproj" ); break;
                case PERFORCE: SetWindowText( hwnd, "Perforce" ); break;
            }
            break;
        case IDM_EXIT:
            DestroyWindow(hWnd);
            break;
        }
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return (DefWindowProc(hWnd, message, wParam, lParam));
    }
    return (NULL);
}
Esempio n. 18
0
/*
 * WindowProc - handle messages for the main application window
 */
LONG _EXPORT FAR PASCAL WindowProc( HWND hwnd, unsigned msg,
                                     WORD wparam, LONG lparam )
{
    FARPROC     proc;
    HANDLE      hinst;
    LPEDATA     ed;
    DWORD       sel;
    int         state;
    HDC         hdc;

    ed = (LPEDATA) GetWindowLong( hwnd, EXTRA_DATA_OFFSET );

    /*
     * all messages are in alphabetical order, except WM_COMMAND, at the end
     */
    switch( msg ) {
    case WM_CLOSE:
        /*
         * see if it is okay to close down
         */
        if( CheckFileSave( ed ) ) {
            DestroyWindow( hwnd );
        }
        break;

    case WM_CREATE:
        /*
         * try to get printer support.  If it works, delete the DC,
         * since these are a system resource
         */
        hdc = PrinterDC();
        if( hdc ) {
            DeleteDC( hdc );
        }
        break;

    case WM_DESTROY:
        if( ed->font != NULL ) DeleteObject( ed->font );
        PostQuitMessage( 0 );
        break;

    case WM_DEVMODECHANGE:
    case WM_WININICHANGE:
        /*
         * handle user changing printer info
         */
        hdc = PrinterDC();
        if( hdc ) {
            DeleteDC( hdc );
        }
        break;

    case WM_FONTCHANGE:
        GetAllFonts( ed );
        break;

    case WM_INITMENU:
        /*
         * initial menu state set here
         */
        if( wparam == GetMenu( hwnd ) ) {

            state = MF_GRAYED;
            if( OpenClipboard( ed->hwnd ) ) {
                if( IsClipboardFormatAvailable( CF_TEXT ) ||
                    IsClipboardFormatAvailable( CF_OEMTEXT )) {
                    state = MF_ENABLED;
                }
                CloseClipboard();
            }
            EnableMenuItem( wparam, MENU_PASTE, state );

            state = MF_GRAYED;
            if( SendMessage( ed->editwnd, EM_CANUNDO, 0, 0L ) ) {
                state = MF_ENABLED;
            }
            EnableMenuItem( wparam, MENU_UNDO, state );
            sel = SendMessage( ed->editwnd, EM_GETSEL, 0, 0L );

            state = MF_GRAYED;
            if( HIWORD( sel ) != LOWORD( sel ) ) state = MF_ENABLED;
            EnableMenuItem( wparam, MENU_CLEAR, state );
            EnableMenuItem( wparam, MENU_COPY, state );
            EnableMenuItem( wparam, MENU_CUT, state );

            state = MF_GRAYED;
            if( PrinterSupport != PSUPP_NONE ) state = MF_ENABLED;
            EnableMenuItem( wparam, MENU_PRINT, state );
            state = MF_GRAYED;
            if( PrinterSupport == PSUPP_CANPRINTANDSET ) state = MF_ENABLED;
            EnableMenuItem( wparam, MENU_PRINT_SETUP, state );

        }
        return( NULL );

    case WM_QUERYENDSESSION:
        /*
         * check if it is okay to end the session
         */
        return( CheckFileSave( ed ) );

    case WM_SETFOCUS:
        /*
         * move the focus to our editor, rather than to the frame
         */
        SetFocus( ed->editwnd );
        break;

    case WM_SIZE:
        /*
         * resize edit window to match size of our client area
         */
        MoveWindow( ed->editwnd, 0, 0, LOWORD( lparam ),
                        HIWORD( lparam ), TRUE );
        break;


    case WM_COMMAND:
        switch( wparam ) {
        case EDIT_ID:
            switch( HIWORD( lparam ) ){
            case EN_CHANGE:
                ed->needs_saving = TRUE;
                break;
            case EN_ERRSPACE:
                MessageBox( hwnd, "Out of Space", EditTitle, MB_OK );
                break;
            }
            break;
        case MENU_ABOUT:
            hinst = GetWindowWord( hwnd, GWW_HINSTANCE );
            proc = MakeProcInstance( (FARPROC)AboutDlgProc, hinst );
            DialogBox( hinst,"AboutBox", hwnd, (DLGPROC)proc );
            FreeProcInstance( proc );
            break;
        case MENU_CLEAR:
            SendMessage( ed->editwnd, EM_REPLACESEL, 0, (LONG) (LPSTR)"" );
            break;
        case MENU_COPY:
            SendMessage( ed->editwnd, WM_COPY, 0, 0L );
            break;
        case MENU_CUT:
            SendMessage( ed->editwnd, WM_CUT, 0, 0L );
            break;
        case MENU_EXIT:
            if( CheckFileSave( ed ) ) {
                DestroyWindow( hwnd );
            }
            break;
        case MENU_FONT_SELECT:
            FontSelect( ed );
            break;
        case MENU_NEW:
            FileEdit( ed, FALSE );
            break;
        case MENU_OPEN:
            FileEdit( ed, TRUE );
            break;
        case MENU_PASTE:
            SendMessage( ed->editwnd, WM_PASTE, 0, 0L );
            break;
        case MENU_PRINT:
            Print( ed );
            break;
        case MENU_PRINT_SETUP:
            GetPrinterSetup( hwnd );
            break;
        case MENU_SAVE:
            FileSave( ed, FALSE );
            break;
        case MENU_SAVE_AS:
            FileSave( ed, TRUE );
            break;
        case MENU_UNDO:
            SendMessage( ed->editwnd, EM_UNDO, 0, 0L );
            break;
        }
        break;

    default:
        return( DefWindowProc( hwnd, msg, wparam, lparam ) );
    }
    return( 0L );

} /* WindowProc */
Esempio n. 19
0
char *WREGetFileName( WREGetFileStruct *gf, DWORD flags, WREGetFileAction action )
{
    OPENFILENAME  wreofn;
    HWND          owner_window;
    Bool          ret;
    DWORD         error;
    int           len;
    char          fn_drive[_MAX_DRIVE];
    char          fn_dir[_MAX_DIR];
    char          fn_name[_MAX_FNAME];
    char          fn_ext[_MAX_EXT + 1];
    HINSTANCE     app_inst;

    if( gf == NULL ) {
        return( NULL );
    }

    owner_window = WREGetMainWindowHandle();
    app_inst = WREGetAppInstance();

    if( app_inst == NULL || owner_window == NULL ) {
        return( NULL );
    }

    if( gf->title != NULL ) {
        len = strlen( gf->title );
        if( len < _MAX_PATH ) {
            memcpy( wrefntitle, gf->title, len + 1 );
        } else {
            memcpy( wrefntitle, gf->title, _MAX_PATH );
            wrefntitle[_MAX_PATH - 1] = 0;
        }
    } else {
        wrefntitle[0] = 0;
    }

    if( gf->file_name != NULL && *gf->file_name != '\0' ) {
        _splitpath( gf->file_name, fn_drive, fn_dir, fn_name, fn_ext );
        if( *fn_drive != '\0' || *fn_dir != '\0' ) {
            _makepath( wre_initial_dir, fn_drive, fn_dir, NULL, NULL );
        }
        _makepath( wre_file_name, NULL, NULL, fn_name, fn_ext );
    } else {
        wre_file_name[0] = 0;
    }

    /* set the initial directory */
    if( *wre_initial_dir == '\0' ) {
        getcwd( wre_initial_dir, _MAX_PATH );
    }

#if !defined ( __NT__ )
    // CTL3D no longer requires this
    flags |= OFN_ENABLEHOOK;
#endif

    /* initialize the OPENFILENAME struct */
    memset( &wreofn, 0, sizeof( OPENFILENAME ) );

    /* fill in non-variant fields of OPENFILENAME struct */
    wreofn.lStructSize = sizeof( OPENFILENAME );
    wreofn.hwndOwner = owner_window;
    wreofn.hInstance = app_inst;
    wreofn.lpstrFilter = gf->filter;
    wreofn.lpstrCustomFilter = NULL;
    wreofn.nMaxCustFilter = 0;
    wreofn.nFilterIndex = WREFindFileFilterIndex( gf->filter );
    wreofn.lpstrFile = wre_file_name;
    wreofn.nMaxFile = _MAX_PATH;
    wreofn.lpstrFileTitle = wrefntitle;
    wreofn.nMaxFileTitle = _MAX_PATH;
    wreofn.lpstrInitialDir = wre_initial_dir;
    wreofn.lpstrTitle = wrefntitle;
    wreofn.Flags = flags;
    wreofn.lpfnHook = (LPVOID)MakeProcInstance( (LPVOID)WREOpenHookProc, app_inst );

#if 0
    wreofn.nFileOffset = 0L;
    wreofn.nFileExtension = 0L;
    wreofn.lpstrDefExt = NULL;
    wreofn.lCustData = NULL;
    wreofn.lpTemplateName = NULL;
#endif

    if( action == OPENFILE ) {
        ret = GetOpenFileName( (LPOPENFILENAME)&wreofn );
    } else if( action == SAVEFILE ) {
        ret = GetSaveFileName( (LPOPENFILENAME)&wreofn );
    } else {
        return( NULL );
    }

#ifndef __NT__
    if( wreofn.lpfnHook != NULL ) {
        FreeProcInstance( (FARPROC)wreofn.lpfnHook );
    }
#endif

    if( !ret ) {
        error = CommDlgExtendedError();
        if( error ) {
            WREDisplayErrorMsg( WRE_ERRORSELECTINGFILE );
        }
        return( NULL );
    } else {
        memcpy( wre_initial_dir, wre_file_name, wreofn.nFileOffset );
        if( wre_initial_dir[wreofn.nFileOffset - 1] == '\\' &&
            wre_initial_dir[wreofn.nFileOffset - 2] != ':' ) {
            wre_initial_dir[wreofn.nFileOffset - 1] = '\0';
        } else {
            wre_initial_dir[wreofn.nFileOffset] = '\0';
        }
        if( gf->save_ext ) {
            _splitpath( wre_file_name, NULL, NULL, NULL, fn_ext + 1 );
            if( fn_ext[1] != '\0' ) {
                fn_ext[0] = '*';
                WRESetFileFilter( fn_ext );
            } else {
                char *out_ext;
                out_ext = WREFindFileFilterFromIndex( gf->filter, wreofn.nFilterIndex );
                if( out_ext[2] != '*' ) {
                    strcat( wre_file_name, &out_ext[1] );
                }
            }
        }
    }

    UpdateWindow( WREGetMainWindowHandle() );

    return( WREStrDup( wre_file_name ) );
}
Esempio n. 20
0
LONG WINAPI MainWndProc(HWND hWnd, UINT message, WPARAM wPrm, LONG lPrm)
{
  DLGPROC lpProcAbout;
  FILE *fp;

  switch(message) {
  case WM_COMMAND:
    switch (GET_WM_COMMAND_ID(wPrm, lPrm)) {
    case IDM_ABOUT:
      lpProcAbout = (DLGPROC) MakeProcInstance((FARPROC) About, hInst);
      DialogBox(hInst, "AboutBox", hWnd, lpProcAbout);
      (void) FreeProcInstance((FARPROC) lpProcAbout);
      break;
    case IDM_NEW:
      if (! QuerySaveFile()) return(FALSE);
      bChanges = FALSE;
      FileName[0] = 0;
      SetNewBuffer(NULL, Untitled);
      break;
    case IDM_OPEN:
      if (! QuerySaveFile())
        return FALSE;
      if (! OpenDlg() || (fp = fopen(FileName, "r")) == NULL)
        return FALSE;
      ReanInFile(fp);
      return FALSE;
    case IDM_SAVE:
      if (! FileName[0]) goto saveas;
      if (bChanges) SaveFile();
      break;
    case IDM_SAVEAS:
saveas:
      if (SaveAsDlg()) {
	sprintf(buf, "LSPEdit - %s", FileName);
	if (SaveFile())
          SetWindowText(hWnd, buf);
        else {
          FileName[0] = 0;
          SetWindowText(hWnd, Untitled);
        }
      }
      break;
    case IDM_PRINT:
      WarningBox("Command Not Implemented");
      break;
    case IDM_EXIT:
      if (! QuerySaveFile()) return FALSE;
      DestroyWindow(hWnd);
      break;
    case IDM_UNDO:
      WarningBox("Command Not Implemented");
      break;
    case IDM_CUT:
      TTYSelToClip();
      TTYClearSel();
      break;
    case IDM_COPY:
      TTYSelToClip();
      break;
    case IDM_PASTE:
      TTYPasteFromClip();
      break;
    case IDM_CLEAR:
      TTYClearSel();
      break;
    case IDM_EVAL:
      {
        HSZ service, topic;
        HCONV hconv;

        service = DdeCreateStringHandle(ddeInst, "XLISP-STAT", CP_WINANSI);
        topic = DdeCreateStringHandle(ddeInst, "XLISP-STAT", CP_WINANSI);
        if ((hconv = DdeConnect(ddeInst, service, topic, NULL)) == NULL)
          WarningBox("Can't connect to XLISP-STAT");
        else {
          /**** switch to allocated buffer? */
          char *data = TTYSelectionStr();
          if (! DdeClientTransaction((LPVOID) data, strlen(data) + 1,
                                     hconv, NULL, CF_TEXT, XTYP_EXECUTE,
                                     60000L, NULL))
            WarningBox("Transaction failed");
          DdeDisconnect(hconv);
        }
        DdeFreeStringHandle(ddeInst, service);
        DdeFreeStringHandle(ddeInst, topic);
      }
      break;
    case IDC_EDIT:
      if (GET_WM_COMMAND_CMD(wPrm, lPrm) == EN_ERRSPACE) {
	WarningBox("Out of memory");
      }
      if (GET_WM_COMMAND_CMD(wPrm, lPrm) == EN_CHANGE) bChanges = TRUE;
      break;
    default: return(DefWindowProc(hWnd, message, wPrm, lPrm));
    }
    break;
  case WM_SETFOCUS:
    SetFocus(hEditWnd);
    break;
  case WM_SIZE:
    MoveWindow(hEditWnd, 0, 0, LOWORD(lPrm), HIWORD(lPrm), TRUE);
    break;
  case WM_QUERYENDSESSION:
    return(QuerySaveFile());
  case WM_CLOSE:
    if (QuerySaveFile()) DestroyWindow(hWnd);
    break;
  case WM_DESTROY:
    PostQuitMessage(0);
    break;
  default:
    return(DefWindowProc(hWnd, message, wPrm, lPrm));
  }
  return FALSE;
}
Esempio n. 21
0
LRESULT CALLBACK WndProc(
      HWND hWnd,         // window handle
      UINT message,      // type of message
      WPARAM uParam,     // additional information
      LPARAM lParam      // additional information
      )
{
   FARPROC lpProcAbout;  // pointer to the "About" function
   int wmId, wmEvent;

//****************** NEW CODE START *********

#define ptrNMHDR       ((LPNMHDR)lParam)
#define ptrNM_TREEVIEW ((NM_TREEVIEW *)lParam)
#define ptrTV_DISPINFO ((TV_DISPINFO *)lParam)

          RECT       rcItem;
   static HIMAGELIST hDragImage;
   static BOOL       bDragging;
   static HTREEITEM  hDragItem;

   switch (message) {

      case WM_NOTIFY: // This is a new Chicago message for control
                      // notifications

         switch (ptrNMHDR->code)
           {
           case TVN_BEGINDRAG: // Sent by TreeView when user
                               // wants to drag an item.

             // Only allow drag & drop for the actual coaster
             // items. The "itemNew" field of the NM_TREEVIEW
             // structure contains the attribytes of the item
             // we are going to drag. Therefore, since we are
             // using the lParam field to store an ITEM_TYPE_*
             // value, we check that field.

             if ( ITEM_TYPE_COASTER_NAME == ptrNM_TREEVIEW->itemNew.lParam)
               {
               // The hDragImage variable is declared static,
               // so the code in WM_LBUTTONUP can delete it when
               // the user stops dragging. Here we create a
               // drag image to use for the ImageList_StartDrag
               // API.

               hDragImage = TreeView_CreateDragImage
                              (
                              ptrNMHDR->hwndFrom,
                              ptrNM_TREEVIEW->itemNew.hItem
                              );

               // Get the location of the item rectangle's text.

               TreeView_GetItemRect
                 (
                 ptrNMHDR->hwndFrom,            // Handle of TreeView
                 ptrNM_TREEVIEW->itemNew.hItem, // Item in TreeView
                 &rcItem,                       // RECT to store result
                 TRUE                           // Rect of label text only
                 );

               // Cache away the handle of the item to drag into a
               // staticly declared variable, so the code in
               // WM_LBUTTONUP can know what the user is dragging.

               hDragItem = ptrNM_TREEVIEW->itemNew.hItem;

               // Start the drag ala ImageList

               ImageList_BeginDrag(hDragImage, 0,
                 ptrNM_TREEVIEW->ptDrag.x - rcItem.left, // Offset hotspot
                 ptrNM_TREEVIEW->ptDrag.y - rcItem.top);


               ImageList_DragEnter(ptrNMHDR->hwndFrom,
                 ptrNM_TREEVIEW->ptDrag.x,  // Coords of image to drag
                 ptrNM_TREEVIEW->ptDrag.y);

               // Capture the mousey to this window

               ShowCursor ( FALSE );
               SetCapture ( hWnd );

               // Set a staticly declared drag flag so the WM_MOUSEMOVE
               // and WM_LBUTTONUP messages know to take action.

               bDragging = TRUE;
               }

             return 0L;  // Return value is irrelevant

           case TVN_GETDISPINFO: // Sent by TreeView just before it paints
                                 // an item declared with callback values.

             // Our "state" items have the I_IMAGECALLBACK value
             // used for the iImage and iSelectedImage fields. This
             // TVN_GETDISPINFO code will be called whenever the
             // item is about to be drawn. It is out responsibility
             // to add code to fill in the images. The code below
             // uses a different image depending on if the item is
             // expanded or collapsed. That attribute is in the
             // state field of the item passed in the TV_DISPINFO
             // structure.

             // Our lParam is where we store what state the item
             // represents. Therefore, we will switch on that so
             // we can indicate the correct image to use.

             if ( ptrTV_DISPINFO->item.state & TVIS_EXPANDED )
               {
               switch (ptrTV_DISPINFO->item.lParam)
                 {
                 case ITEM_TYPE_STATE_CA:

                   ptrTV_DISPINFO->item.iImage =
                   ptrTV_DISPINFO->item.iSelectedImage = iImageCA_OPEN;
                   break;

                 case ITEM_TYPE_STATE_NY:

                   ptrTV_DISPINFO->item.iImage =
                   ptrTV_DISPINFO->item.iSelectedImage = iImageNY_OPEN;
                   break;

                 case ITEM_TYPE_STATE_OH:

                   ptrTV_DISPINFO->item.iImage =
                   ptrTV_DISPINFO->item.iSelectedImage = iImageOH_OPEN;
                   break;
                 }
               }
             else  // Collapsed item
               {
               switch (ptrTV_DISPINFO->item.lParam)
                 {
                 case ITEM_TYPE_STATE_CA:

                   ptrTV_DISPINFO->item.iImage =
                   ptrTV_DISPINFO->item.iSelectedImage = iImageCA;
                   break;

                 case ITEM_TYPE_STATE_NY:

                   ptrTV_DISPINFO->item.iImage =
                   ptrTV_DISPINFO->item.iSelectedImage = iImageNY;
                   break;

                 case ITEM_TYPE_STATE_OH:

                   ptrTV_DISPINFO->item.iImage =
                   ptrTV_DISPINFO->item.iSelectedImage = iImageOH;
                   break;
                 }
               }
             return TRUE;

           case TVN_BEGINLABELEDIT: // Sent by TreeView when user single
                                    // clicks on an item in a TreeView
                                    // that has the TVS_EDITLABELS style
                                    // bit set.

             // Only allow label editing for the coaster names

             if (ITEM_TYPE_COASTER_NAME == ptrTV_DISPINFO->item.lParam)
               return 0;  // Return 0 to OK edit
             else
               return 1;  // Return non-zero to disallow edit
             break;

           case TVN_ENDLABELEDIT:   // Sent by TreeView when user presses
                                    // the ENTER key or ESC key, to end
                                    // an in-place edit session. If the user
                                    // pressed the ESC key, the pszText
                                    // field of the item in the TV_DISPINFO
                                    // field is NULL.

             // if user pressed ENTER to accept edits


             if ( ptrTV_DISPINFO->item.pszText)
               {
               // Set the "change mask" to indicate that the only attribute
               // we wish to change is the text field. The TV_DISPINFO
               // structure has already been filled out with the new
               // text the user typed in, we just need to pass that on
               // to the TreeView control. This is our chance to evaluate
               // the contents of this field and change it.


               ptrTV_DISPINFO->item.mask = TVIF_TEXT;

               TreeView_SetItem
                 (
                   ptrNMHDR->hwndFrom,      // Handle of TreeView
                   &(ptrTV_DISPINFO->item)  // TV_ITEM structure w/changes
                 );
               }
             break;

           }

         return (DefWindowProc(hWnd, message, uParam, lParam));

      case WM_MOUSEMOVE: // Since the mouse capture is set to this
                         // window while we do our drag & drop,
                         // we check for the drag flag and process
                         // the WM_MOUSEMOVE message.

         if (bDragging)
           {
           HTREEITEM       hTarget;  // Item under mouse
           TV_HITTESTINFO  tvht;     // Used for hit testing

           // Do standard drag drop movement

           ImageList_DragMove ( LOWORD (lParam), HIWORD (lParam));

           // Fill out hit test struct with mouse pos

           tvht.pt.x = LOWORD (lParam);
           tvht.pt.y = HIWORD (lParam);

           // Check to see if an item lives under the mouse

           if ( hTarget = TreeView_HitTest
                            (
                            hWndTreeView,  // This is the global variable
                            &tvht          // TV_HITTESTINFO struct
                            )
              )
             {
             TV_ITEM         tvi;           // Temporary Item

             tvi.mask       = TVIF_PARAM; // We want to fetch the
                                          // lParam field.

             tvi.hItem      = hTarget;    // Set the handle of the
                                          // item to fetch.

             TreeView_GetItem ( hWndTreeView, &tvi ); // Fetch, spot!

             // Check to see if the lParam is a valid item to drop
             // onto (in this case, another roller coaster, such as
             // the Coney Island Cyclone). Skip this operation if
             // the item is already selected (to avoid flicker)

             if ( ITEM_TYPE_COASTER_NAME == tvi.lParam )
               {
               if ( hTarget != TreeView_GetDropHilight (hWndTreeView))
                 {
                 // Hide the drag image
                 ImageList_DragShowNolock ( FALSE );  //DragShow to DragShowNoLock lithangw
                 // Select the item
                 TreeView_SelectDropTarget ( hWndTreeView, hTarget );
                 // Show the drag image
                 ImageList_DragShowNolock ( TRUE ); //DragShow to DragShowNoLock lithangw
                 }
               return 0L;
               }
             }

           // If we made it here, then the user has either
           // dragged the mouse over an invalid item, or no item.
           // Hide any current drop target, this is a no-no drop
           ImageList_DragShowNolock ( FALSE );  //screen update problem tokuroy
           TreeView_SelectDropTarget ( hWndTreeView, NULL );
           ImageList_DragShowNolock ( TRUE );   //screen update problem tokuroy
           }
         break;

      case WM_LBUTTONUP: // Since the mouse capture is set to this
                         // window while we do our drag & drop,
                         // we check for the drag flag and process
                         // the WM_LBUTTONUP message.


         if (bDragging)
           {
           HTREEITEM       hTarget;       // Item under mouse
           TV_ITEM         tvi;           // Temporary Item
           TV_INSERTSTRUCT tvIns;         // Insert struct
           char            szBuffer[256]; // Item text buffer

           // End the drag
           ImageList_EndDrag();
           // Bring back the cursor
           ShowCursor ( TRUE );
           // Release the mouse capture
           ReleaseCapture();
           // Clear the drag flag
           bDragging = FALSE;
           // Clean up the image list object
           ImageList_Destroy ( hDragImage );
           hDragImage = NULL;

           // First, check to see if there is a valid drop point.
           // The cheezy way to do this is to check for a highlighted
           // drop target, since the logic to validate drop points
           // is in the WM_MOUSEMOVE. Duping that code here would
           // be a headache.

           if ( hTarget = TreeView_GetDropHilight (hWndTreeView))
             {
             // If we made it here, then we need to move the item.
             // First, we will fetch it, specifying the attributes
             // we need to copy.

             tvi.mask       = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
             tvi.hItem      = hDragItem;
             tvi.pszText    = szBuffer;
             tvi.cchTextMax = sizeof(szBuffer);

             TreeView_GetItem ( hWndTreeView, &tvi );

             // Now, figure the new place to put it by filling out
             // the TV_INSERTSTRUCT structure, to use the drop target
             // as the sibling to insert after, and using the drop
             // target's parent as the parent to insert this one
             // after as well.

             tvIns.hParent         = TreeView_GetParent ( hWndTreeView, hTarget );
             tvIns.hInsertAfter    = hTarget;
             tvIns.item            = tvi;

             // Delete the old item

             TreeView_DeleteItem ( hWndTreeView, hDragItem );

             // And add the new item (if your app tracks the handles of
             // the items, you want to use the return value
             // of this function to update your data structure that
             // tracks the handles.

             TreeView_InsertItem ( hWndTreeView, &tvIns );
             }

           // Clear any drop highlights on the TreeView

           TreeView_SelectDropTarget ( hWndTreeView, NULL );
           }
         break;

      case WM_SIZE:

         if ( hWndTreeView )     // Standard code to keep the TreeView
                                 // sized up with the main window
           {
           SetWindowPos ( hWndTreeView,
                          NULL,
                          0, 0,
                          LOWORD (lParam),
                          HIWORD (lParam),
                          SWP_NOZORDER
                        );
           }
         break;

//****************** NEW CODE END *********

      case WM_COMMAND:  // message: command from application menu

         // Message packing of uParam and lParam have changed for Win32,
         // let us handle the differences in a conditional compilation:
         #if defined (_WIN32)
             wmId    = LOWORD(uParam);
			    wmEvent = HIWORD(uParam);
         #else
            wmId    = uParam;
            wmEvent = HIWORD(lParam);
         #endif

         switch (wmId) {
            case IDM_ABOUT:
               lpProcAbout = MakeProcInstance((FARPROC)About, hInst);

               DialogBox(hInst,           // current instance
                  "AboutBox",             // dlg resource to use
                  hWnd,                   // parent handle
                  (DLGPROC)lpProcAbout);  // About() instance address

               FreeProcInstance(lpProcAbout);
               break;

            case IDM_EXIT:
               DestroyWindow (hWnd);
               break;

            case IDM_HELPCONTENTS:
               if (!WinHelp (hWnd, "TREEVIEW.HLP", HELP_KEY,(DWORD)(LPSTR)"CONTENTS")) {
                  MessageBox (GetFocus(),
                     "Unable to activate help",
                     szAppName, MB_SYSTEMMODAL|MB_OK|MB_ICONHAND);
				
               }
               break;

            case IDM_HELPSEARCH:
               if (!WinHelp(hWnd, "TREEVIEW.HLP", HELP_PARTIALKEY, (DWORD)(LPSTR)"")) {
                  MessageBox (GetFocus(),
                     "Unable to activate help",
                     szAppName, MB_SYSTEMMODAL|MB_OK|MB_ICONHAND);
               }
               break;

            case IDM_HELPHELP:
               if(!WinHelp(hWnd, (LPSTR)NULL, HELP_HELPONHELP, 0)) {
                  MessageBox (GetFocus(),
                     "Unable to activate help",
                     szAppName, MB_SYSTEMMODAL|MB_OK|MB_ICONHAND);
               }
               break;

            // Here are all the other possible menu options,
            // all of these are currently disabled:
            case IDM_NEW:
            case IDM_OPEN:
            case IDM_SAVE:
            case IDM_SAVEAS:
            case IDM_UNDO:
            case IDM_CUT:
            case IDM_COPY:
            case IDM_PASTE:
            case IDM_LINK:
            case IDM_LINKS:

            default:
               return (DefWindowProc(hWnd, message, uParam, lParam));
         }
         break;

      case WM_DESTROY:  // message: window being destroyed

         PostQuitMessage(0);
         break;

      default:          // Passes it on if unproccessed
         return (DefWindowProc(hWnd, message, uParam, lParam));
   }
   return (0);
}
Esempio n. 22
0
/*
 * StatDialog - show task status
 */
BOOL CALLBACK StatDialog( HWND hwnd, UINT msg,WPARAM  wparam, LPARAM lparam )
{
    WORD        cmd;
    FARPROC     fp;
    StatData    *statdata;

    statdata = (StatData *)GetWindowLong( hwnd, DWL_USER );
    fp = fp;
    switch( msg ) {
    case STAT_FOREGROUND:
#ifdef __NT__
        SetForegroundWindow( hwnd );
#else
        SetActiveWindow( hwnd );
#endif
        break;
    case WM_INITDIALOG:
        InitStatDialog( hwnd );
        return( FALSE );
    case STAT_MAD_NOTIFY:
        switch( wparam ) {
        case MNT_REDRAW_REG:
        case MNT_MODIFY_REG:
            DoUpdateWalk( hwnd, (mad_reg_set_data *)lparam );
            break;
        case MNT_MODIFY_IP:
        case MNT_REDRAW_DISASM:
            DisplayAsmLines( hwnd, &( statdata->curr_addr ) );
            break;
        }
        break;
    case WM_VSCROLL:
        ScrollAsmDisplay( hwnd, wparam, &( statdata->curr_addr ) );
        break;
    case WM_CLOSE:
        PostMessage( hwnd, WM_COMMAND, IDCANCEL, 0L );
        return( TRUE );
    case WM_DESTROY:
        StatHdl = NULL;
        MemFree( statdata );
        break;
    case WM_COMMAND:
        if( HIWORD( wparam ) == CBN_SELCHANGE ) {
            SwitchRegSets( hwnd, statdata );
            break;
        }
        cmd = LOWORD( wparam );
        switch( cmd ) {
#ifndef __NT__
        case STAT_SEG_MAP:
            fp = MakeProcInstance( SegMapDlgProc, Instance );
            JDialogBox( Instance, "SEG_MAP_DLG", hwnd, fp );
            FreeProcInstance( fp );
            break;
        case STAT_STACK_TRACE:
            StartStackTraceDialog( hwnd );
            break;
#else
        case STAT_SEG_MAP:
            {
                HANDLE                  hdl;
                ExceptDlgInfo * info;

                info = StatGetExceptDlgInfo( hwnd );

                DuplicateHandle(
                            GetCurrentProcess(),
                            info->procinfo->prochdl,
                            GetCurrentProcess(),
                            &hdl,
                            0,
                            FALSE,
                            DUPLICATE_SAME_ACCESS );
                WalkMemory( hwnd, hdl, info->procinfo->procid );
            }
            break;
#endif
        case STAT_SYMBOLS:
            if( StatShowSymbols == TRUE ) {
                StatShowSymbols = FALSE;
            } else {
                StatShowSymbols = TRUE;
            }
            DisplayAsmLines( hwnd, &( statdata->curr_addr ) );
            break;
        case IDCANCEL:
            EndDialog( hwnd, 0 );
            return( TRUE );
        case IDOK:
            EndDialog( hwnd, 1 );
            return( TRUE );
        }
    }
    return( FALSE );

} /* StatDialog */
Esempio n. 23
0
//-----------------Dialog boxes--------------------------
TDialog::~TDialog ()
 { FreeProcInstance((DLGPROC)m_lpfnBox); }
Esempio n. 24
0
/*
 * WindowProc - handle messages for the main application window
 */
LONG _EXPORT FAR PASCAL WindowProc( HWND window_handle, unsigned msg,
                                     WORD wparam, LONG lparam )
/*************************************************************/
{
    FARPROC             proc;
    HANDLE              inst_handle;
    extra_data          *edata_ptr;
    HDC                 hdc;
    PAINTSTRUCT         ps;
    RECT                rect;
    HBRUSH              brush;

    /*
     * if the message window is ON, send all messages we want to display to the
     * message window, so that we can see what is happening
     * ( before we actually process the message )
     */
    if( MessagesOn ) {
        switch( msg ) {
        case WM_COMMAND:
        case WM_MOUSEMOVE:
        case WM_LBUTTONUP:
        case WM_LBUTTONDOWN:
        case WM_LBUTTONDBLCLK:
        case WM_RBUTTONUP:
        case WM_RBUTTONDOWN:
        case WM_RBUTTONDBLCLK:
        case WM_KEYDOWN:
        case WM_KEYUP:
        case WM_CHAR:
        case WM_TIMER:
        case WM_HSCROLL:
        case WM_VSCROLL:
            SendMessage( MessageWnd, msg, wparam, lparam );
            break;
        }
    }

    /*
     * now process the message
     */
    switch( msg ) {
    case WM_CREATE:
        inst_handle = GetWindowWord( window_handle, GWW_HINSTANCE );
        /*
         * make sure message window is turned OFF to start
         */
        MessagesOn = FALSE;
        CheckMenuItem ( GetMenu( window_handle ), MENU_MESSAGE_WINDOW_ON,
                        MF_BYCOMMAND | MF_UNCHECKED );
        break;
    case WM_LBUTTONDOWN:
        /*
         * zap the target with a lightning bolt!
         */
        edata_ptr = (extra_data *) GetWindowLong( window_handle,
                                            EXTRA_DATA_OFFSET );
        /*
         * set the aim point to where the mouse was just clicked
         * set the bolt start point to the top left corner of the window
         */
        edata_ptr->aim = MAKEPOINT( lparam );
        edata_ptr->bolt.x = edata_ptr->client_rect.right - BOLTWIDTH;
        edata_ptr->bolt.y = edata_ptr->client_rect.top;
        /*
         * shoot the bolt from the current bolt position to the aim point
         */
        ShootBolt( window_handle );
        break;
    case WM_SIZE:
        edata_ptr = (extra_data *) GetWindowLong( window_handle,
                                            EXTRA_DATA_OFFSET );
        /*
         * store the new size of the window
         */
        GetClientRect( window_handle, &edata_ptr->client_rect );
        SetScrollRange( window_handle, SB_HORZ, edata_ptr->client_rect.left,
                        edata_ptr->client_rect.right, TRUE );
        SetScrollRange( window_handle, SB_VERT, edata_ptr->client_rect.top,
                        edata_ptr->client_rect.bottom, TRUE );
        break;
    case WM_COMMAND:
        switch( wparam ) {
        case MENU_ABOUT:
            inst_handle = GetWindowWord( window_handle, GWW_HINSTANCE );
            proc = MakeProcInstance( (FARPROC)About, inst_handle );
            DialogBox( inst_handle,"AboutBox", window_handle, (DLGPROC)proc );
            FreeProcInstance( proc );
            break;
        case MENU_EXIT:
            SendMessage( window_handle, WM_CLOSE, 0, 0L );
            break;
        case MENU_SET_TARGET_SPEED:
            inst_handle = GetWindowWord( window_handle, GWW_HINSTANCE );
            proc = MakeProcInstance( (FARPROC)SpeedDlgProc, inst_handle );
            DialogBoxParam( inst_handle,"SpeedDlg", window_handle, (DLGPROC)proc,
                            (DWORD)SET_TARGET_SPEED );
            FreeProcInstance( proc );
            break;
        case MENU_SET_BOLT_SPEED:
            inst_handle = GetWindowWord( window_handle, GWW_HINSTANCE );
            proc = MakeProcInstance( (FARPROC)SpeedDlgProc, inst_handle );
            DialogBoxParam( inst_handle,"SpeedDlg", window_handle, (DLGPROC)proc,
                            (DWORD)SET_BOLT_SPEED );
            FreeProcInstance( proc );
            break;
        case MENU_SCORE_WINDOW_ON:
            /*
             * toggle the score window on or off
             */
            edata_ptr = (extra_data *) GetWindowLong( window_handle,
                                                EXTRA_DATA_OFFSET );
            if( !edata_ptr->score_on ) {
                TurnScoreWindowOn( window_handle );
                CheckMenuItem ( GetMenu( window_handle ),
                                wparam, MF_BYCOMMAND | MF_CHECKED );
                edata_ptr->score_on = TRUE;
            } else {
                SendMessage( ScoreWnd, WM_CLOSE, 0, 0L );
                CheckMenuItem ( GetMenu( window_handle ), wparam,
                    MF_BYCOMMAND | MF_UNCHECKED );
                edata_ptr->score_on = FALSE;
            }
            break;
        case MENU_SOUND_ON:
            /*
             * toggle the sound on or off
             */
            edata_ptr = (extra_data *) GetWindowLong( window_handle,
                                                EXTRA_DATA_OFFSET );
            if( !edata_ptr->sound_on ) {
                CheckMenuItem ( GetMenu( window_handle ),
                                wparam, MF_BYCOMMAND | MF_CHECKED );
                edata_ptr->sound_on = TRUE;
            } else {
                CheckMenuItem ( GetMenu( window_handle ), wparam,
                    MF_BYCOMMAND | MF_UNCHECKED );
                edata_ptr->sound_on = FALSE;
            }
            break;
        case MENU_MESSAGE_WINDOW_ON:
            /*
             * toggle the message window on or off
             */
            if( !MessagesOn ) {
                TurnMessageWindowOn( window_handle );
                CheckMenuItem ( GetMenu( window_handle ),
                                wparam, MF_BYCOMMAND | MF_CHECKED );
                MessagesOn = TRUE;
            } else {
                SendMessage( MessageWnd, WM_CLOSE, 0, 0L );
                CheckMenuItem ( GetMenu( window_handle ), wparam,
                    MF_BYCOMMAND | MF_UNCHECKED );
                MessagesOn = FALSE;
            }
            break;
        }
        break;
    case WM_PAINT:
        edata_ptr = (extra_data *) GetWindowLong( window_handle,
                                            EXTRA_DATA_OFFSET );
        hdc = BeginPaint (window_handle, &ps);
        /*
         * paint the invalid area with the background colour
         */
        brush = CreateSolidBrush( BACKGROUND );
        FillRect( hdc, &ps.rcPaint, brush );
        DeleteObject( brush );

        rect.left   = edata_ptr->target.x;
        rect.top    = edata_ptr->target.y;
        rect.right  = rect.left + edata_ptr->size.x;
        rect.bottom = rect.top + edata_ptr->size.y;

        /*
         * if part of the target bitmap is invalid, redraw it
         */
        if( IntersectRect( &rect, &rect, &ps.rcPaint ) ) {
            DrawBitmap( hdc, edata_ptr->target_bmp,
                        edata_ptr->target.x, edata_ptr->target.y );
        }
        EndPaint(window_handle, &ps);
        break;
    case WM_HSCROLL:
    case WM_VSCROLL:
        /*
         * use the scrollbars to move the target around
         */
        {
            short position; /* the x or y position of the scrollbar */
            short max;
            short min;

            edata_ptr = (extra_data *) GetWindowLong( window_handle,
                                                EXTRA_DATA_OFFSET );
            position = ( msg == WM_HSCROLL ) ?
                       edata_ptr->target.x : edata_ptr->target.y;

            switch( wparam ) {
            case SB_PAGEDOWN:
                position += 15;
                break;
            case SB_LINEDOWN:
                position++;
                break;
            case SB_PAGEUP:
                position -= 15;
                break;
            case SB_LINEUP:
                position--;
                break;
            case SB_THUMBPOSITION:
            case SB_THUMBTRACK:
                position = LOWORD( lparam );
                break;
            default:
                return( 0L );
            }
            if( msg == WM_HSCROLL ) {
                GetScrollRange( window_handle, SB_HORZ, (LPINT)&min, (LPINT)&max );
                edata_ptr->target.x = max( min( position, max ), min );
                SetScrollPos( window_handle, SB_HORZ, edata_ptr->target.x , TRUE );
            } else {
                GetScrollRange( window_handle, SB_VERT, (LPINT)&min, (LPINT)&max );
                edata_ptr->target.y = max( min( position, max ), min );
                SetScrollPos( window_handle, SB_VERT, edata_ptr->target.y, TRUE );
            }
            InvalidateRect( window_handle, &edata_ptr->client_rect, FALSE );
        }
        break;
    case WM_MOVE_TARGET:

        /*
         * move the target to a random location on the screen
         */

        edata_ptr = (extra_data *) GetWindowLong( window_handle,
                                            EXTRA_DATA_OFFSET );
        rect.left   = edata_ptr->target.x;
        rect.top    = edata_ptr->target.y;
        rect.right  = rect.left + edata_ptr->size.x;
        rect.bottom = rect.top + edata_ptr->size.y;
        InvalidateRect( window_handle, &rect, TRUE );

        edata_ptr->target = RandPoint( edata_ptr->client_rect, edata_ptr->size );

        rect.left   = edata_ptr->target.x;
        rect.top    = edata_ptr->target.y;
        rect.right  = rect.left + edata_ptr->size.x;
        rect.bottom = rect.top + edata_ptr->size.y;
        InvalidateRect( window_handle, &rect, TRUE );

        /* set the scrollbars to indicate the new position */
        SetScrollPos( window_handle, SB_HORZ, edata_ptr->target.x , TRUE );
        SetScrollPos( window_handle, SB_VERT, edata_ptr->target.y, TRUE );

        break;
    case WM_TIMER:
        SendMessage( window_handle, WM_MOVE_TARGET, 0, 0L );
        break;
        break;
    case WM_DESTROY:
        edata_ptr = (extra_data *) GetWindowLong( window_handle,
                                                  EXTRA_DATA_OFFSET );
        KillTimer( window_handle, TARGET_TIMER );       /* Stops the timer */
        FreeProcInstance( edata_ptr->message_window_proc );
        FreeProcInstance( edata_ptr->score_window_proc );
        PostQuitMessage( 0 );
        break;

    default:
        return( DefWindowProc( window_handle, msg, wparam, lparam ) );
    }
    return( 0L );

} /* WindowProc */
Esempio n. 25
0
int GUIGetFileName( gui_window *wnd, open_file_name *ofn )
{
    OPENFILENAME        wofn;
    bool                issave;
    int                 rc;
    unsigned            drive;
#if defined(HAVE_DRIVES)
    unsigned            old_drive;
    unsigned            drives;
#endif

    LastPath = NULL;
    if( ofn->initial_dir != NULL && ofn->initial_dir[0] != '\0' && ofn->initial_dir[1] == ':' ) {
        drive = ofn->initial_dir[0];
        memmove( ofn->initial_dir, ofn->initial_dir+2, strlen( ofn->initial_dir+2 ) + 1 );
    } else {
        drive = 0;
    }

    memset( &wofn, 0 , sizeof( wofn ) );

    if( ofn->flags & OFN_ISSAVE ) {
        issave = true;
    } else {
        issave = false;
    }

    wofn.Flags = 0;
    if( hookFileDlg ) {
        wofn.Flags |= OFN_ENABLEHOOK;
    }
    if( !(ofn->flags & OFN_CHANGEDIR) ) {
        wofn.Flags |= OFN_NOCHANGEDIR;
    }

    if( ofn->flags & OFN_OVERWRITEPROMPT ) {
        wofn.Flags |= OFN_OVERWRITEPROMPT;
    }
    if( ofn->flags & OFN_HIDEREADONLY ) {
        wofn.Flags |= OFN_HIDEREADONLY;
    }
    if( ofn->flags & OFN_FILEMUSTEXIST ) {
        wofn.Flags |= OFN_FILEMUSTEXIST;
    }
    if( ofn->flags & OFN_PATHMUSTEXIST ) {
        wofn.Flags |= OFN_PATHMUSTEXIST;
    }
    if( ofn->flags & OFN_ALLOWMULTISELECT ) {
        wofn.Flags |= OFN_ALLOWMULTISELECT;
    }
    wofn.hwndOwner = GUIGetParentFrameHWND( wnd );
    wofn.hInstance = GUIMainHInst;
    wofn.lStructSize = sizeof( wofn );
    wofn.lpstrFilter = ofn->filter_list;
    wofn.nFilterIndex = ofn->filter_index;
    wofn.lpstrFile = ofn->file_name;
    wofn.nMaxFile = ofn->max_file_name;
    wofn.lpstrFileTitle = ofn->base_file_name;
    wofn.nMaxFileTitle = ofn->max_base_file_name;
    wofn.lpstrTitle = ofn->title;
    wofn.lpstrInitialDir = ofn->initial_dir;
    wofn.lpfnHook = (LPOFNHOOKPROC)NULL;
    if( hookFileDlg ) {
        wofn.lpfnHook = (LPOFNHOOKPROC)MakeOpenFileHookProcInstance( OpenHook, GUIMainHInst );
    }

#if defined( HAVE_DRIVES )
    if( drive ) {
        _dos_getdrive( &old_drive );
        _dos_setdrive( tolower( drive ) - 'a' + 1, &drives );
    }
#endif
    if( issave ) {
        rc = GetSaveFileName( &wofn );
    } else {
        rc = GetOpenFileName( &wofn );
    }

    if( hookFileDlg ) {
        (void)FreeProcInstance( (FARPROC)wofn.lpfnHook );
    }

    if( LastPath && ( !rc || !( ofn->flags & OFN_WANT_LAST_PATH ) ) ) {
        GUIMemFree( LastPath );
        LastPath = NULL;
    }
    ofn->last_path = LastPath;
#if defined( HAVE_DRIVES )
    if( drive ) {
        _dos_setdrive( old_drive, &drives );
    }
#endif
    if( rc ) {
        return( OFN_RC_FILE_SELECTED );
    }
    if( !CommDlgExtendedError() ) {
        return( OFN_RC_NO_FILE_SELECTED );
    }
    return( OFN_RC_FAILED_TO_INITIALIZE );
} /* _GUIGetFileName */
Esempio n. 26
0
/*
 * "shoot" a bolt from the current bolt location to the "aim" location
 */
static void ShootBolt( HWND window_handle )
/*****************************************/
{
    extra_data  *edata_ptr;
    HDC         hdc;
    HBITMAP     screensavebmp;
    MSG         msg;
    FARPROC     proc;
    HANDLE      inst_handle;
    icon_mover  mover;

    edata_ptr = (extra_data *) GetWindowLong( window_handle,
                                        EXTRA_DATA_OFFSET );

    hdc = GetDC( window_handle );
    inst_handle = GetWindowWord( window_handle, GWW_HINSTANCE );

    /* set up an "icon_mover" struct to give all needed data to DrawBolt */
    mover.icon = edata_ptr->bolt_icon;
    mover.size.x = BOLTWIDTH;
    mover.size.y = BOLTHEIGHT;
    mover.last.x = -1;
    mover.last.y = -1;
    mover.screen_dc = hdc;
    mover.storage_dc = CreateCompatibleDC( hdc );
    mover.speed = edata_ptr->bolt_speed;

    screensavebmp = CreateCompatibleBitmap( hdc, mover.size.x, mover.size.y );
    SelectObject( mover.storage_dc, screensavebmp );

    if( edata_ptr->sound_on ) {
        BoltSound();
    }
    /*
     * for each point on the line between the points BOLT and AIM,
     * call DrawBolt
     * use aim - boltheight so that the bottom left corner of the bolt icon
     * stops at the point AIM
     */
    proc = MakeProcInstance( (FARPROC)DrawBolt, inst_handle );
    LineDDA( edata_ptr->bolt.x, edata_ptr->bolt.y, edata_ptr->aim.x,
             edata_ptr->aim.y - BOLTHEIGHT, proc, (LPARAM)(LPVOID)&mover );
    FreeProcInstance( proc );

    /*
     * remove all WM_LBUTTONDOWN messages from the application queue which
     * occured while the bolt was "in the air"
     * this prevents the shots from building up - only 1 can happen at a time
     */
    while( PeekMessage( &msg, window_handle, WM_LBUTTONDOWN, WM_LBUTTONDOWN,
                        PM_REMOVE ) );

    /* make sure the bolt is drawn at the final location regardless of speed */
    mover.speed = 1;
    DoDrawBolt( edata_ptr->aim.x, edata_ptr->aim.y - BOLTHEIGHT, &mover );
    if( edata_ptr->sound_on ) {
        BoomSound();
    }
    /* redraw the background behind the icon */
    BitBlt( mover.screen_dc, mover.last.x, mover.last.y, mover.size.x,
            mover.size.y, mover.storage_dc, 0, 0, SRCCOPY);

    CheckHit( hdc, edata_ptr->aim );

    DeleteDC( mover.storage_dc );
    DeleteObject( screensavebmp );
    ReleaseDC(window_handle, hdc);

} /* ShootBolt */
int
gsdll_class::unload(void)
{
    // exit Ghostscript interpreter
    if (initialized) {
        if (!execute_code)
            c_execute_end();
        c_exit();
#ifndef __WIN32__
        FreeProcInstance((FARPROC)callback);
#endif
        callback = NULL;
    }

    // For Win16, must free the thunks.
#ifndef __WIN32__
// is it safe to call these with NULL pointers?
    FreeProcInstance(c_revision);
    FreeProcInstance(c_init);
    FreeProcInstance(c_execute_begin);
    FreeProcInstance(c_execute_cont);
    FreeProcInstance(c_execute_end);
    FreeProcInstance(c_exit);
    FreeProcInstance(c_lock_device);
    FreeProcInstance(c_copy_dib);
    FreeProcInstance(c_copy_palette);
    FreeProcInstance(c_draw);
#endif

    // Set functions to NULL to prevent use
    c_revision = NULL;
    c_init = NULL;
    c_execute_begin = NULL;
    c_execute_cont = NULL;
    c_execute_end = NULL;
    c_exit = NULL;
    c_lock_device = NULL;
    c_copy_dib = NULL;
    c_copy_palette = NULL;
    c_draw = NULL;

    // need to do more than this
    device = NULL;

    // Don't do anything else if already unloaded
    if (hmodule == (HINSTANCE)NULL)
        return 0;

    return 0;
}
Esempio n. 28
0
File: wpause.c Progetto: zsx/gnuplot
/* PauseBox */
int WDPROC
PauseBox(LPPW lppw)
{
	MSG msg;
	HDC hdc;
	int width, height;
	TEXTMETRIC tm;
	RECT rect;
	char *current_pause_title = lppw->Title;
	static char TITLE_PAUSE_MOUSE[] = "waiting for mouse click";
	if (paused_for_mouse)
	    current_pause_title = TITLE_PAUSE_MOUSE;

	if (!lppw->hPrevInstance)
		CreatePauseClass(lppw);
	GetWindowRect(GetDesktopWindow(), &rect);
	if ( (lppw->Origin.x == CW_USEDEFAULT) || (lppw->Origin.x == 0) )
		lppw->Origin.x = (rect.right + rect.left) / 2;
	if ( (lppw->Origin.y == CW_USEDEFAULT) || (lppw->Origin.y == 0) )
		lppw->Origin.y = (rect.bottom + rect.top) / 2;

	hdc = GetDC(NULL);
	SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
	GetTextMetrics(hdc, &tm);
	width  = max(24,4+_fstrlen(lppw->Message)) * tm.tmAveCharWidth;
	width = min(width, rect.right-rect.left);
	height = 28 * (tm.tmHeight + tm.tmExternalLeading) / 4;
	ReleaseDC(NULL,hdc);

#ifndef WIN32
	lppw->lpfnPauseButtonProc =
#ifdef __DLL__
		(WNDPROC)GetProcAddress(hdllInstance, "PauseButtonProc");
#else
		(WNDPROC)MakeProcInstance((FARPROC)PauseButtonProc ,hdllInstance);
#endif
#endif
	lppw->hWndPause = CreateWindowEx(
        WS_EX_DLGMODALFRAME | WS_EX_TOPMOST
#ifdef WS_EX_APPWINDOW
        /* HBB 20001217: put the pause window into the taskbar, and make
         * float on top of everything. This is cleaner than adding a window
         * menu to it, as the 3.5 code did it: */
        | WS_EX_APPWINDOW
#endif
        , szPauseClass, current_pause_title,
/* HBB 981202: WS_POPUPWINDOW would have WS_SYSMENU in it, but we don't
 * want, nor need, a System menu in our Pause windows. Actually, it was
 * emptied manually, in the WM_CREATE handler below, in the original code.
 * This solution seems cleaner. */
		WS_POPUP | WS_BORDER | WS_CAPTION,
		lppw->Origin.x - width/2, lppw->Origin.y - height/2,
		width, height,
		lppw->hWndParent, NULL, lppw->hInstance, lppw);

	SendMessage(lppw->hCancel, BM_SETSTYLE, (WPARAM)BS_DEFPUSHBUTTON, (LPARAM)FALSE);

	/* Don't show the pause "OK CANCEL" dialog for "pause mouse ..." -- well, show
	   it only for "pause -1".
	   Note: maybe to show in the window titlebar or somewhere else a message like 
	   graphwin.Title = "gnuplot pausing (waiting for mouse click)";
	*/
	if (!paused_for_mouse) {
	    ShowWindow(lppw->hWndPause, SW_SHOWNORMAL);
	    BringWindowToTop(lppw->hWndPause);
	    UpdateWindow(lppw->hWndPause);
	}

	lppw->bPause = TRUE;
	lppw->bPauseCancel = IDCANCEL;

	while (lppw->bPause) {
	    /* HBB 20021211: Nigel Nunn found a better way to avoid
	     * 100% CPU load --> use it */
	    if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
		/* wait until window closed */
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	    } else
		WaitMessage();
	}

	DestroyWindow(lppw->hWndPause);
#ifndef WIN32
#ifndef __DLL__
	FreeProcInstance((FARPROC)lppw->lpfnPauseButtonProc);
#endif
#endif

	return(lppw->bPauseCancel);
}
Esempio n. 29
0
//---------------------------------------------------------------------------
// MainWndProc
//
// Main window procedure
//
// RETURNS:     Per Windows Convention....
//---------------------------------------------------------------------------
LONG  APIENTRY MainWndProc (HWND hwnd, WORD message,
                             WPARAM wParam, LPARAM lParam)
{
    FARPROC lpProcAbout;

    switch (message)
        {
        case WM_CREATE:
            {
            RECT    r;

            // Create an edit window for the client area
            //---------------------------------------------------------------
            GetClientRect (hwnd, &r);
            hwndEdit = CreateWindow ("RBEdit", NULL,
            //hwndEdit = CreateWindow ("edit", NULL,
            //                         ES_MULTILINE |
                                     WS_BORDER |
                                     WS_CHILD | WS_CLIPCHILDREN |
                                     WS_VSCROLL | WS_HSCROLL,
                                     0,
                                     20,
                                     r.right,
                                     r.bottom-20,
                                     hwnd,
                                     0xCAC,
                                     hInst,
                                     NULL);
            ShowWindow (hwndEdit, SW_SHOWNORMAL);
            fNotify = FALSE;
            break;
            }

        case WM_SIZE:
            // Move the edit window to fit the new client area
            //---------------------------------------------------------------
            if (IsWindow (hwndEdit))
                MoveWindow (hwndEdit, 0, 20,
                                      LOWORD(lParam), HIWORD(lParam)-20, 1);
            break;

        case WM_PAINT:
            {
            HDC         hdc;
            PAINTSTRUCT ps;

            hdc = BeginPaint (hwnd, &ps);
            PaintStatus (hwnd, hdc);
            EndPaint (hwnd, &ps);
            break;
            }

        case WM_SETFOCUS:
            if (IsWindow (hwndEdit))
                SetFocus (hwndEdit);
            break;

        case WM_SYSCOLORCHANGE:
            SendMessage (hwndEdit, message, wParam, lParam);
            break;

        case WM_COMMAND:
            switch (GET_WM_COMMAND_ID (wParam, lParam))
                {
                case IDM_ABOUT:
                    lpProcAbout = MakeProcInstance ((FARPROC)About, hInst);
                    DialogBox (hInst, "AboutBox", hwnd, (WNDPROC)lpProcAbout);
                    FreeProcInstance (lpProcAbout);
                    break;

                case IDM_CRASH:
                    {
                    INT     l;

                    l = (INT)SendMessage (hwndEdit, EM_LINELENGTH, 0, -1L);
                    SendMessage (hwndEdit, EM_SETSELXY, -1,
                                 MAKELONG (l, l+3));
                    break;
                    }

                case IDM_UNDO:
                    if (!SendMessage (hwndEdit, EM_UNDO, 0, 0L))
                        MessageBeep (0);
                    break;

                case IDM_SETRO:
                    SendMessage (hwndEdit, EM_SETREADONLY, 1, 0L);
                    break;

                case IDM_SETRW:
                    SendMessage (hwndEdit, EM_SETREADONLY, 0, 0L);
                    break;

                case IDM_SETFONT:
                    SendMessage (hwndEdit, EM_SETFONT,
                                 (WORD)GetStockObject (ANSI_FIXED_FONT), 0L);
                    break;

                case IDM_CHGATTR:
                    SendMessage (hwndEdit, EM_SETLINEATTR, -1, oldattr++);

                    if (oldattr == 4)
                        oldattr = 0;
                    break;

                case IDM_NOTIFY:
                    fNotify = !fNotify;
                    SendMessage (hwndEdit, EM_SETNOTIFY, fNotify, 0L);
                    CheckMenuItem (GetMenu (hwnd), IDM_NOTIFY,
                                   fNotify ? MF_CHECKED : MF_UNCHECKED);
                    break;

                case IDM_LOADFILE:
                    {
                    HANDLE  hText;
                    LPSTR   lpText;
                    INT     file;
                    LONG    size;
                    DWORD   l1, l2;
                    CHAR    buf[80];

                    l1 = GetWindowLong (hwndEdit, 0);
                    l2 = GetWindowLong (hwndEdit, 4);
                    wsprintf (buf, "HSTATE: %X  LPSTATE: %x\r\n", l1, l2);
                    Out (buf);

                    hText = GlobalAlloc (GHND, 65536);
                    if (!hText)
                        break;
                    lpText = GlobalLock (hText);

                    l1 = GetWindowLong (hwndEdit, 0);
                    l2 = GetWindowLong (hwndEdit, 4);
                    wsprintf (buf, "HSTATE: %X  LPSTATE: %x\r\n", l1, l2);
                    Out (buf);

                    file = _lopen ("edittest.txt", OF_READ);
                    if (file != -1)
                        {
                        size = _llseek (file, 0, 2);
                        if (size > 0x0000ffff)
                            {
                            size = 0xfe00;
                            Alert (hwnd, "File truncated!");
                            }
                        _llseek(file, 0, 0);
                        lpText[_lread(file, lpText, (UINT)size)] = 0;

                    l1 = GetWindowLong (hwndEdit, 0);
                    l2 = GetWindowLong (hwndEdit, 4);
                    wsprintf (buf, "HSTATE: %X  LPSTATE: %x\r\n", l1, l2);
                    Out (buf);

                        _lclose(file);
                        Out ("Sending SETTEXT... ");

                    l1 = GetWindowLong (hwndEdit, 0);
                    l2 = GetWindowLong (hwndEdit, 4);
                    wsprintf (buf, "HSTATE: %X  LPSTATE: %x\r\n", l1, l2);
                    Out (buf);

                        file = (INT)SendMessage (hwndEdit, EM_RBSETTEXT, 0,
                                                 (LONG)lpText);
                        wsprintf (buf, "file = %d\r\n", file);
                        Out (buf);
                        if (!file)
                            Alert (hwnd, "SETTEXT Failed!");
                        }
                    else
                        Alert (hwnd, "EDITTEST.TXT not found...");
                    GlobalUnlock (hText);
                    GlobalFree (hText);
                    break;
                    }

                case 0xCAC:
                    // These (had better be) notification codes for the
                    // edit window
                    //-------------------------------------------------------
                    switch (HIWORD (lParam))
                        {
                        case EN_ERRSPACE:
                            Alert (hwnd, "Out of edit spce");
                            break;
                        case EN_LINETOOLONG:
                            Alert (hwnd, "Line too long");
                            break;
                        case EN_LINEWRAPPED:
                            Alert (hwnd, "Line too long -- CR inserted");
                            break;
                        case EN_SETCURSOR:
                            {
                            HDC     hdc;

                            hdc = GetDC (hwnd);
                            PaintStatus (hwnd, hdc);
                            ReleaseDC (hwnd, hdc);
                            break;
                            }
                        default:
                            break;
                            //Alert (hwnd, "Unknown notification code");
                        }
                    break;


                default:
                    return (DefWindowProc(hwnd, message, wParam, lParam));
                }
            break;

        case WM_DESTROY:
	    PostQuitMessage(0);
	    break;

        default:
            return (DefWindowProc (hwnd, message, wParam, lParam));
        }
    return (NULL);
}
Esempio n. 30
0
/* =============                                                    */
int EXPORT FAR PASCAL EnumSizesProc (LPLOGFONT lf, LPTEXTMETRIC tm,
                                     short FontType, LPSTR Data)

/* Data should point to a handle to the dialog box */
{
    if ((lf->lfWeight > 400) || lf->lfItalic || lf->lfUnderline ||
        lf->lfStrikeOut) return 1;
#if WIN30SDK
    if (FontType & 0x04) {
#else
    if (FontType & TRUETYPE_FONTTYPE) {
#endif
        /* make a size list up */
        short int h;
        
        for (h = lf->lfHeight / 4; h <= (3 * lf->lfHeight) / 2; h += 2) {
            AddSize (*(HWND FAR *)Data, h, 0);
        }
        return 0;   /* no need to list this one further */
    }
    else {  /* non-scalable font */
        /* list it only if it has a proper aspect ratio */
        HFONT   hFont;
        LOGFONT Font;
        TEXTMETRIC Metrics; 

	Font = *lf;
	Font.lfWidth = 0;
	hFont = CreateFontIndirect (&Font);
	GetFontMetrics (hFont, &Metrics, NULL);
	DeleteObject (hFont);
	if (tm->tmAveCharWidth == Metrics.tmAveCharWidth) {
	    AddSize (*(HWND FAR *)Data,
                     (short int)lf->lfHeight, (short int)lf->lfWidth);
	}
    }
    return 1;
} /* EnumSizesProc */

/* BuildSizeList:   initializes the FontSize list box */
/* =============                                      */

static void PASCAL BuildSizeList (HWND hDlg, TEXTMETRIC *Metrics)

/* This function initializes the FontSize list box with the sizes
   available for the face name currently selected in the Font list box.
   The sizes are written in the format: CXxCY. Also, the sizes are
   stored in the 32 bit values retrievable by LB_GETITEMDATA: width in
   the low-order word and height in the high order word */
{
    SendDlgItemMessage (hDlg, ID_FONTSIZE, WM_SETREDRAW, FALSE, 0L);
    SendDlgItemMessage (hDlg, ID_FONTSIZE, CB_RESETCONTENT, 0, 0L);
    {
	HDC     hDC;
	FARPROC ProcInstance;
	char    FaceName[LF_FACESIZE];

	SendDlgItemMessage (hDlg, ID_FONT, LB_GETTEXT,
			    (UINT)SendDlgItemMessage (hDlg, ID_FONT,
						      LB_GETCURSEL, 0, 0L),
			    (DWORD)(LPSTR)&FaceName[0]);
	    /* FaceName now contains the currently selected face name */
	hDC = GetDC (hDlg);
	ProcInstance = MakeProcInstance ((FARPROC)EnumSizesProc,
					 hEmacsInstance);
	EnumFonts (hDC, FaceName, ProcInstance, LPDATA(&hDlg));
	FreeProcInstance (ProcInstance);
	ReleaseDC (hDlg, hDC);
	if (SendDlgItemMessage (hDlg, ID_FONTSIZE, CB_GETCOUNT, 0, 0L) == 0) {
	    /* no size at all in the size list (ATM, for instance, does that!).
               Let's fill it with a few sample sizes... */
            short int h;

            for (h = 6; h <= 40; h += 2) AddSize (hDlg, h, 0);
	}
    }
    SendDlgItemMessage (hDlg, ID_FONTSIZE, WM_SETREDRAW, TRUE, 0L);
    InvalidateRect (GetDlgItem (hDlg, ID_FONTSIZE), NULL, TRUE);
    {   /*-Select the larger height that is smaller or equal to the
	   current Metrics (assumed to be the ones of the previous font)
	   */
	int     i;
	int     BestIndex = 0;
	short int h, w, BestHeight = 0, BestWidth = 0;
	DWORD   ItemData;

	for (i = 0;; i++) {
	    ItemData = SendDlgItemMessage (hDlg, ID_FONTSIZE,
					   CB_GETITEMDATA, i, 0L);
	    if (ItemData == CB_ERR) break;  /* end of list hit */
	    if ((h = HIWORD(ItemData)) > Metrics->tmHeight) continue;
	    if (BestHeight > h) continue;
	    w = LOWORD(ItemData);
	    if (BestHeight == h) {  /* use the width to optimize */
		if (w > Metrics->tmAveCharWidth) continue;
		if (BestWidth > w) continue;
	    }
	    BestHeight = h;
	    BestWidth = w;
	    BestIndex = i;
	}
	SendDlgItemMessage (hDlg, ID_FONTSIZE, CB_SETCURSEL, BestIndex, 0L);
    }
    NewFont (hDlg, TRUE);
} /* BuildSizeList */