Little Magnifier

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Little Magnifier

Post by BackupUser »

Code updated for 5.20+

Restored from previous forum. Originally posted by Franco.

Code: Select all

; (c) 2002 - Franco's template - absolutely freeware
; Thank's Pupil for the hint :)
; Desktop Loupe Function
;
Procedure CaptureScreen(Left.l, Top.l,Factor.l)
  DC = GetDC_(0)
  MemDC = CreateCompatibleDC_(DC)
  BmpID = CreateImage(0, 200, 200)
  SelectObject_( MemDC, BmpID)
  StretchBlt_( MemDC, 0, 0,200*Factor,200*Factor, DC,Left, Top, 200, 200, #SRCCOPY )
  DeleteDC_( MemDC)
  ReleaseDC_(0,DC)
  ProcedureReturn BmpID
EndProcedure
;
If OpenWindow(0,200,200,200,200,"Loupe",#PB_Window_SystemMenu) : Else : End : EndIf
;
CursorPosition.POINT
StartDrawing(WindowOutput(0))
;
Repeat
  EventID = WindowEvent()
  Delay(10)
  GetCursorPos_(CursorPosition)
  hImage = CaptureScreen( CursorPosition\x - 24,CursorPosition\y - 24,4)
  DrawImage(hImage, 0, 0)
Until EventID=#PB_Event_CloseWindow   
;
End

Have a nice day...
Franco

Sometimes you have to go a lonely way to accomplish genius things.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> If OpenWindow(0,200,200,200,200,#PB_Window_SystemMenu,"Loupe") : Else : End : EndIf

Out of curiosity: I use the following variation of the above...

If OpenWindow(0,200,200,200,200,#PB_Window_SystemMenu,"Loupe")=0 : End : EndIf

...I wonder which produces the smaller code and memory use? I'm thinking perhaps
mine does, as there is no "Else" condition involved... would that be right, Fred?

BTW Franco: this is not to rubbish your programming, so don't be offended.


PB - Registered PureBasic Coder

Edited by - PB on 13 June 2002 01:11:43
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.

Both are the same, look at the ASM code .

Fred - AlphaSND
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.

Do you know what PB?
I also tried:
If Not OpenWindow(0,200,200,200,200,#PB_Window_SystemMenu,"Loupe") : End : EndIf
but this is not working, there comes an error message:
'...garbage at the end of the line...'
The curious thing is that NOT is recognized by the editor and I thought that it is available in 3.2.
Well that's live...



Have a nice day...
Franco

Sometimes you have to go a lonely way to accomplish genius things.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by tinman.
The curious thing is that NOT is recognized by the editor and I thought that it is available in 3.2.
You did read the manual, in the variables section it tells you all the operators? The not operator is the ~ character.


--
It's not minimalist - I'm increasing efficiency by reducing input effort.
(Win98first ed. + SP1, PB3.20)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.
The curious thing is that NOT is recognized by the editor and I thought that it is available in 3.2.
You did read the manual, in the variables section it tells you all the operators? The not operator is the ~ character.


--
It's not minimalist - I'm increasing efficiency by reducing input effort.
(Win98first ed. + SP1, PB3.20)
Yes Tinman, I read it before but this:

If ~ OpenWindow(0,200,200,200,200,#PB_Window_SystemMenu,"Loupe") : End : EndIf

didn't work either.
Error message:

"EndIf without If"



Have a nice day...
Franco

Sometimes you have to go a lonely way to accomplish genius things.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by tinman.
Yes Tinman, I read it before but this:
If ~ OpenWindow(0,200,200,200,200,#PB_Window_SystemMenu,"Loupe") : End : EndIf
didn't work either.
Error message:
"EndIf without If"
You could have mentioned that you tried the ~ character first. Now I feel like a fool :)

You're right. I guess this could be classed as a bug, since it probably should be possible to use the operator like that. However, I'm guessing that Fred implemented it the same as every other operator (and since you would never use them in that kind of way, it produces a weird result).


--
It's not minimalist - I'm increasing efficiency by reducing input effort.
(Win98first ed. + SP1, PB3.20)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.
You could have mentioned that you tried the ~ character first. Now I feel like a fool :)
Tinman, you don't have to.
I'm not a pro and there is a lot that I don't know.

I think it was Albert Einstein who said:
"The more I learn and my knowlegde grows, the more I realize that I know nothing..."
or something like that


Have a nice day...
Franco

Sometimes you have to go a lonely way to accomplish genius things.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

all SYMBOLs (!,|,&,~) are for BINARY operations only:
1 & 2 | 5 ! 6 ~ 12

The WORDs (AND,OR,NOT) are for LOGICAL operations.
This logical operations return 0 or 1 (logical TRUE or FALSE).

Maybe Fred could implement "IfNot" as 1 word, so
it doesnt collide with the other Not.
(If a = x Not a = y ...)

cya,
...Danilo

(registered PureBasic user)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.
Maybe Fred could implement "IfNot" as 1 word, so
it doesnt collide with the other Not.
(If a = x Not a = y ...)
Does it make sense to have such operand ? NOT is useally a one parameter operand.. I will implement it for v3.30.

Fred - AlphaSND
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.
Does it make sense to have such operand ? NOT is useally a one parameter operand.. I will implement it for v3.30.

Fred - AlphaSND
Well Fred, 'If' you implement 'IfNot' can you also think about 'CaseNot'
Just in 'Case'...



Have a nice day...
Franco

Sometimes you have to go a lonely way to accomplish genius things.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by TronDoc.

I get an "Lcclnk illegal operation" error when trying to run the loupe code???

elecTRONics DOCtor
{registeredPB}P150 32Mb w98/DOS/Linux NO DirX NO IE :wink:
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.

TronDoc this is strange.
I tested this code on Win98SE and WinXP.

The error message "Lcclnk illegal operation" is an error message of the LCC linker.
Maybe one PureBasic Library is damaged and causes it.
There are only 3 in use: Window, Image and 2DDrawing (maybe also WindowExtension...)

Try this one, it uses the libraries Window and Gadget:

Code: Select all

Procedure CaptureScreen(Left.l, Top.l, handle.l,Factor)
  DC.l = GetDC_(0)
  MemDC.l = CreateCompatibleDC_(DC)
  If handle = 0
    BmpID.l = CreateCompatibleBitmap_(DC, 200, 200)
  Else
    BmpID.l = handle
  EndIf
  SelectObject_( MemDC, BmpID)
  StretchBlt_( MemDC, 0, 0,200*Factor,200*Factor, DC,Left, Top, 200, 200, #SRCCOPY )
  DeleteDC_( MemDC)
  ReleaseDC_(0,DC)
 ProcedureReturn BmpID ;same BUG if Bitmap or BmpID is used...
EndProcedure
;
If OpenWindow(0,200,200,200,200,#PB_Window_SystemMenu,"Loupe") : Else : End : EndIf
If CreateGadgetList(WindowID()) : Else : End : EndIf
;
CursorPosition.POINT
hImage = CaptureScreen( CursorPosition\x, CursorPosition\y, 0,1)
hGadget = ImageGadget(0, 0, 0, 200,200, hImage)
;
Repeat
  EventID.l = WindowEvent()
  Delay(10
  GetCursorPos_(CursorPosition) 
  hImage = CaptureScreen( CursorPosition\x, CursorPosition\y, hImage,4)
  SendMessage_(hGadget, #STM_SETIMAGE, #IMAGE_BITMAP, hImage)
Until EventID=#PB_EventCloseWindow   
;
End
I work with the newest libraries from http://www.purebasic.com/update/ and both versions work well.


Have a nice day...
Franco

Sometimes you have to go a lonely way to accomplish genius things.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by TronDoc.

I will try first chance I get. I'm away from home right now. -jb
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by tinman.
The error message "Lcclnk illegal operation" is an error message of the LCC linker.
Maybe one PureBasic Library is damaged and causes it.
Wasn't TronDoc having trouble with IE downloading the update libraries as text files? IIRC the Window lib has been updated, so that could be the corrupt libfile.


--
It's not minimalist - I'm increasing efficiency by reducing input effort.
(Win98first ed. + SP1, PB3.20)
Post Reply