Gdi + wrappers

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
aloberoger
Posts: 480
Joined: Jan 13, 2009 19:23

Gdi + wrappers

Postby aloberoger » May 29, 2019 20:50

no need to chat, take a look
http://s000.tinyupload.com/?file_id=15433733343393883645

don't forget GdiPlusinitialize() and GDIPlusTerminate()

Code: Select all

 #Include Once "windows.bi"
#include Once "vbcompat.bi"
#include Once "win/winspool.bi"
    #include once "win/gdiplus.bi"
    using gdiplus



  #Include Once "GdiplussClasslib.bi"
 Using Drawing2D
 

Dim Shared As Integer ClientWidth=0,ClientHeight=0


Sub ExecuteGDIPlus(hdc As HDC)
   Dim As Graphics mGraphics=hdc
   
   Dim As Double xmax=10.0F , ymax=10.0F, xmin=0,ymin=0
   Dim As Single echx ,echy
   
   
   echx=(xmax-xmin)/ClientWidth   : echy= (ymax-ymin)/ClientHeight
   
   
   Dim As Drawing2D.Matrix m = Drawing2D.Matrix(1, 0, 0, -1, 0, 0)
   mGraphics.Transform = m
   mGraphics.TranslateTransform(0,ClientHeight , MatrixOrderAppend)
   mGraphics.scaleTransform(1/echx,1/echy)
       
         Dim redPen As Pen=Pen(Color.Red, 1*echx)
        mGraphics.DrawRectangle(redPen, 1.0F,1.0F,8.0F,8.0F)
   
   
     mGraphics.DrawLine(Pen(color.Green,5*echx), 1.0F,1.0F,9.0F,9.0F)
   


End Sub

Function WndProc(hWnd As HWND,uMsg As UINT,wParam As WPARAM,lParam As LPARAM) As Integer
   Dim ps As PAINTSTRUCT
   Static As HDC compHdc,hdc
   Dim rc As RECT
   Select Case uMsg
      Case WM_CLOSE
          GDIPlusTerminate()
         DeleteDC(compHdc)
         PostQuitMessage(0)
      
      Case WM_SIZE
         sendMessage(hwnd,WM_CREATE,wparam,lparam)
         'InvalidateRect(hwnd,NULL,TRUE)
         Return 0L
      Case WM_CREATE
         
         GDIPlusInitialize()
         
         GetClientRect(hwnd,@rc) : ClientWidth=rc.right-rc.left : ClientHeight=rc.Bottom-rc.top
         
         hdc=GetDC(GetDesktopWindow)
         compHdc=CreateCompatibleDC(hdc)
         Var bitmap = CreateCompatibleBitmap(hdc,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN))
         SelectObject(compHdc,bitmap)
         DeleteObject(bitmap)
         ReleaseDC(GetDesktopWindow,hdc)
         ExecuteGDIPlus(compHdc)
         InvalidateRect(hwnd,0,0)
      Case WM_PAINT
         BeginPaint(hWnd,@ps)
         BitBlt(ps.hdc,ps.rcPaint.left,ps.rcPaint.top,ps.rcPaint.right-ps.rcPaint.left,ps.rcPaint.bottom-ps.rcPaint.top,compHdc,ps.rcPaint.left,ps.rcPaint.top,SRCCOPY)
         EndPaint(hWnd,@ps)
         Return 0
      Case Else
         Return DefWindowProc(hWnd,uMsg,wParam,lParam)
   End Select
End Function


Dim wc As WNDCLASSEX
Dim  msg As MSG

With wc
   .hInstance=GetModuleHandle(0)
   .cbSize=SizeOf(WNDCLASSEX)
   .style=CS_HREDRAW Or CS_VREDRAW
   .lpfnWndProc=@WndProc
   .lpszClassName=StrPtr("classe")
   .hCursor=LoadCursor(NULL,IDC_ARROW)
End With
RegisterClassEx(@wc)
CreateWindowEx(0,wc.lpszClassName,"DrawGDI+",WS_OVERLAPPEDWINDOW Or WS_VISIBLE,200,200,640,480,0,0,wc.hInstance,0)

While GetMessage(@msg,0,0,0)
   TranslateMessage(@msg)
   DispatchMessage(@msg)
Wend

Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 1 guest