{$cleq} {$res noversioninfo,nomanifest} {$res icon "xpview.ico",exeicon "xpview.ico"} const appName="XP-View" const appVersion="0.5" const appTitle=appName+" "+appVersion set("AutoPaint",2) set("ErrorLevel",-1) #include dlgmenu.pcu = menu. #include usermessages.pcu = um. windowTitle appTitle windowStyle 1024 | 80 | 512 window 0,0 - 0,0 windowStyle 1 | 2 | 4 | 8 | 16 long hWnd2=createWindow(0,appTitle,200,200,maxx-400,maxy-400),\ hWnd2.hMenu=hWnd2.initMenu(),\ long hWnd2.hStatBar=create("statusWindow",hWnd2,"Bereit."),\ hWnd2.width,\ hWnd2.height,\ hWnd2.hVScroll=Create("VScroll",hWnd2,"",,,,),\ hWnd2.hHScroll=Create("HScroll",hWnd2,"",,,,),\ hWnd2.hpplPic=createPuppelPic(),\ hWnd2.hPuppel=create("bitmap",hWnd2,hWnd2.hpplPic,,,,),\ hWnd2.hXPuppel=control("STATIC","",$50000000/*-8*/,,,,,hWnd2,1000,%Hinstance,),\ hWnd2.hYPuppel=control("STATIC","",$50000000/*-8*/,,,,,hWnd2,1000,%Hinstance,),\ hWnd2.pHScroll,\ hWnd2.pVScroll long vp.centerX,\ vp.centerY,\ vp.mx,\ vp.my,\ vp.lmx,\ vp.lmy,\ vp.xx,\ vp.yy long hbm,bmx,bmy,bsx,bsy,\ h,\ l1,l2,\ float bScale=1,\ f,\ string s,\ tempPicFle,\ long mouse.x,mouse.y mem mouse.mem=point setclasslong(hWnd2,-12,65553) on.registerEvents() hwnd2.onIdle() app.createImage(,) select parCount caseOf 1 select par$(1) caseOf "-importFromClipboard" img.pasteFromClipboard() otherWise app.loadImage(par$(1)) endSelect endSelect do { hWnd2.waitInput() select abs(%menuItem) setMenuItem 0 caseOf 1999 : break caseOf 1000 : app.loadImageDlg() caseOf 3000 : app.saveImageDlg() caseOf 4000 : img.copyImageToClipboard() caseOf 4001 : img.pasteFromClipboard() caseOf 4008 : img.pasteFromClipboardNewFile() caseOf 8001 : app.about() endSelect select uMessage caseOf wm_mouseWheel if hiword(uwparam)==120 { vp.zoomIn() } else { vp.zoomOut() } caseOf wm_lbuttondown select childWindowFromPointEx(hWnd2,mouse.x,mouse.y,cwp_all) caseOf hWnd2.hPuppel previewFrame() endSelect caseOf wm_close : break endSelect } on.deregisterEvents() end img.copyImageToClipboard{ startPaint -1 saveBmpToClip 0,0 - bmx,bmy endPaint } img.pasteFromClipboardNewFile{ string tmpFle=getTmpFleName() startPaint -1 clipLoadBmp 0,0;0 long x=bmpX,\ y=bmpY endPaint if (x==0) or (y==0) { messageBox("Kein Bild in der Zwischenablage welches eingefügt werden kann.",appTitle,4096) } else { shell par$(0)+" -importFromClipboard" } } img.pasteFromClipboard{ string tmpFle=getTmpFleName() startPaint -1 clipLoadBmp 0,0;0 long x=bmpX,\ y=bmpY endPaint if (x==0) or (y==0) { messageBox("Kein Bild in der Zwischenablage welches übernommen werden kann.",appTitle,4096) } else { mcls x,y startPaint -1 clipLoadBmp 0,0;0 saveBmp tmpFle,0,0 - x,y endPaint app.loadImage(tmpfle) unlink(tmpFle) } } removeUserMessages{ setTimer 50 do { waitInput ifnot wmTimer { killTimer setTimer 50 continue } break } killTimer } colToHex(long col){ long r=getRValue(col),\ g=getGValue(col),\ b=getBValue(col) string ret=hex$(r),s case len(ret$)==1 : ret="0"+ret s=hex$(g) ret=ret+if(len(s)==1,"0"+s,s) s=hex$(b) return ret+if(len(s)==1,"0"+s,s) } previewFrame{ getMousePos() long omouse.x=mouse.x,\ omouse.y=mouse.y float xx=100,\ yy=100 if yy>xx { xx=100*bmx/bmy } else { yy=100*bmy/bmx } if xx>yy { float f=bmx/xx } else { float f=bmy/yy } float wxx=(vp.xx)/f/bScale,\ wyy=(vp.yy)/f/bScale setWindowPos hWnd=((mouse.x-xx*0.5)-1),((mouse.y-yy*0.5)-1) - xx+2,yy+2;-1 cls $888888 string tmpFle=getTmpFleName() mCopySizedBmp 0,0 - bmx,bmy > 1,1 - xx,yy;0 usepen 0,,0 rec(0,0,xx+1,yy+1) saveBmp tmpFle,0,0 - xx+2,yy+2 long tmpHPic=create("hPic",-1,tmpFle) unlink tmpFle setMousePos(winLeft+(hWnd2.pHScroll/f)+wxx*0.5,winTop+(hWnd2.pVScroll/f)+wyy*0.5) while lm_() { clipMouse(winLeft,winTop,winRight,winBottom) hWnd2.onIdle() getMousePos() sub mouse.x,%winLeft sub mouse.y,%winTop sub mouse.x,wxx*0.5 sub mouse.y,wyy*0.5 case mouse.x<-1 : mouse.x=-1 case mouse.y<-1 : mouse.y=-1 case mouse.x+wxx>xx+2 : mouse.x=xx-wxx+2 case mouse.y+wyy>yy+2 : mouse.y=yy-wyy+2 drawPic tmpHPic,0,0;0 usepen 0,0,0 rec(mouse.x+2,mouse.y+2,wxx-3,wyy-3) sleep 10 setScrollPos hWnd2.hHScroll,mouse.x*f setScrollPos hWnd2.hVScroll,mouse.y*f } clipMouse(,,maxX,maxY) setMousePos(oMouse.x,oMouse.y) setWindowPos hWnd=0,0 - 0,0;0 deleteObject tmpHPic hwnd2.rePaint() } app.loadImageDlg{ 'on.deregisterEvents() string op=getDir$("@") string s=loadFile$("Bilddatei öffnen:","Bilddateien;*.bmp;*.png;*.jpg;*.gif","*:*") chdir op 'on.registerEvents() case s=="" : return false return app.loadImage(s) } app.saveImageDlg{ 'on.deregisterEvents() string op=getDir$("@") string s=saveFile$("Bilddatei speichern:","*.*","*:*") chdir op 'on.registerEvents() case s=="" : return false return app.saveImage(s) } app.saveImage(string s){ string tmpFle=getTmpFleName()+".bmp" startPaint -1 saveBmp tmpFle,0,0 - bmx,bmy endPaint long tmpHPic=create("hPic",-1,tmpfle) savePic s,tmpHPic setText hWnd2.hStatBar,0,"Gespeichert, bereit." hWnd2.rePaint() } app.loadImage(string s){ if fileExists(s) { hbm=create("hPic",-1,s) if hbm { if (bmpx<=1800) and (bmpy<=1800) { bmx=bmpx bmy=bmpy bsx=0 bsy=0 mcls bmx+maxx,if(bmy*3>maxy,bmy*3,maxy),0 startPaint -1 drawPic hbm,,0;0 endPaint deleteObject hbm bScale=1 } else { msg("Bild konnte nicht geladen werden.") } } else { msg("Bild konnte nicht geladen werden.") } setText hWnd2.hStatBar,2,"A:"+str$(bmx)+"x"+str$(bmy) } else { app.createImage(0,0) } bScale=1 scrollBars.setup() hWnd2.onIdle() hWnd2.rePaint() } app.createImage(long x,y){ if (x<=1800) and (y<=1800) { bmx=x bmy=y bsx=0 bsy=0 bScale=1 mcls bmx+maxx,if(bmy*3>maxy,bmy*3,maxy),0 hWnd2.rePaint() setText hWnd2.hStatBar,2,"A:"+str$(bmx)+"x"+str$(bmy) } else { msg("Bild konnte nicht erzeugt werden.") } } on.registerEvents{ subClass hWnd2,true subClass hWnd2.hHScroll,true subClass hWnd2.hVScroll,true um.add wm_mouseWheel um.add wm_lbuttondown um.add wm_rbuttondown um.add wm_close } on.deregisterEvents{ um.reset() subClass hWnd2,false subClass hWnd2.hHScroll,false subClass hWnd2.hVScroll,false } hWnd2.rePaint(long tx,ty,bool scaled){ select pCount caseOf false tx=hWnd2.width ty=hWnd2.height scaled=true scrollBars.setup() endSelect if scaled { setWindowPos hWnd2.hStatBar=0,0 - 0,0;0 mem mem=16 Long mem#,0=200 Long mem#,4=500 Long mem#,8=650 Long mem#,12=-1 Sendmessage(hWnd2.hStatBar,$404,4,mem) Dispose mem } sub ty,height(hWnd2.hStatBar) sub tx,18 sub ty,18 startPaint -1 usepen 5,,0 usebrush 5,0 fillRec bmx,,maxx,maxy long bgmode=1 select bgMode caseOf 1 'copybmp bmx,0 - maxx,maxy > bmx,0; 'copybmp bmx,0 - maxx,maxy > bmx+2,2;2 caseOf 2 copybmp bmx,0 - maxx,maxy > bmx,0;4 copybmp bmx,0 - maxx,maxy > bmx+2,2;2 endSelect long bx=bmx*bScale,\ by=bmy*bScale,\ obx=bmx,\ oby=bmy,\ nx,\ ny nx=bmx ny=0 bsx=hWnd2.pHScroll bsy=hWnd2.pVScroll long cx=tx\2-bx\2,\ cy=ty\2-by\2 case cx<0 : cx=0 case cy<0 : cy=0 vp.centerX=nx+cx vp.centerY=ny+cy if (cx>0) and (cy>0) { add vp.centerX,9 add vp.centerY,9 } copysizedbmp_(bsx,bsy , obx,oby , vp.centerX,vp.centerY , bx,by,0) float tmpScale=1/bScale sub vp.centerX,bmx endPaint if bScale>=1 { float tmpx=tx\bScale*bScale,\ tmpy=ty\bScale*bScale } else { float tmpx=tx,\ tmpy=ty } vp.xx=tmpx vp.yy=tmpy startPaint hWnd2 if (cx=0) or (cy=0) { mcopybmp bmx,0 - tmpx,tmpy > 0,0;0 } else { mcopybmp bmx,0 - tmpx+18,tmpy+18 > 0,0;0 } endPaint long sx=tx-tmpx,\ sy=ty-tmpy-18 tx=tmpx+18 ty=tmpy+18 if (cx=0) or (cy=0) { setWindowPos hWnd2.hVScroll=(tx-18),0 - 18,ty-18;0 invalidateRect(hWnd2.hVScroll,,) updateWindow(hWnd2.hVScroll) setWindowPos hWnd2.hHScroll=0,(ty-18) - (tx-18),18;0 invalidateRect(hWnd2.hHScroll,,) updateWindow(hWnd2.hHScroll) setWindowPos hWnd2.hPuppel=(tx-18),(ty-18) - 18,18;0 invalidateRect(hWnd2.hPuppel,,) updateWindow(hWnd2.hPuppel) setWindowPos hWnd2.hXPuppel=(tmpx+18),0 - sx,(ty);0 invalidateRect(hWnd2.hXPuppel,,) updateWindow(hWnd2.hXPuppel) setWindowPos hWnd2.hYPuppel=0,(tmpy+18) - (tx+sx),sy+18;0 invalidateRect(hWnd2.hYPuppel,,) updateWindow(hWnd2.hYPuppel) } else { setWindowPos hWnd2.hVScroll=0,0-0,0 setWindowPos hWnd2.hHScroll==0,0-0,0 setWindowPos hWnd2.hPuppel==0,0-0,0 setWindowPos hWnd2.hXPuppel==0,0-0,0 setWindowPos hWnd2.hYPuppel==0,0-0,0 } setFocus(hWnd2) } copysizedbmp_(long x,y,xx,yy,xxx,yyy,xxxx,yyyy,mode){ float f=1 while (xxxx*f>vp.xx*2) and (yyyy*f>vp.yy*2) {f=f*0.5} copySizedBmp x,y - xx*f,yy*f > xxx,yyy - xxxx*f,yyyy*f;mode } scrollBars.setup{ scrollBarX.setup() scrollBarY.setup() } scrollBarX.setup{ scrollBar.setInfo(hWnd2.hHscroll,,bmx-1,(width(hWnd2)-18)/bScale,hWnd2.pHScroll) } scrollBarY.setup{ scrollBar.setInfo(hWnd2.hVscroll,,bmy-1,(height(hWnd2)-height(hWnd2.hStatBar)-18)/bScale,hWnd2.pVScroll) } vp.zoomIn{ if bScale<20 { bScale=bScale*2 long x=(width(hWnd2))/bScale hWnd2.pHScroll=(vp.mx-((x)*0.5)) long y=(height(hWnd2)-height(hWnd2.hStatBar))/bScale hWnd2.pVScroll=(vp.my-((y)*0.5)) scrollBars.setup() hWnd2.onIdle() hWnd2.rePaint(hWnd2.width,hWnd2.height,) } setText hwnd2.hStatBar,3,"Zoom: "+str$(bScale*100)+"%" } vp.zoomOut{ if bScale>0.03125*0.25 { bScale=bScale*0.5 long x=(width(hWnd2))/bScale hWnd2.pHScroll=(vp.mx-((x)*0.5)) long y=(height(hWnd2)-height(hWnd2.hStatBar))/bScale hWnd2.pVScroll=(vp.my-((y)*0.5)) scrollBars.setup() hWnd2.onIdle() hWnd2.rePaint(hWnd2.width,hWnd2.height,) } setText hwnd2.hStatBar,3,"Zoom: "+str$(bScale*100)+"%" } vp.mouse2Pic(long x,y){ vp.mx=mouse.x vp.my=mouse.y sub vp.mx,vp.centerX sub vp.my,vp.centerY vp.lmx=vp.mx vp.lmy=vp.my add vp.mx,bsx*bScale add vp.my,bsy*bScale vp.mx=vp.mx/bScale vp.my=vp.my/bScale vp.lmx=vp.lmx/bScale vp.lmy=vp.lmy/bScale case vp.mx>bmx-1:vp.mx=bmx-1 case vp.my>bmy-1:vp.my=bmy-1 case vp.mx<0 : vp.mx=0 case vp.my<0 : vp.my=0 } hWnd2.getMousePos{ mem gmp=8 clear gmp clientToScreen(hWnd2,gmp) int Gmx=Long(Gmp,) int Gmy=Long(Gmp,4) getCursorPos(Gmp) Gmx=Long(Gmp,)-Gmx Gmy=Long(Gmp,4)-Gmy mouse.x=gmx mouse.y=gmy dispose gmp vp.mouse2Pic(mouse.x,mouse.y) } hWnd2.initMenu{ long h=menu.new(hWnd2) menu.popup("&Datei") menu.appendMenu(1000,"Öffnen") menu.separator menu.appendMenu(3000,"Speichern unter") menu.separator menu.appendMenu(1999,"Beenden\tAlt+F4") menu.popup("&Bearbeiten") menu.appendmenu(4000,"Kopieren") menu.appendmenu(4001,"Einfügen") menu.separator menu.appendmenu(4008,"Einfügen neues Fenster") menu.popup("&Hilfe") menu.appendmenu(8001,"Über "+appTitle) return h } hWnd2.waitInput{ waitinput hWnd2.onIdle() } hWnd2.onIdle{ bool redrw,scale long tx=width(hWnd2),\ ty=height(hWnd2) if (tx<>hWnd2.width) or (ty<>hWnd2.height) { hWnd2.width=tx hWnd2.height=ty scrollBars.setup() redrw=true scale=true } long tmp1=getScrollPos(hWnd2.hHScroll),\ tmp2=getScrollPos(hWnd2.hVScroll),\ if (tmp1<>hWnd2.pHScroll) or (tmp2<>hWnd2.pVScroll) { hWnd2.pHScroll=tmp1 hWnd2.pVScroll=tmp2 redrw=true } case redrw:hWnd2.rePaint(hWnd2.width,hWnd2.height,scale) } rec(long x,y,xx,yy,col,col2){ if pcount==5 { usepen 2,,col } case pCount==6 : col=col2 add xx,x add yy,y line x,y - xx,y line x,y - x,yy line xx,y - xx,yy line x,yy - xx,yy setpixel xx,yy,col } fillRec(long x,y,xx,yy){ add xx,x+1 add yy,y+1 rectangle x,y - xx,yy } scrollBar.setInfo(long h,nmin,nmax,npage,npos){ mem si=scrollinfo with si .fmask&=sif_all .nmin&=nmin .nmax&=nmax .npage&=npage .npos&=npos .ntrackpos&=0 endwith sendmessage(h,sbm_setscrollinfo,true,si) dispose si } pokedw(long adr,float v){ long vi rtlMoveMemory(adr+2,addr(vi),2) vi=int(v-(vi*2^16)) rtlMoveMemory(adr,Addr(vi),2) } subClassProc{ hWnd2.onIdle() select sWnd caseOf hWnd2 select sMessage caseOf wm_getminmaxinfo pokeDW sLparam+24,200 pokeDW sLparam+28,200 caseOf wm_paint,wm_erasebkgnd,wm_activate hWnd2.rePaint(hWnd2.width,hWnd2.height,false) caseOf wm_mouseMove hWnd2.getMousePos() select childWindowFromPointEx(hWnd2,mouse.x,mouse.y,cwp_all) caseOf hWnd2 startPaint -1 setText hWnd2.hStatBar,1,"("+str$(vp.mx)+","+str$(vp.my)+") - #"+colToHex(getPixel(vp.mx,vp.my)) endPaint endSelect caseOf wm_keyDown select hiWord(slParam) caseOf 78 vp.zoomIn() caseOf 74 vp.zoomOut() otherwise endSelect endSelect endSelect } msg(string s){messageBox(s,appTitle,4096)} unlink(string fle){ long fh=assign(fle) erase fh assign fh,"" } getTmpFleName{ return $tempDir+"\\"+str$(getTickCount)+str$(rnd(999999)) } app.about{ msg("XProfan.Com's "+appTitle+" (C) 2008 by David Strutz\n\nhttp://xprofan.com") hWnd2.rePaint() } createPuppelPic{ mcls 18,18,$888888 startPaint -1 usepen 0,1,$FFFFFF rec(2,2,12,12,$FFFFFF) long h=Create("hPic",0,"&membmp") endpaint return h } lm_{;return if(getasynckeystate(1)==0,false,true);} rm_{;return if(getasynckeystate(2)==0,false,true);} whilem_{ while (lm_() | rm_()){ sleep 10 } } getmousepos{ GetCursorPos(mouse.mem) mouse.x:=mouse.mem::x& mouse.y:=mouse.mem::y& } setmousepos(long x,y){;setcursorpos(x,y);} clipmouse(long x,y,xx,yy){ mem mem=rect mem::left&:=x mem::top&:=y mem::right&:=xx mem::bottom&:=yy clipcursor(mem) dispose mem } mouse.close{ dispose mouse.mem }