1. Using GDI Plus with Win32Lib
- Posted by buzzo Jan 09, 2012
- 1318 views
Have attempted to use GDI Plus for displaying images reusing Al Getz's code from his example program. This example runs fine, and will display my jpeg's just fine; resizeing to boot.
Lifted Al's code, and adapted it to my project. My main window is created with Win32Lib.. However, the image does not appear in the main window. Seems there may be a problem with the handle(s) This is a portion of my code:
integer wH --wH=getHandle(win) -- no image --wH=getHandle("win") -- win32lib error message, but "continue" puts partial image is on desktop --wH=getHWND(win) -- no image --wH=getHWND("win") -- error wH=getId(win) -- partial image is on desktop --wH=getMainWindow() -- partial image is on desktop --wH=getIdName(win) -- error --wH=getIdName("win") -- error --wH=getNameId(win) -- error --wH=getNameId("win") -- partial image is on desktop --wH=getNameIdInContext("win", win) -- partial image is on desktop status=GdipCreateFromHWND(wH,ppGraphics) .......... more code, omited ......... The code does get the height and with properly: puts(1,w32ToString(Width)) puts(1,CrLf) puts(1,w32ToString(Height)) puts(1,CrLf) status=GdipDrawImageRectI(pGraphics,pImage, 40,20,Width,Height) -- returns 0
When the partial image is displayed, it is placed at 40, 20 on the desktop... "behind" the main window..
The image is never placed in the Main Window.. other "parts" of the project(in excess of 1400 lines of compact code) work fine..
Is GDI Plus not compatible with Win32Lib or am I missing something? Suggested fix?
This is on a Win 7 box..
Buzzo
2. Re: Using GDI Plus with Win32Lib
- Posted by BRyan Jan 09, 2012
- 1286 views
Always use ATOMS for any HANDLE when writing windows code
3. Re: Using GDI Plus with Win32Lib
- Posted by buzzo Jan 09, 2012
- 1302 views
Thanks... atom or integer give same result..
4. Re: Using GDI Plus with Win32Lib
- Posted by mattlewis (admin) Jan 09, 2012
- 1283 views
Is GDI Plus not compatible with Win32Lib or am I missing something? Suggested fix?
First, note that a Win32Lib id is not a HWND (Windows Handle). A Windows handle is a 32-bit value (technically, the size of a pointer), and so should always be an atom. The values used by Win32Lib are indices into a sequence, and so may be safely stored in an atom.
The ~GDIPlus library is not Win32Lib specific, and requires the actual Windows handle. You can get the Windows handle for any Win32Lib id using the Win32Lib function, getHandle(). Make sure that all of the values you pass to the GDIPlus library are generated like that.
Matt
5. Re: Using GDI Plus with Win32Lib
- Posted by BRyan Jan 09, 2012
- 1300 views
Why don't you try using this code which doesn't use win32lib to verify your code.
http://rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=gdi
6. Re: Using GDI Plus with Win32Lib
- Posted by buzzo Jan 09, 2012
- 1277 views
Matt,
My code:
atom wH wH=getHandle(win) -- no image
win is the constant generated here:
constant win = createEx( Window, "Relatives", 0, xWinPos, yWinPos, winWidth, winHeight, 0, 0 ), GStatus = create( StatusBar, " ", win, 0, {{300},0.46,-1}, 0, 0, 0 ),
Am I missing something?
Buzz
7. Re: Using GDI Plus with Win32Lib
- Posted by mattlewis (admin) Jan 09, 2012
- 1305 views
Matt,
My code:
atom wH wH=getHandle(win) -- no image
win is the constant generated here:
constant win = createEx( Window, "Relatives", 0, xWinPos, yWinPos, winWidth, winHeight, 0, 0 ), GStatus = create( StatusBar, " ", win, 0, {{300},0.46,-1}, 0, 0, 0 ),
Am I missing something?
That's the correct way to get handle. I can't comment on much else, since I've only seen a sliver of your code. I downloaded the GdiPlus library from the archives, and I can't find a match for the version of GdipCreateFromHWND that you're using. Your code shows you passing 2 parameters, but the copy I downloaded only takes one.
Matt
8. Re: Using GDI Plus with Win32Lib
- Posted by buzzo Jan 09, 2012
- 1289 views
Matt,
I am using GdiPlus Graphics Library 132K Al Getz Use search on the archives at RDS..
Buzz
9. Re: Using GDI Plus with Win32Lib
- Posted by mattlewis (admin) Jan 09, 2012
- 1286 views
Matt,
I am using GdiPlus Graphics Library 132K Al Getz Use search on the archives at RDS..
Oops, I downloaded Mike Duffy's version. I see that now. Still, I don't think there's anything else that can be said based on the bit of code that you've posted.
Matt
10. Re: Using GDI Plus with Win32Lib
- Posted by buzzo Jan 09, 2012
- 1266 views
Matt,
Thanks anyway If you think of a solution/fix, please let me know..
Buzzo
11. Re: Using GDI Plus with Win32Lib
- Posted by mattlewis (admin) Jan 09, 2012
- 1254 views
Matt,
Thanks anyway If you think of a solution/fix, please let me know..
Solution/fix to what?
Matt
12. Re: Using GDI Plus with Win32Lib
- Posted by buzzo Jan 09, 2012
- 1262 views
Matt,
This is from GDIPLUS ...
constant xGdipCreateFromHWND=lF(gdiplus,"GdipCreateFromHWND",{CP,CP},CL) global function GdipCreateFromHWND(atom hwnd,atom pp_graphics) --(HWND hwnd,GpGraphics **graphics) if gdiplus>0 then return c_func(xGdipCreateFromHWND,{hwnd,pp_graphics}) else return 0 end if end function
This is my code...
atom ppGraphics,ppImage,pGraphics atom wH wH=getHandle(win) -- no image status=GdipCreateFromHWND(wH,ppGraphics)
Atoms are atoms where they should be.. If you have no idea why this fails, that's OK... Maybe someone else will have a idea why atoms are not atoms?????? I'll be checking back from time to time..
Buzzo
13. Re: Using GDI Plus with Win32Lib
- Posted by mattlewis (admin) Jan 09, 2012
- 1234 views
Atoms are atoms where they should be.. If you have no idea why this fails, that's OK... Maybe someone else will have a idea why atoms are not atoms?????? I'll be checking back from time to time..
Well, one problem is that you didn't initialize ppGraphics. Don't you getting an error at that point? And then you never use it. What do you expect this code to do? I don't see it doing much of anything, unless you mean that you actually have more code (which your original post seems to imply).
No one will be able to help you if no one knows what your code looks like. I'm not sure what sort of answer you're expecting, but it since the demo works for you, it seems clear that you aren't using the library correctly. But without seeing what you're doing, that's about all I can say. So far, all you've provided are a few snippets of your code.
I'm sure someone on this forum can help you if you let them. Otherwise, I'd recommend examining each variable to make sure that it's correct, and that you're using it correctly. Right now, only you can do that, since only you have the code. At some point, you must be using something incorrectly, but so far, no one but you has seen enough of your code to know what might be happening.
If your code is very large, then try slimming it down to a minimal example that is easy to post. That also makes it easier to track down the problem, since you'll get rid of things unrelated to the problem. But note that a minimal example will have a lot more code than what you've provided. What we've seen so far won't even run, because it's only a fraction.
Matt
14. Re: Using GDI Plus with Win32Lib
- Posted by buzzo Jan 09, 2012
- 1289 views
Slimmed down code.. same results..
--testGDI-01.exw -- 1-9-2012 include machine.e include misc.e include Win32Lib.ew include dll.e include wildcard.e include gdiplus_Win98,XP.ew without warning sequence screenSize screenSize = getCtlSize( Screen ) -- get screen size global integer screenWidth screenWidth = screenSize[1] -- width global integer screenHeight screenHeight = screenSize[2] -- height integer winWidth winWidth = 1280 -- MAIN WINDOW WIDTH integer winHeight winHeight = 900 -- MAIN WINDOW WIDTH integer xWinPos xWinPos = floor((screenWidth - winWidth)/2) -- x postion on display for centering MAIN WINDOW integer yWinPos yWinPos = floor((screenHeight - winHeight)/2) -- y postion on display constant win = createEx( Window, "Relatives", 0, xWinPos, yWinPos, winWidth, winHeight, 0, 0 ), CrLf = { '\r', '\n' } --************ GdiPlus Specific code *************** global atom status,ppGraphics,ppImage,pGraphics,pImage status=GdipInitialize() if status!=0 then puts(1,"Cant open a required dll\n") sleep(1) end if --pointer vars for use with images pImage=0 ppGraphics=allocate(4) ppImage=allocate(4) procedure DoGraphics() puts(1,w32ToString(win)) puts(1,CrLf) sequence FilePath,FileName atom Width,Height,pUINT,status,x,y object lpFilePathW atom wH --wH=getHandle(win) -- no image --wH=getHandle("win") -- error message, but continue puts partial image is on desktop --wH=getHWND(win) -- no image --wH=getHWND("win") -- error wH=getId(win) -- partial image is on desktop --wH=getMainWindow() -- partial image is on desktop --wH=getIdName(win) -- error --wH=getIdName("win") -- error --wH=getNameId(win) -- error --wH=getNameId("win") -- partial image is on desktop --wH=getNameIdInContext("win", win) -- partial image is on desktop puts(1,w32ToString(wH)) puts(1,CrLf) -- **************** from GDI ***************** --constant xGdipCreateFromHWND=lF(gdiplus,"GdipCreateFromHWND",{CP,CP},CL) --global function GdipCreateFromHWND(atom hwnd,atom pp_graphics) -- --(HWND hwnd,GpGraphics **graphics) -- if gdiplus>0 then -- return c_func(xGdipCreateFromHWND,{hwnd,pp_graphics}) -- else -- return 0 -- end if --end function status=GdipCreateFromHWND(wH,ppGraphics) puts(1,w32ToString(status)) puts(1,CrLf) if status=0 then pGraphics=peek4u(ppGraphics) --the graphics object has been created. puts(1,w32ToString(pGraphics)) puts(1,CrLf) else pGraphics=0 end if FilePath="H:\\Euphoria\\relatives\\Genealogy\\JPark.jpg" if length(FilePath)>0 then --release old pic status=GdipDisposeImage(pImage) --load the file lpFilePathW=AnsiToUnicode(FilePath) status=GdipLoadImageFromFile(lpFilePathW,ppImage) FreeUnicode(lpFilePathW) if status=0 then pImage=peek4u(ppImage) puts(1,w32ToString(pImage)) puts(1,CrLf) else pImage=0 end if end if pUINT=allocate(4) status=GdipGetImageWidth(pImage,pUINT) Width=peek4u(pUINT) status=GdipGetImageHeight(pImage,pUINT) Height=peek4u(pUINT) --Width=Width/2 --Height=Height/2 puts(1,w32ToString(Width)) puts(1,CrLf) -- puts correct size puts(1,w32ToString(Height)) puts(1,CrLf) -- puts correct size -- ************* from GDI ************** --constant xGdipDrawImageRectI=lF(gdiplus,"GdipDrawImageRectI",{CP,CP,CI,CI,CI,CI},CL) --global function GdipDrawImageRectI(atom p_graphics,atom p_image,atom x,atom y,atom width,atom height) -- --(GpGraphics *graphics,GpImage *image,INT x,INT y,INT width,INT height) -- if gdiplus>0 then -- return c_func(xGdipDrawImageRectI,{p_graphics,p_image,x,y,width,height}) -- else -- return 0 -- end if --end function status=GdipDrawImageRectI(pGraphics,pImage, 40,20,Width,Height) puts(1,w32ToString(status)) puts(1,CrLf) free(pUINT) free(ppGraphics) free(ppImage) end procedure ------------------------------------------------------------------------------ DoGraphics() WinMain(win,Normal)
Buzzo
15. Re: Using GDI Plus with Win32Lib
- Posted by mattlewis (admin) Jan 09, 2012
- 1236 views
Slimmed down code.. same results..
DoGraphics() WinMain(win,Normal)
OK, first, remember to use getHandle() (or getHWND()) to convert your Win32Lib id into a valid windows handle. The next thing is that you need to put the call to DoGraphics() inside of a paint event handler:
procedure win_onPaint(integer Self, integer Event, sequence Params) DoGraphics() end procedure setHandler( win, w32HPaint, routine_id("win_onPaint"))
Basically, for anything that happens while your program is open, the code needs to be called from an event handler.
Matt
16. Re: Using GDI Plus with Win32Lib
- Posted by buzzo Jan 09, 2012
- 1269 views
Matt,
That did it...
I lost sight of the fact that the code I was lifting stuff from was not made with Win32Lib and did not need a handler..
Thanks for your help.
17. Re: Using GDI Plus with Win32Lib
- Posted by petelomax Jan 10, 2012
- 1326 views
I am using GdiPlus Graphics Library 132K Al Getz Use search on the archives at RDS..
Oops, I downloaded Mike Duffy's version.
I don't suppose we can get that search fixed - is Rob Craig still listening?
http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=gdiplus
so "gdiplus" lists Al Getz's entry but "gdi" does not.
Pete