Page 1 of 2
Canot open large imagegadget -- Why?
Posted: Thu Oct 31, 2024 7:48 am
by Randy Walker
Supposed to be a magnifier -- I originally ported this code in from GFA Basic and had it working in earlier version on PB but now cannot get it working right in PB 6.12
Main problem is the ImageGadget will not fill the window as it is.
Am I just asking too much of ImageGadget?
Code: Select all
Dim mousePoint.POINT(1)
GetCursorPos_(mousePoint(1))
x = mousePoint(1)\x
y = mousePoint(1)\y
myX = 400
myY = 300
;
wnd = OpenWindow(0, x-myx/2, y-myy/2, myx, myy, "", #PB_Window_BorderLess)
GetCursorPos_(mousePoint(1))
ImageGadget(1, 0, 0, myx, myy, 0, #PB_Image_Border)
FrameGadget(2, 0, 0, myX+8, myY+8, "")
ResizeGadget(1, #PB_Ignore, #PB_Ignore, 500, 400)
CreateImage(0, myX, myY)
Debug "Gadget bounds: " + Str(GadgetX(1)) + ", " + Str(GadgetY(1)) + ", " + Str(GadgetWidth(1)) + ", " + Str(GadgetHeight(1))
HDC = GetDC_(0)
AddWindowTimer(0, 100, 10)
PointColor = GetPixel_(HDC, x, y)
hdcImage = StartDrawing(ImageOutput(0))
If hdcImage
x - myX/10
If x < 0 : x = 0 : EndIf
y - myY/10
If y < 0 : y = 0 : EndIf
StretchBlt_(hdcImage, 0, 0, myX, myY, HDC, x, y, myX/5, myY/5, #SRCCOPY)
StopDrawing()
SetGadgetState(0, ImageID(0))
; The next line tied to "SendMessage WM_NCLBUTTONDOWN, HTCAPTION" line allows dragging window.
SetWindowLong_(GadgetID(1), #GWL_STYLE, GetWindowLong_(GadgetID(1), #GWL_STYLE) &~#SS_NOTIFY)
SetForegroundWindow_(WindowID(0))
SetActiveWindow_(WindowID(0))
SetActiveWindow(0)
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Timer
If GetForegroundWindow_() = WindowID(0)
If EventTimer() = 100
x = DesktopMouseX()
y = DesktopMouseY()
GetCursorPos_(mousePoint(1))
PointColor = GetPixel_(HDC, x, y)
hdcImage = StartDrawing(ImageOutput(0))
If hdcImage
Xold = x
Yold = y
x - myX/10
If x < 0 : x = 0 : EndIf
y - myY/10
If y < 0 : y = 0 : EndIf
StretchBlt_(hdcImage, 0, 0, myX, myY, HDC, DesktopMouseX() - myX/10 - 40, DesktopMouseY() - myY/10 - 80, myX/5, myY/5, #SRCCOPY)
Result.d = DrawText(10, 20, "Mouse: " + Str(x) + ", " + Str(y))
StopDrawing()
SetGadgetState(1, ImageID(0))
EndIf
EndIf
Else
Event = #PB_Event_CloseWindow
EndIf
Case #WM_LBUTTONUP ; Only detected if double clicked on magnivur
Event = #PB_Event_CloseWindow
Case #WM_LBUTTONDOWN ;, Window dragging dependant on "Left Button Down"
; The next line tied to "SetWindowLong_GetWindowLong" line allows dragging window.
SendMessage_(wnd,#WM_NCLBUTTONDOWN, #HTCAPTION,0)
Case #WM_KEYDOWN
Debug "Keyd"
; Case #WM_KEYUP
; Event = #PB_Event_CloseWindow
; Debug "Keyu"
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf
Re: Canot open large imagegadget -- Why?
Posted: Thu Oct 31, 2024 8:00 am
by RASHAD
Hi
Code: Select all
If hdcImage
x - myX/10
If x < 0 : x = 0 : EndIf
y - myY/10
If y < 0 : y = 0 : EndIf
StretchBlt_(hdcImage, 0, 0, myX, myY, HDC, x, y, myX/5, myY/5, #SRCCOPY)
StopDrawing()
EndIf
If IsGadget(0)
SetGadgetState(0, ImageID(0))
EndIf
Re: Canot open large imagegadget -- Why?
Posted: Thu Oct 31, 2024 8:24 am
by Randy Walker
Thanks RASHAD. You pulled through for me once again. It certainly fills the window now. Thank you very much, but now It's not magnifying anything. Don't know what happened there.
Re: Canot open large imagegadget -- Why?
Posted: Thu Oct 31, 2024 11:12 am
by PBJim
Hi Randy,
If it helps you to know, under PureBasic 6.00 64-bit Windows, it appears to work, at least with the ISGadget() correction.

Re: Canot open large imagegadget -- Why?
Posted: Thu Oct 31, 2024 9:50 pm
by Randy Walker
Hi PBJim,
Yes, if I only add only the If IsGadget part it does magnify, but the ImageGadget still does not fill the window as it does if i use the entire If hdcImage post RASHAD gave me.
BTW I am using ver 6.12x64 on 64 bit Windows 11 Pro 23H2
Re: Canot open large imagegadget -- Why?
Posted: Thu Oct 31, 2024 10:11 pm
by JHPJHP
Hi Randy Walker,
You're setting Gadget 0, but there is no Gadget 0.
• Should be changed to Gadget 1; line 30 in your original post.
It's not filling the entire window space because the code is not compliant with your DPI setting.
•
[ Menu ] > Compiler > Compiler Options... > Enable DPI aware (remove this switch)
I'm not saying the above changes will solve much, because the code is a bit of a mess... sorry.
Are you using the code for anything important or is this just an exercise to convert GFA Basic to PureBasic?
• I only ask because I have a much better solution if you're interested.
Re: Canot open large imagegadget -- Why?
Posted: Fri Nov 01, 2024 12:14 am
by Randy Walker
JHPJHP wrote: Thu Oct 31, 2024 10:11 pm
Hi Randy Walker,
I'm not saying the above changes will solve much, because the code is a bit of a mess... sorry.
Are you using the code for anything important or is this just an exercise to convert GFA Basic to PureBasic?
• I only ask because I have a much better solution if you're interested.
Hi JHPJHP
"Messy" is my trademark

Always open to better solution, but if you're thinking of the Builtin Windows magnifier, it's not a solution I'm trying to achieve. I use it daily and could not survive without it but it's quite clumsy, so I want my reasonably sized window that can track and magnify around the mouse as a focal point.
Re: Canot open large imagegadget -- Why?
Posted: Fri Nov 01, 2024 12:47 am
by JHPJHP
Hi Randy Walker,
Randy Walker wrote:... but if you're thinking of the Builtin Windows magnifier...
No, I am a programmer
See the following temporary link:
Windows Magnification API
• Much better resolution.
• Maximize window for Fullscreen mode without borders, Esc to return to Window mode.
• Keys 1 - 4 for various color filters.
• X Key to exclude windows; currently all windows are excluded but could be modified for select windows.
If you're in Fullscreen mode and lose focus because you clicked another object, you will need to move your mouse pointer to the Taskbar and select the window (magnifying glass icon) so that the Esc Key can be used to return to Window mode.
Re: Canot open large imagegadget -- Why?
Posted: Fri Nov 01, 2024 1:51 am
by Randy Walker
JHPJHP wrote: Fri Nov 01, 2024 12:47 am
Hi Randy Walker,
Randy Walker wrote:... but if you're thinking of the Builtin Windows magnifier...
No, I am a programmer
See the following temporary link:
Windows Magnification API
Hi JHPJHP,
Best I can get out of that is "Icon file not found" popup. No indication I can see to say where it looks for the file. I put it in the PB source folder buit same message.
Re: Canot open large imagegadget -- Why?
Posted: Fri Nov 01, 2024 2:13 am
by JHPJHP
Hi Randy Walker,
-\
WindowsMagnification\
--\
icons\
---magnify.ico
--\
references\
---readme.txt
--
WM_API.pb
It's a self-contained folder, the icon
icons\magnify.ico is included in the ZIP file:
1. Extract the
WindowsMagnification folder from the ZIP file.
2. Run the PureBasic file
WM_API.pb from its default location.
or (but why?)
• Remove the icon from compiler options:
[ Menu ] > Compiler > Compiler options... > Use Icon.
Let me know how it goes; I'm expecting/expected a positive response
You don't know me, but if you did, you could tell by my use of emojis how much I want this to work for you... I hate using emojis

Re: Canot open large imagegadget -- Why?
Posted: Fri Nov 01, 2024 3:09 am
by Randy Walker
Oh WOW!!! This WM_API.pb code is VERY complex. Pheewww. I can't begin to figure out what is going 0n anywhere in that code. Much less how to modify and trim it down to my bare necessities. MY original code opened a window and filled that window with enlargement of the area surrounding the mouse pointer, similar to what WM_API.pb is doing but I had no title bar eating up real estate, and a simple click outside the window would close the window. Also allowed to grab anywhere in the window to drag the window.
Did I mention somewhere that I an not a programmer?
Re: Canot open large imagegadget -- Why?
Posted: Fri Nov 01, 2024 4:44 am
by RASHAD
Hi Randy
I am not sure about your exact aim
But next snippet may help
Code: Select all
Global width,height,zoomfactor
Global DC = GetDC_(0)
Global MemDC = CreateCompatibleDC_(DC)
width = 800
height = 600
zoomfactor = 5
CreateImage(0,width,height)
SelectObject_(MemDC,ImageID(0))
Procedure Zoom()
GetCursorPos_(p.POINT)
StretchBlt_(MemDC,0,0,width*zoomfactor,height*zoomfactor,DC,p\x,p\y+height/zoomfactor,width,height,#SRCCOPY)
StartDrawing(CanvasOutput(0))
DrawImage(ImageID(0),0,0)
StopDrawing()
EndProcedure
OpenWindow(0,0,0,width,height,"Zoom",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
StickyWindow(0,1)
CanvasGadget(0,0,0,width,height)
AddWindowTimer(0,125,10)
Repeat
Select WaitWindowEvent(1)
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Timer
Zoom()
EndSelect
Until Quit = 1
Re: Canot open large imagegadget -- Why?
Posted: Fri Nov 01, 2024 6:07 am
by Randy Walker
Hi RASHAD, (My Savior, miracle worker)
That Really looks like something I can work with. I will trim it down, applay a few adaptations and post my results. Thank you VERY MUCH!!!!
Re: Canot open large imagegadget -- Why?
Posted: Fri Nov 01, 2024 4:24 pm
by Randy Walker
Well I thought I would be able to tweak your code into my desired shape and behavior but almost all attempts seem to fail.
1. Get window and drawing area to match at 400x300 -- **oddly successful
2. Get window to close by clicking outside window -- Success
3. Get magnifier window to focus/center around mouse pointer so mouse hot spot is always showing at center of the window. -- Total failure
4. Make window open so mouse hot spot is always at center of the window at launch. -- Total failure
5. Line 34 + 45-47 do not allow grab and drag anywhere in the window -- Total failure
**Item #1 I had to do a very odd adjustment to width and height variables to get it to approximate 400x300 dimension.
Adjusted code as follows:
Code: Select all
Dim mousePoint.POINT(1)
GetCursorPos_(mousePoint(1))
x = mousePoint(1)\x
y = mousePoint(1)\y
Global width,height,zoomfactor
Global DC = GetDC_(0)
Global MemDC = CreateCompatibleDC_(DC)
width = 400
height = 300
zoomfactor = 5
CreateImage(0,width,height)
SelectObject_(MemDC,ImageID(0))
Procedure Zoom()
GetCursorPos_(p.POINT)
newX = p\x
newY = p\y
StretchBlt_(MemDC,0,0,width*zoomfactor,height*zoomfactor,DC,newX,newY+height/zoomfactor,width,height,#SRCCOPY)
StartDrawing(CanvasOutput(0))
DrawImage(ImageID(0),0,0)
Result.d = DrawText(10, 10, "Mouse: " + Str(newX) + ", " + Str(newY), RGB(0, 0, 0), RGB(250, 250, 0)) ; Yellow text
StopDrawing()
EndProcedure
GetCursorPos_(p.POINT)
newX = p\x
newY = p\y
wnd = OpenWindow(0,newX,newY,width-80,height-58,"",#PB_Window_BorderLess) ; | #PB_Window_ScreenCentered)
StickyWindow(0,1)
CanvasGadget(0,0,0,width,height)
; The next line tied to "SendMessage WM_NCLBUTTONDOWN, HTCAPTION" line allows dragging window.
SetWindowLong_(GadgetID(0), #GWL_STYLE, GetWindowLong_(GadgetID(0), #GWL_STYLE) &~#SS_NOTIFY)
AddWindowTimer(0,125,10)
Repeat
If GetForegroundWindow_() = WindowID(0)
Event = WaitWindowEvent(1)
Select Event
Case #PB_Event_Timer
Zoom()
Case #WM_LBUTTONUP ; Only detected if double clicked on magnivur
;Event = #PB_Event_CloseWindow
Case #WM_LBUTTONDOWN ;, Window dragging dependant on "Left Button Down"
; The next line tied to "SetWindowLong_GetWindowLong" line allows dragging window.
SendMessage_(wnd,#WM_NCLBUTTONDOWN, #HTCAPTION,0)
EndSelect
Else
Event = #PB_Event_CloseWindow
EndIf
Until event = #PB_Event_CloseWindow
Re: Canot open large imagegadget -- Why?
Posted: Fri Nov 01, 2024 5:43 pm
by RASHAD
Hi Randy
You can start from here
LBUTTON down to move
Esc to end
Code: Select all
Global width,height,zoomfactor
Global DC = GetDC_(0)
Global MemDC = CreateCompatibleDC_(DC)
width = 400
height = 300
zoomfactor = 5
CreateImage(0,width,height)
SelectObject_(MemDC,ImageID(0))
Procedure moveCB()
GetCursorPos_(p.POINT)
StretchBlt_(MemDC,0,0,width*zoomfactor,height*zoomfactor,DC,p\x,p\y+height/zoomfactor,width,height,#SRCCOPY)
StartDrawing(CanvasOutput(0))
DrawImage(ImageID(0),0,0)
Result.d = DrawText(10, 10, "Mouse: " + Str(p\x) + ", " + Str(p\y), RGB(0, 0, 0), RGB(250, 250, 0)) ; Yellow text
StopDrawing()
EndProcedure
wnd = OpenWindow(0,0,0,width-80,height-58,"",#PB_Window_BorderLess | #PB_Window_ScreenCentered|#WS_BORDER)
StickyWindow(0,1)
CanvasGadget(0,0,0,width,height )
BindEvent(#PB_Event_MoveWindow,@moveCB())
Repeat
Select WaitWindowEvent(1)
Case #WM_CHAR
If EventwParam() = 27
End
EndIf
Case #PB_Event_Gadget
Select EventGadget()
Case 0
Select EventType()
Case #PB_EventType_LeftButtonDown
ReleaseCapture_()
SendMessage_(WindowID(0),#WM_NCLBUTTONDOWN,#HTCAPTION,0)
EndSelect
EndSelect
EndSelect
ForEver