/*---------------------------------------------------------------------- * Function: WinMain() * * Description: * This is the main window function and we use it to initialize data * and then call our loop function. This is a std. Win32 function. * * Args: * HINSTANCE hInstance // handle to current instance * HINSTANCE hPrevInstance // handle to previous instance * LPSTR lpszCmdLine // pointer to command line * int nCmdShow // show state of window * * Return Value: * int Returns the return value of DispatchLoopNT * *----------------------------------------------------------------------*/ int WINAPI WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow ) { int res; /* SbInits result..if>0 it worked, if=0 it didnt work */ int hsize, vsize; /* size of window to be created,for each Dimension */ /* Set Window Size */ hsize = 280; vsize = 215; /* create our apps window */ CreateSPWindow(0, 0, hsize, vsize, "SbTest32"); /* update screen */ InvalidateRect(hWndMain, NULL, FALSE); /* intitialize spaceball */ res = SbInit(); /* if SpaceBall was not detected then print error, close win., exit prog. */ if (res < 1) { MessageBox(hWndMain, "Sorry - No supported Spacetec IMC device available.\n", NULL, MB_OK); if (hWndMain != NULL) { DestroyWindow(hWndMain); /* destroy window */ } ExitProcess(1); /* exit program */ } /* Function To be Repeated */ return(DispatchLoopNT()); }
int WINAPI WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow ) { SpaceballControlStruct scs; SpaceballAppDataStruct app; PointStr World[2]; char fname[256]; float CTM[4][4]; /* Current transformation matrix */ SiSpwHandlers DspHandlers; LONG addr = (long)&scs; HWND wndScreen; RECT screenRect; int size; DWORD dSizeNeeded; char appDir[256]; //int ssize; //char DirName[256]; ncmdshow = nCmdShow; //FILE *fp; /* * Figure out how big the screen is so that we can make our * window an appropriate size. */ wndScreen = GetDesktopWindow(); GetWindowRect ( wndScreen, &screenRect ); size = (int)(.8 * SPW_MIN( (screenRect.bottom - screenRect.top), (screenRect.right - screenRect.left) )); Spw_WindowWidth = size; Spw_WindowHeight = size; /* Add code to parse command line for alternate file --here-- */ /* Code that finds the default data file in its usual spot */ // if (0 != (dSizeNeeded = GetCurrentDirectory(256, appDir))) if (0 != (dSizeNeeded = GetModuleFileName(NULL, appDir, 256 ))) { char widgetUStr[] = "WIDGET\0"; char widgetLStr[] = "widget\0"; char DirName[256]; char *pdest; int result; FILE *fp; /* find "widget" in directory string */ pdest = strstr( appDir, widgetUStr ); if (pdest == NULL) { pdest = strstr( appDir, widgetLStr ); } if (pdest != NULL) { /* get the index of the end of "widget" */ result = pdest - appDir + strlen(widgetUStr); /* snip everything after "widget" */ appDir[result] = '\0'; /* build the file name */ strcpy(DirName, appDir); strcat(DirName, "\\dat\\widget.dat"); } /* see if we can open the file */ if (NULL != (fp=fopen(DirName, "r"))) { fclose(fp); /* close it back up */ strcpy(fname, DirName); /* save the file name */ } else /* file is in a non standard location; let user find it */ { strcpy(fname, "*.dat"); GetNTFileName( NULL, fname ); } } /* * Initialize the Spaceball data structures */ /* Spaceball tuning values */ scs.sbScaleFactor[0] = (float)0.05; scs.sbScaleFactor[1] = (float)0.05; scs.sbScaleFactor[2] = (float)0.005; scs.sbScaleFactor[3] = (float)0.0005; scs.sbScaleFactor[4] = (float)0.0005; scs.sbScaleFactor[5] = (float)0.0005; /* Initialize platform-independent data */ MainInitialize (fname, &scs, &app, (float *)CTM, World); MoveWindow(hWndMain, 300, 0, Spw_WindowWidth, Spw_WindowHeight, TRUE); SetClassLong(hWndMain, 0, (LONG)(&scs)); /* * Initialize the Spaceball, render initial scene */ InitializeSpaceball(0, hWndMain, &DspHandlers, &scs); ResetWidgetView( (float(*)[4])app.CTM, app.center ); app.redraw = TRUE; InvalidateRect(hWndMain, NULL, FALSE); return(DispatchLoopNT(&DspHandlers)); } /* end of WinMain */