SilverScreen Solid Modeler

Non-MFC Applications

Non-MFC Applications

Previous topic Next topic  

Non-MFC Applications

Previous topic Next topic JavaScript is required for the print function  



Non-MFC Applications


Applications for straight Win32 may also use the SilverEngine. The methodology is similar to that used by MFC programs. The task is to tie a Windows window to a SilverScreen screen. In the example that we provide, we create our window, and use sdc_open to make the connection. We also use the same window to be our “frame” window, using engine_set_frame_window.



Assume that we have the following global variables, used for a single-window application:


C / C++ Code


  static HDC           MemDC = NULL;

  static HBITMAP       MemBitmap = NULL;

  static HBITMAP       OldBitmap = NULL;

  static SDCInitStruct SDCIS = {0};

  static SDC           SDCHandle = 0;


  static HWND          hwndMain = NULL;




In the section where we create the window, we can perform SilverEngine initialization:


C / C++ Code


  hwndMain = CreateWindow( ClassName,



                           0, 0, 200, 200,

                           NULL, NULL, ghInst, NULL );


  if ( ! hwndMain )

     return FALSE;


  // Show the window


  ShowWindow(hwndMain, SW_SHOW);



 // Initialize SilverEngine and establish the frame window


  eis.bits = EI_USE_ENV;

  strcpy(eis.env_file, "silver");








Again, a good place to handle SilverScreen Display Context creation is in the handler for WM_SIZE. This fragment would be for the first time that the window was sized, meaning that it’s when the SDC is created. If the SDC has already been created, then we would want to resize the bitmap associated with the refresh DC:


C / C++ Code


if ( ! SDCHandle )


   MemDC     = CreateCompatibleDC(hDC);

   MemBitmap = CreateCompatibleBitmap(hDC, RectWidth(&wRect), RectHeight(&wRect));

   OldBitmap = (HBITMAP)SelectObject(MemDC, MemBitmap);


   SDCIS.hWnd  = hwnd;  // Can be NULL if not using interactive commands or OpenGL

   SDCIS.drawDC = hDC;   // Can be NULL if not using interactive commands

   SDCIS.refreshDC = MemDC;


   SDCHandle = sdc_open(&SDCIS);


   ss_command("silent screen create");




   SelectObject(MemDC, OldBitmap);



   MemBitmap = CreateCompatibleBitmap(hDC, RectWidth(&wRect), RectHeight(&wRect));

   OldBitmap = (HBITMAP)SelectObject(MemDC,MemBitmap);



// Inform SilverEngine the active display window has changed size


resize_screen(wRect.left, wRect.right - 1,,  wRect.bottom - 1, FALSE);

ss_command("refresh all");

ReleaseDC(hwnd, hDC);




Finally, the WM_PAINT handler refreshes the screen display from the refresh DC:


C / C++ Code


  RECT wRect;


  if ( SDCHandle )


     GetClientRect(hWnd, &wRect);

















See Also

See the SilverEngine sample Win32 for a complete example