How to copy CreateImage drawings to clipboard?
-
BackupUser
- PureBasic Guru

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

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

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Paul.
You beat me to it Fred
Anyways... here's a longer example:
You beat me to it Fred
Anyways... here's a longer example:
Code: Select all
hnd=CreateImage(0,100,100)
If StartDrawing(ImageOutput())
FrontColour(128,0,128)
Circle(50, 50, 30)
StopDrawing()
EndIf
OpenClipboard_(0)
EmptyClipboard_()
SetClipboardData_(#CF_BITMAP,hnd)
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by fred.
Ok, I beat you from few minutes but my code was incomplete. And yours too
. Don't forget CloseClipboard() before quit.
Fred - AlphaSND
Ok, I beat you from few minutes but my code was incomplete. And yours too
Code: Select all
#CF_BITMAP = 2
If OpenClipboard_(0)
SetClipboardData_(#CF_BITMAP, LoadImage(0, "c:\background4.bmp"))
CloseClipboard_()
EndIf
-
BackupUser
- PureBasic Guru

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

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by cor.
Thanks for your quick reply.
You can also use the following command to test if the copy was successfull.
If IsClipboardFormatAvailable_(#CF_BITMAP) = 0
MessageRequester("","Fault copy",#PB_MessageRequester_Ok)
EndIf
There is only one problem:
When I close the program it give the following code:
Stack fault in 'kernel32.dll'
Just test the code by yourself
Registered user of PB
C. de Visser
Author of Super Guitar Chord Finder
http://www.ready4music.com
Thanks for your quick reply.
You can also use the following command to test if the copy was successfull.
If IsClipboardFormatAvailable_(#CF_BITMAP) = 0
MessageRequester("","Fault copy",#PB_MessageRequester_Ok)
EndIf
There is only one problem:
When I close the program it give the following code:
Stack fault in 'kernel32.dll'
Just test the code by yourself
Code: Select all
Gosub createimage
wndpl.WINDOWPLACEMENT
wndpl\Length = SizeOf(WINDOWPLACEMENT)
wndpl\showCmd = #SW_SHOWMAXIMIZED
wndpl\flags = 0;
If OpenWindow(0, #CW_USEDEFAULT, #CW_USEDEFAULT, #CW_USEDEFAULT, #CW_USEDEFAULT, #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget, "PureBasic Demo")
SetWindowPlacement_(WindowID(), @wndpl)
Gosub createimage
Procedure WindowCallback(WindowID, Message, lParam, wParam)
If Message = #WM_PAINT
StartDrawing(WindowOutput())
DrawImage(ImageID(), 100, 10)
StopDrawing()
EndIf
EndProcedure
SetWindowCallback(@WindowCallback())
OpenClipboard_(0)
EmptyClipboard_()
SetClipboardData_(#CF_BITMAP,hnd)
CloseClipboard_()
If IsClipboardFormatAvailable_(#CF_BITMAP) = 0
MessageRequester("","Fault copy",#PB_MessageRequester_Ok)
EndIf
; Wait for UserInput
Repeat
Select WaitWindowEvent()
Case #PB_EventMenu
Case #PB_EventRepaint
Case #WM_CLOSE ; #PB_EventCloseWindow
Quit = 1
EndSelect
Until Quit = 1
EndIf
createimage:
hnd=CreateImage(0,250,200)
StartDrawing(ImageOutput())
; DrawingMode(1)
FrontColour(255,255,255)
Box(0,0,250,200)
FrontColour(0,0,0)
xpos=50
xwidth=100
yheight=100
; draw guitar box
For y= 35 To 37
Line(50,y,xwidth,0)
Next
For y= 40 To 40
Line(50,y,xwidth,0)
Line(50,y+20,xwidth,0)
Line(50,y+40,xwidth,0)
Line(50,y+60,xwidth,0)
Line(50,y+80,xwidth,0)
Line(50,y+100,xwidth,0)
Next
For x = 50 To 50
Line(x,40,0,yheight)
Line(x+20,40,0,yheight)
Line(x+40,40,0,yheight)
Line(x+60,40,0,yheight)
Line(x+80,40,0,yheight)
Line(x+100,40,0,yheight)
Next
StopDrawing()
Return
End
C. de Visser
Author of Super Guitar Chord Finder
http://www.ready4music.com
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by PB.
label, as per our discussion in the "Bugs" forum.
PB - Registered PureBasic Coder
Edited by - PB on 22 January 2002 21:01:31
Not a bug: you just left out the End command before your createimage:There is only one problem:
When I close the program it give the following code:
Stack fault in 'kernel32.dll'
label, as per our discussion in the "Bugs" forum.
PB - Registered PureBasic Coder
Edited by - PB on 22 January 2002 21:01:31
-
BackupUser
- PureBasic Guru

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

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Paul.
Not the exact answer to your question but here's how to get it back off the clipboard...
Not the exact answer to your question but here's how to get it back off the clipboard...
Code: Select all
OpenClipboard_(0)
hnd=GetClipboardData_(#CF_BITMAP)
CloseClipboard_()
If OpenWindow(0,10,10,200,200,#PB_Window_SystemMenu,"Test")
StartDrawing(WindowOutput())
DrawImage(hnd,0,0)
StopDrawing()
EndIf
Delay(2000)
End
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Paul.
OK... being a little less lazy this time, here's your answer
Edited by - paul on 22 January 2002 22:00:12
OK... being a little less lazy this time, here's your answer
Code: Select all
OpenClipboard_(0)
hnd=GetClipboardData_(#CF_BITMAP)
CloseClipboard_()
InitGadget(1)
If OpenWindow(0,10,10,200,200,#PB_Window_SystemMenu,"Test")
If CreateGadgetList(WindowID())
ImageGadget(1,10,10,100,100,hnd)
EndIf
Repeat
EventID.l = WaitWindowEvent()
Until EventID=#PB_EventCloseWindow
EndIf
End
Edited by - paul on 22 January 2002 22:00:12
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by PB.
for some reason I could never work out how to "paste" it to an Image control.
PB - Registered PureBasic Coder
Thanks, Paul! I worked out the hnd=GetClipboardData_(#CF_BITMAP) part, butOK... being a little less lazy this time, here's your answer![]()
for some reason I could never work out how to "paste" it to an Image control.
PB - Registered PureBasic Coder
-
BackupUser
- PureBasic Guru

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

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by PB.
my PureBasic apps are just API calls and API constants.
PB - Registered PureBasic Coder
Edited by - PB on 22 January 2002 23:52:11
Hehehe, yeah. As mentioned in another post, about 40% of the actual code of allI see than some of you are becoming expert in PureBasic + Win API.
my PureBasic apps are just API calls and API constants.
PB - Registered PureBasic Coder
Edited by - PB on 22 January 2002 23:52:11
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Franco.
But that is because of the lack of build in commands of PureBasic!
And that's very, very bad for the Linux or Amiga world!
To recompile applications to these OS are very difficult if you use WinAPI.
(Normally you don't know much about Linux or Amiga API as you know about WinAPI...)
Have a nice day...
Franco
Sometimes you have to go a lonely way to accomplish genius things.
Yeah, that seems to be normal this days...... about 40% of the actual code of all my PureBasic apps are just API calls and API constants.
But that is because of the lack of build in commands of PureBasic!
And that's very, very bad for the Linux or Amiga world!
To recompile applications to these OS are very difficult if you use WinAPI.
(Normally you don't know much about Linux or Amiga API as you know about WinAPI...)
Have a nice day...
Franco
Sometimes you have to go a lonely way to accomplish genius things.
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by PB.
because it makes your executables smaller. For example, compile both these
lines into an executable, and you'll see that the API version is smaller...
One other reason why I like using the API: it makes translating source code
both to and from both C and Visual Basic so much easier. Quite often I read
the Visual Basic groups/help sites to find a way to do something, and as they
normally use API routines it makes it very easy to convert to PureBasic.
PB - Registered PureBasic Coder
Edited by - PB on 23 January 2002 19:01:19
No, not always. I prefer an API instead of the equivalent PureBasic commandBut that is because of the lack of build in commands of PureBasic!
because it makes your executables smaller. For example, compile both these
lines into an executable, and you'll see that the API version is smaller...
Code: Select all
; Example 1: This compiles to an exe of 6688 bytes.
MessageRequester("Test","hmm",0)
Code: Select all
; Example 2: This compiles to an exe of 4640 bytes.
MessageBox_(0,"hmm","Test",0)
both to and from both C and Visual Basic so much easier. Quite often I read
the Visual Basic groups/help sites to find a way to do something, and as they
normally use API routines it makes it very easy to convert to PureBasic.
PB - Registered PureBasic Coder
Edited by - PB on 23 January 2002 19:01:19