FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

DRAWING

Use USR GETPICT with FB^3


I am trying to capture the screen via USR GETPICT but the result, obtained via PICTURE in a GWorld, always comes out in black and white only.

I think your problem stems from not setting a CGrafPort. At startup, with no window, the program's port is not easily determinable. From the behaviour you describe, it is probably set to the WMgrPort (a black-and-white GrafPort).

Although the colour problem is easily overcome, for example by
     CALL GETCWMGRPORT(thePort&): CALL SETPORT(thePort&)
it is inadvisable to write to the Window manager's port. It's better always to write to a window, in this case, one that covers the full screen. Then you'll get proper refreshing of the desktop at program termination.

Try the demo below. It's modified for FB^3, from Fonder (a program of mine that plays various tricks with the desktop). The full FBII code for Fonder is available at HTTP://WWW.FUTUREBASIC.ORG/SAMPLE.HTML. Because Fonder was a mini-app, there are hardly any calls to the FB Runtime. For instance,USR GETPICT isn't used. Also, I made the window with FN NEWCWINDOW, because it's also easier to get a properly located full-screen window this way.
The statement
    WINDOW 1,"",@gScrnRect,_dialogPlain
doesn't put the window in the right place.
'---------Full screen desktop window (FB^3)----------------
DIM gMainWnd&, gPictWorld&, gScrnRect as rect
END GLOBALS

LOCAL FN NewGWWithDesktop&(sPtr&)
// make GWorld with copy of desktop
  DIM @ currGW&,currDev&,copyGW&
  CALL GETGWORLD(currGW&,currDev&)
  LONG IF (FN NEWGWORLD(copyGW&,0,#sPtr&,0,currDev&,0) == _noErr)
    CALL HIDECURSOR
    CALL COPYBITS(#currGW&+2,#copyGW&+2,#sPtr&,#sPtr&,_patCopy,_nil)
    CALL SHOWCURSOR
  XELSE
    STOP "error in GrabPixNewGW&"
  END IF
END FN = copyGW&

LOCAL FN CopyGWToCurrentGW(srcGW&,rectPtr&)
  DIM @ currPort&, currDevice&
  CALL GETGWORLD(currPort&, currDevice&)
  LONG IF (FN LOCKPIXELS(FN GETGWORLDPIXMAP(srcGW&)) == _true)
    CALL HIDECURSOR
    CALL COPYBITS(#srcGW&+2,#currPort&+2,#rectPtr&,#rectPtr&,_srcCopy,0)
    CALL SHOWCURSOR
    CALL UNLOCKPIXELS(FN GETGWORLDPIXMAP(srcGW&))
  XELSE
    STOP "error in CopyGW2CurrentGW"
  END IF
end fn

CALL SETRECT(gScrnRect, 0,0,SYSTEM(_scrnWidth),SYSTEM(_scrnHeight))
gPictWorld& = FN NewGWWithDesktop&(@gScrnRect)

// put up a (non FB) window covering whole screen
gMainWnd&=FN NEWCWINDOW(0,gScrnRect,"",_true,_PlainDBox,-1,1,0)
CALL SETPORT(gMainWnd&)// activate

FN CopyGWToCurrentGW (gPictWorld&,@gScrnRect)

// prove we have a window, by scribbling in it
CALL MOVETO(gScrnRect.left,gScrnRect.top)
CALL LINETO(gScrnRect.right,gScrnRect.bottom)

DO: UNTIL FN BUTTON
'---------------------------------------------
Robert

Here is code I use in FB^3. I call this when no window is built so you'll have to save and restore the port in your own program.
CLEAR LOCAL
DIM @ deskPic&
DIM @ port&
DIM ScrnT as Rect
LOCAL FN GrabScreen

  GETCWMGRPORT(port&)
  SETPORT(port&)

'set up your rectangle here

  deskPic& = USR GETPICT(ScrnT)

END FN = deskPic&
Derek