GETBMP function
Purpose: Captures portion of screen to a bmp and stores it in an HDC.
Syntax: hDCBmp = GETBMP(LeftSrc%, TopSrc%, WidthSrc%, HeightSrc%, hWnd) Parameters:
Return Value:
|
SAVEBMP function
Purpose: Saves a bmp, stored in an HDC or accessible through a HBITMAP, to a file. Use the GETBMP function to store a bitmap in a HDC.
Syntax: SAVEBMP(hDCBmp, FileName$) Parameters:
|
Example: Note the use of ONENTRY and ONEXIT metafunctions.
' ****************************************************************' GetBmp SaveBmp Demo by Robert Wishlaw 2002/05/28' ****************************************************************' Paste this example into an editor and save as GetSaveBmp.bas' BC GetSaveBmp will translate, compile and run the program' ****************************************************************$COMPILER"$PELLES$\Bin\pocc -W1 -Gd -Go -Ze -Zx -Tx86-coff $FILE$.c"$LINKER"$PELLES$\Bin\polink -release _ -machine:ix86 _ -subsystem:windows _ -OUT:$FILE$.exe _ $FILE$.obj"$ONEXIT"GetSaveBmp"GUI"GetBmp-SaveBmp"DIMForm1ASCONTROLDIMButton3ASCONTROLDIMButton4ASCONTROLDIMButton5ASCONTROLDIMRich1ASCONTROLDIMStat1ASCONTROLDIMBuffer$DIMRectASRECTDIMHDCBmpASHDCDIMhwndASHANDLEDIMretvalDIMstr1$CONSTRunEx(lpFile, lpParameters, nShowCmd)=_ ShellExecute(0,"open", lpFile, lpParameters,0, nShowCmd)SUBFORMLOADCALLLoadBuffer1()'******************************************************************Form1=BCX_FORM("GetBmp SaveBmp",0,0,200,110)Button3=BCX_BUTTON("Capture Client",Form1,101,5,10,50,15)Button4=BCX_BUTTON("Capture Portion",Form1,102,55,10,50,15)Button5=BCX_BUTTON("Capture Screen",Form1,103,105,10,50,15)Rich1=BCX_RICHEDIT(Buffer$ ,Form1,104,5,30,190,60)Stat1=BCX_STATUS("Ready",Form1)'*******************************************************************SendMessage(Rich1,EM_SETBKGNDCOLOR,0,0x00f3f3f3)' Set background colorCENTER(Form1)' Center it!SHOW(Form1)' Show it!ENDSUBBEGINEVENTSSELECTCASECBMSG'**********************CASEWM_COMMAND'**********************IFCBCTL=101THEN' Capture Client area of a windowGetClientRect(Rich1,&Rect)HDCBmp=GETBMP(Rect.left, Rect.top, _ Rect.right-Rect.left, _ Rect.bottom-Rect.top, _ Rich1)SAVEBMP(HDCBmp,"richedit.bmp")'IMPORTANT ! Release device context resources back to system.retval=DeleteDC(HDCBmp)str1$="richedit.bmp"RunEx(str1$,"",1)' Start default paint appENDIFIFCBCTL=102THEN'Capture User defined area of a windowHDCBmp=GETBMP(10,58,360,54, Rich1)SAVEBMP(HDCBmp,"richedit.bmp")'IMPORTANT ! Release device context resources back to system.retval=DeleteDC(HDCBmp)str1$="richedit.bmp"RunEx(str1$,"",1)' Start default paint appENDIFIFCBCTL=103THEN' Capture screen. NULL is HDC for screenhwnd=GetDesktopWindow()HDCBmp=GETBMP(0,0,300,200, hwnd)SAVEBMP(HDCBmp,"richedit.bmp")'IMPORTANT ! Release device context resources back to system.retval=DeleteDC(HDCBmp)str1$="richedit.bmp"RunEx(str1$,"",1)' Start default paint appENDIFEXITFUNCTION'**********************CASEWM_CLOSE'**********************IFMSGBOX("Are you sure?","Quit Program!", MB_YESNO)=IDYESTHENDestroyWindow(Form1)ENDIFEXITFUNCTIONENDSELECTENDEVENTSSUBLoadBuffer1()Buffer$=""Buffer$=Buffer$&"{\rtf1\ansi\ansicpg1252\deff0\deflang1033"Buffer$=Buffer$&"{\fonttbl"Buffer$=Buffer$&"{\f0\froman Times New Roman;}"Buffer$=Buffer$&"{\f1\fmodern Lucida Console;}"Buffer$=Buffer$&"{\f2\fswiss Arial;}"Buffer$=Buffer$&"}"Buffer$=Buffer$&"{\colortbl ;"Buffer$=Buffer$&"\red192\green000\blue000;"Buffer$=Buffer$&"\red000\green000\blue160;"Buffer$=Buffer$&"\red255\green255\blue255;"Buffer$=Buffer$&"}\qc"Buffer$=Buffer$&"\f0\fs72\cf1\b\i BCX \i0\b0\par"Buffer$=Buffer$&"\f0\fs64\cf2 GetBmp SaveBmp"Buffer$=Buffer$&"}"ENDSUB