Esempio n. 1
0
void CALLBACK Export( HWND, HINSTANCE, LPTSTR lpCmdLine, int )
{
    if( !lpCmdLine )
        ExitProcess( 0 );
    Handle onp( CreateFile( lpCmdLine, GENERIC_WRITE,
                FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0 ) );

    if( !onp || onp == INVALID_HANDLE_VALUE )
        ExitProcess( 0 );
    
    wchar_t* env = GetEnvironmentStringsW();
    int i;
    for( i = 0; *(int*)(env + i); i++ );

    i *= sizeof(*env);
    i += 2 * sizeof(*env);

    DWORD written;

    WriteFile( onp, env, i, &written, 0 );

    FreeEnvironmentStringsW( env );

    return;
}
Esempio n. 2
0
void RSpline::updateFromControlPoints() const {
#ifndef R_NO_OPENNURBS
    if (controlPoints.size()<degree+1) {
        invalidate();
        qWarning() << "RSpline::updateFromControlPoints: not enough control points: "
                   << controlPoints.size();
        return;
    }

    // periodic:
    if (periodic && !hasFitPoints()) {
        ON_3dPoint* points = new ON_3dPoint[controlPoints.size()];
        for (int i=0; i<controlPoints.size(); ++i) {
            RVector cp = controlPoints.at(i);
            points[i] = ON_3dPoint(cp.x, cp.y, cp.z);
        }
        curve.CreatePeriodicUniformNurbs(3, getOrder(), controlPoints.size(), points);
        delete[] points;
    }

    // open or from fit points:
    else {
        curve.Create(3, false, getOrder(), controlPoints.size());

        // setting control points:
        for (int i=0; i<controlPoints.size(); ++i) {
            RVector cp = controlPoints.at(i);
            ON_3dPoint onp(cp.x, cp.y, cp.z);
            curve.SetCV(i, onp);
            //qDebug() << "RSpline: controlPoints[" << i << "]: " << cp;
        }

        bool knotCondition = (knotVector.size() == getOrder() + controlPoints.size() - 2);
        //knotCondition = true;

        // genetate knot vector automatically:
        if (knotVector.isEmpty() || !knotCondition) {
//            if (!knotVector.isEmpty()) {
//                qDebug() << "RSpline: knotVector ignored";
//                qDebug() << "RSpline:   knots: " << knotVector.size();
//                qDebug() << "RSpline:   order: " << getOrder();
//                qDebug() << "RSpline:   controlPoints: " << controlPoints.size();
//            }

            int si = ON_KnotCount(getOrder(), controlPoints.size());
            double* knot = new double[si];
            //ON_MakePeriodicUniformKnotVector(getOrder(), controlPoints.size(), knot);
            ON_MakeClampedUniformKnotVector(getOrder(), controlPoints.size(), knot);
            for (int i=0; i<si; ++i) {
//                qDebug() << "RSpline: knot[" << i << "]: " << knot[i];
                curve.SetKnot(i, knot[i]);
            }
            delete[] knot;
        }
        else {
            int k=0;
            for (int i=0; i<knotVector.count(); ++i) {
                //qDebug() << "RSpline: knot[" << i << "]: " << knotVector.at(i);
                bool ok = curve.SetKnot(k++, knotVector.at(i));
                if (!ok) {
                    //qDebug() << "RSpline: knot[" << i << "]: NOT set";
                }
            }
        }
    }

    //##getExploded();
#endif
}
Esempio n. 3
0
HANDLE WINAPI OpenW(const struct OpenInfo *Info)
{
    const int CUR_DIR_SIZE = 100000;
    char* filename = 0;

    switch( Info->OpenFrom )
    {
    case OPEN_COMMANDLINE:
        {
            OpenCommandLineInfo* cinfo = (OpenCommandLineInfo*)Info->Data;

            const wchar_t* cmdline = cinfo->CommandLine;
            if( !cmdline )
                return INVALID_HANDLE_VALUE;

            while( *cmdline && *cmdline <= ' ' )
                cmdline++;

            if( *cmdline )
                filename = w2a( cmdline );
            else
                return 0;
            break;
        }
    case OPEN_PLUGINSMENU:
        {
            FarGetPluginPanelItem pinfo;
            PluginPanelItem* pitem = (PluginPanelItem*)malloc(CUR_DIR_SIZE);
            ZeroMemory(&pinfo, sizeof(pinfo));
            ZeroMemory(pitem, CUR_DIR_SIZE);
            pinfo.StructSize = sizeof(pinfo);
            pinfo.Size = CUR_DIR_SIZE;
            pinfo.Item = pitem;

            if(InfoW.PanelControl( PANEL_ACTIVE, FCTL_GETCURRENTPANELITEM, 0, &pinfo ))
            {
                filename = w2a( pinfo.Item->FileName );
                free(pitem);
            }
            else
            {
                free(pitem);
                return 0;
            }
            break;
        }
    default:
        return 0;
    }
    
    if( !filename )
        return 0;

    wchar_t comspec[MAX_PATH * 2];
    if( !GetEnvironmentVariableW( L"COMSPEC", comspec, sizeofa( comspec ) ) )
        lstrcpyW( comspec, L"cmd.exe" );

    char pipename[100];
    wsprintf( pipename, "\\\\.\\pipe\\FarCall%ul", GetCurrentProcessId() );

    char* batchstr = (char*)malloc( 10000 );
    wsprintf( batchstr, batch, filename, ModuleName, pipename );

    // obtaining temp file name
    wchar_t tmp[MAX_PATH * 10];
    GetTempPathW( sizeofa( tmp ), tmp );
    GetTempFileNameW( tmp, L"", 0, tmp );
    DeleteFileW( tmp );

    lstrcatW( tmp, L".bat" );

    HANDLE file = CreateFileW( tmp, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, CREATE_ALWAYS, 0, 0 );
    if( !file || file == INVALID_HANDLE_VALUE )
    {
        DeleteFileW( tmp );
        free( filename );
        free( batchstr );
        return INVALID_HANDLE_VALUE;
    }

    DWORD written;
    WriteFile( file, batchstr, lstrlen( batchstr ), &written, 0 );
    CloseHandle( file );

    wchar_t cmd[MAX_PATH * 10] = L"\"";
    lstrcatW( lstrcatW( lstrcatW( lstrcatW( cmd, comspec ), L"\" /c \"" ), tmp ), L"\"");

    STARTUPINFOW sinfo;
    ZeroMemory( &sinfo, sizeof( sinfo ) );
    sinfo.cb = sizeof( sinfo );

    PROCESS_INFORMATION pinfo;

    Handle np( CreateNamedPipe( pipename, PIPE_ACCESS_DUPLEX, PIPE_WAIT,
                                PIPE_UNLIMITED_INSTANCES, 100, 100, 0, 0 ) );

    connected = false;

    DWORD id;
    Handle thread( CreateThread( 0, 0, ListenEnv, np, 0, &id ) );
    
    while( !connected )
        Sleep( 100 );
    
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    GetConsoleScreenBufferInfo( GetStdHandle( STD_OUTPUT_HANDLE ), &csbi );
    
#ifndef LIGHTGRAY
#define LIGHTGRAY 7
#endif

    wchar_t Blank[1024];
    FSFW.sprintf(Blank,L"%*s",csbi.dwSize.X,L"");
    FarColor fc = {FCF_NONE, LIGHTGRAY, 0, 0};
    for (int Y=0;Y<csbi.dwSize.Y;Y++)
        InfoW.Text(0,Y,&fc,Blank);
    InfoW.Text(0,0,0,NULL);
    
    COORD C;
    C.X=0;
    C.Y=csbi.dwCursorPosition.Y;
    SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), C );

    wchar_t* curr_dir = (wchar_t*)malloc(CUR_DIR_SIZE);
    
    FSFW.GetCurrentDirectory(CUR_DIR_SIZE, curr_dir);

    if( np && CreateProcessW( NULL, cmd, 0, 0, TRUE, 0, 0, curr_dir[0] ? curr_dir : 0, &sinfo, &pinfo ) )
    {

        HANDLE ar[] = {pinfo.hProcess, np};

        WaitForMultipleObjects( 2, ar, TRUE, INFINITE );
        CloseHandle(pinfo.hProcess);
        CloseHandle(pinfo.hThread);
        SMALL_RECT src;
        COORD dest;
        CHAR_INFO fill;
        src.Left=0;
        src.Top=2;
        src.Right=csbi.dwSize.X;
        src.Bottom=csbi.dwSize.Y;
        dest.X=dest.Y=0;
        fill.Char.AsciiChar=' ';
        fill.Attributes=7;
        ScrollConsoleScreenBuffer( GetStdHandle( STD_OUTPUT_HANDLE ), &src, NULL, dest, &fill);

        InfoW.AdvControl(0, ACTL_REDRAWALL, 0, 0);
    }
    else
        Handle onp( CreateFile( pipename, GENERIC_WRITE,
            FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0 ) );

    
    free( filename );
    free( batchstr );
    free( curr_dir );
    DeleteFileW( tmp );
    
    return 0;
}
Esempio n. 4
0
//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_PAINT    - Paint the main window
//  WM_DESTROY  - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	PAINTSTRUCT ps;
	HDC hdc;

	switch (message)
	{
		case WM_CREATE: //tylko raz sie to wywluje przy tworzeniu okienka(czy programu, nie wiem :D)
		{
			// Create an edit box
			hEdit=CreateWindowEx(WS_EX_CLIENTEDGE, //tworzy pole do wprowadzania tekstu
				"EDIT",
				"",
				WS_CHILD|WS_VISIBLE|
				ES_MULTILINE|ES_AUTOVSCROLL|ES_AUTOHSCROLL,
				10,
				10,
				470,
				20,
				hWnd,
				(HMENU)IDC_MAIN_EDIT,
				GetModuleHandle(NULL),
				NULL);
			HGDIOBJ hfDefault=GetStockObject(DEFAULT_GUI_FONT);
			SendMessage(hEdit,
				WM_SETFONT,
				(WPARAM)hfDefault,
				MAKELPARAM(FALSE,0));
			SendMessage(hEdit,
				WM_SETTEXT,
				NULL,
				(LPARAM)"");

			//tworzy pole do wypisania ONP i wyniku
			hOnpOutput = CreateWindow("STATIC", "Tutaj pojawi sie wyrazenie skonwertowane do ONP", WS_VISIBLE | WS_CHILD | SS_LEFT, 10, 40, 470, 20, hWnd, NULL, hInst, NULL);
			hResult = CreateWindow("STATIC", "Tutaj pojawi sie wynik", WS_VISIBLE | WS_CHILD | SS_LEFT, 10, 65, 470, 20, hWnd, NULL, hInst, NULL);

			// Create a push button
			 hButton=CreateWindowEx(NULL, //tworzy przycisk
				"BUTTON",
				"Oblicz",
				WS_TABSTOP|WS_VISIBLE|
				WS_CHILD|BS_DEFPUSHBUTTON,
				50,
				85,
				100,
				24,
				hWnd,
				(HMENU)IDC_MAIN_BUTTON,
				GetModuleHandle(NULL),
				NULL);
			SendMessage(hButton,
				WM_SETFONT,
				(WPARAM)hfDefault,
				MAKELPARAM(FALSE,0));
		}
	case WM_PAINT:
		hdc = BeginPaint(hWnd, &ps);

		// Here your application is laid out.
		// For this introduction, we just print out "Hello, World!"
		// in the top left corner.
		// End application-specific layout section.

		EndPaint(hWnd, &ps);
		break;
	case WM_COMMAND: //guzik przesyla ten rodzaj komendy
		if ((HWND)lParam == hButton) //sprawdzamy czy to nasz guzik
		{
			try
			{

				int txtlen = GetWindowTextLength(hEdit); //sprawdzamy ile liter ma wprowadzone przez nas wyrazenie
				std::string expr;  //or use wstring for wchar_t //tworzymy string ktory bedzie to przechowywal.
				expr.reserve(txtlen + 1); //zwiekszamy ilosc znakow w tym stringu zeby mogl to przechowac (bedziemy przesylac wskaznik wiec musimy to zrobic)
				GetWindowText(hEdit, const_cast<char*>(expr.c_str()), txtlen + 1); //pobieramy napis

				ONP onp(expr.c_str()); //inicjalizujemy ONP


				std::string value = std::to_string(onp); //pobieramy wynik
				std::string onpExpr = onp.onpExpression; //pobieramy wyrażenie ONP

				SetWindowText(hOnpOutput, onpExpr.c_str()); //pokazujemy wyrazenie w psotaci ONP
				SetWindowText(hResult, value.c_str()); //pokazujemy wynik
			}
			catch (std::exception e) 
			{
				MessageBox(NULL, //pokazuje nam okienko z bledem (moze dzielenie przez 0?
			(e.what()),
			_T("Blad!!!"),
			NULL);
			}
			catch (...) //lapie kazdy inny blad ktory nie jest std::exception
			{
				MessageBox(NULL, //pokazuje nam okienko z bledem (moze dzielenie przez 0?
					("Unexpected error"),
					_T("Blad!!!"),
					NULL);
			}
		}
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
		break;
	}

	return 0;
}