Announcement

Collapse
No announcement yet.

C# and PB (example)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • C# and PB (example)

    If ever you need an example of using a PB/Win32 control from C#.

    I have written a small C# WinTutor based on GDImage
    showing the use of CONST, DLLimport, the creation of a GDImage control
    altogether with the use of CALLs to setup properties.

    Note: I am still learning


    ------------------
    Patrice Terrier
    mailto[email protected][email protected]</A>
    www.zapsolution.com
    Addons: WinLIFT (Skin Engine), GDImage (Graphic control), Artwork (logo creation), GDI+ Helper (GDIPLUS)
    Patrice Terrier
    www.zapsolution.com
    www.objreader.com
    Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

  • #2
    I would be interested.
    Recently I posted about needing help with C# and a dll that I built
    in PB

    I got everything working except when the parent form (C#) closes,
    even though I purposely (or think purposely) tell Windows to release
    my dll, I still get an error because it just won't let go.

    I too am still learning, but have a good programming background and
    can usually learn a lot from examples.



    ------------------
    Engineer's Motto: If it aint broke take it apart and fix it

    "If at 1st you don't succeed... call it version 1.0"

    "Half of Programming is coding"....."The other 90% is DEBUGGING"

    "Document my code????" .... "WHYYY??? do you think they call it CODE? "

    Comment


    • #3
      Cliff,

      Here is the link to download the ZoomPlus project.
      Download the demo
      It is written with "Visual C# 2005 Express".

      The GDImage.dll itself is written with PB/WIN 8.xx
      and it works like a charm with it.

      Of course the first thing to do is to create a Class
      to encapsulate the Win32 DLL, see below:
      class GDImage
      {
      // ANCHOR properties
      public const int ANCHOR_NONE = 0;
      public const int ANCHOR_WIDTH = 1;
      public const int ANCHOR_RIGHT = 2;
      public const int ANCHOR_CENTER_HORZ = 3;
      public const int ANCHOR_HEIGHT = 4;
      public const int ANCHOR_HEIGHT_WIDTH = 5;
      public const int ANCHOR_HEIGHT_RIGHT = 6;
      public const int ANCHOR_BOTTOM = 7;
      public const int ANCHOR_BOTTOM_WIDTH = 8;
      public const int ANCHOR_BOTTOM_RIGHT = 9;
      public const int ANCHOR_CENTER_HORZ_BOTTOM = 10;
      public const int ANCHOR_CENTER_VERT = 11;
      public const int ANCHOR_CENTER_VERT_RIGHT = 12;
      public const int ANCHOR_CENTER = 13;

      // ZD_DrawText constants
      public const int ZD_TextHorzUp = 0x0; // Horizontal text orientation
      public const int ZD_TextVertUp = 0x1; // Vertical text orientation from bottom to top
      public const int ZD_TextVertDn = 0x2; // Vertical text orientation from top to bottom
      public const int ZD_HIDE = 0x0; // FALSE
      public const int ZD_SHOW = 0x1; // TRUE

      // GDImage overlay Generic STYLE must be a 2^
      public const int ZS_HIDDEN = ZD_HIDE;
      public const int ZS_VISIBLE = ZD_SHOW; // VISIBLE, same as WS_VISIBLE
      public const int ZS_SCROLL = 0x2; // MOVE with scroll bars, default is FIX (do not scroll)
      public const int ZS_DRAFT = 0x4; // Draft drawing mode

      public const int ZI_FitToWindow = 7; // Resize the image to fit the view port
      // And use any of this constant as Parameter
      public const int ZI_QualityDefault = -1;
      public const int ZI_QualityGood = 1; // Best performance
      public const int ZI_QualityHigh = 2; // Best rendering quality

      public const int ZI_GradientTop = 5; // Set/Get top gradiant color backgroud
      public const int ZI_GradientBottom = 6; // Set/Get bottom gradiant color backgroud
      public const int ZI_ZoomWindow = 11; // Set/Get zoom window status
      public const int ZI_Orientation = 13; // Set/Get orientation

      public const int RotateNoneFlipNone = 0; // GDI+ constant
      public const int Rotate90FlipNone = 1; // GDI+ constant
      public const int Rotate180FlipNone = 2; // GDI+ constant
      public const int Rotate270FlipNone = 3; // GDI+ constant
      public const int RotateNoneFlipX = 4; // GDI+ constant
      public const int RotateNoneFlipY = 6; // GDI+ constant

      public const int ID_TEXT_HELL0 = 1; // Sprite text
      public const int ID_CTRL = 100;
      public const int ID_THUMB = 101;
      public const string Times_New_Roman = "Times New Roman"; // Must be a valid TTF
      public const string Arial_Black = "Arial Black"; // Must be a valid TTF
      private const string User32 = @"user32.dll";
      // private const string MyDLL = @"c:\travail\gdimage\gdimage.dll";
      private const string MyDLL = @"gdimage.dll";

      // Mimic Global
      // Keep track of the active picture name
      static public string sPicName = ""; // Default to ""
      static public IntPtr Ctrl = System.IntPtr.Zero; // Default to Zero
      static public IntPtr Thumb = System.IntPtr.Zero; // Default to Zero
      static public Boolean ShowThumb = false; // Default to false

      [DllImport(MyDLL)] // Register the GDImage Win32 class
      public static extern Boolean RegisterGDImageClass();

      [DllImport(MyDLL)] // Get the current GDImage version #
      public static extern string ZI_Version();

      [DllImport(MyDLL)] // Create a simplified GDImage control window
      public static extern IntPtr ZI_CreateWindow(
      IntPtr hParent, // The Window/Dialog container
      int x, // The control top left corner horizontal location
      int y, // The control top left corner vertical location
      int xW, // The control width
      int yH, // The control height
      int ControlID // The control unique IDentifier
      );

      [DllImport(MyDLL)] // Load image from file
      public static extern void ZI_SetFromFile(
      IntPtr hCtrl, // The GDImage control
      string zFullPath // The control unique IDentifier
      );

      [DllImport(MyDLL)] // Anchor control to the main window form
      public static extern void ZI_SetAnchorMode(
      IntPtr hCtrl, // The GDImage control
      int AnchorMode // The control unique IDentifier
      );

      [DllImport(MyDLL)] // Dialog file selector with thumbnail preview
      public static extern string ZI_LoadDialog(
      IntPtr hParent // The Window/Dialog container
      );

      [DllImport(MyDLL)] // Set property of a GDImage control
      public static extern void ZI_SetProperty(
      IntPtr hCtrl, // The GDImage control
      int nProperty, // A ZI_ predefined constant
      int nParam // A parameter matching the type of property to set or retrieve.
      );

      [DllImport(MyDLL)] // Get property of a GDImage control
      public static extern int ZI_GetProperty(
      IntPtr hCtrl, // The GDImage control
      int nProperty // A ZI_ predefined constant
      );

      [DllImport(MyDLL)] // Get the Device Context of a GDImage control
      public static extern int ZI_GetDC(
      IntPtr hCtrl // The GDImage control
      );

      [DllImport(MyDLL)] // Get width and height of a provide bitmap
      public static extern void ZI_GetBitmapSize(
      int hBitmap, // Handle to a standard bitmap.
      int BitmapWidth, // Width of the bitmap.
      int BitmapHeight // Height of the bitmap.
      );

      [DllImport(MyDLL)] // Load image from file and return a valid GDIPLUS image handle
      public static extern int zLoadImageFromFile(
      string zFullName, // Full path name to any of the supported graphic format.
      ref int imgW, // Return the image width.
      ref int imgH, // Return the image height.
      int Orientation // Orientation to create the memory image.
      );

      [DllImport(MyDLL)] // Save image to file using a valid GDIPLUS image handle.
      public static extern int zSaveImageToFile(
      string zFullName, // Full path name destination.
      int Img, // A valid GDIPLUS handle.
      int Quality // Quality applies to the JPEG format only.
      );

      [DllImport(MyDLL)] // Save image to file using a valid GDIPLUS image handle.
      public static extern int ZD_DrawTextToCtrl(
      IntPtr hCtrl, // The GDImage control
      string zUseTex, // The text to display.
      int x, // Top left X coordinate.
      int y, // Top left Y coordinate.
      int ColrARGB, // The ARGB color to use.
      string zUseFont, // The "Tue Type Font" name to use.
      int UseSize, // The size of the font in pixel.
      int ObjID, // The unique object IDentifier (each object MUST USE A UNIQUE one).
      int ZS_STYLE, // The object Generic STYLE (use at least ZS_VISIBLE to show it).
      int UseShadow, // The shadow 3D offset.
      int Orientation // The text orientation (%ZD_TextHorzUp, %ZD_TextVertUp, %ZD_TextVertDn).
      );

      [DllImport(MyDLL)] // Save image to file using a valid GDIPLUS image handle.
      public static extern int ZD_ColorARGB(
      byte AlphaChannel, // The translucency level ranging from 0 to 255.
      int RGB // The classical RGB() color to use.
      );

      [DllImport(User32)] // Win32 encapsulation
      public static extern IntPtr GetDlgItem(IntPtr hCtrl, int DlgItem);

      // Emulate standard Win32 RGB function
      public static int RGB(byte R, byte G, byte B) { return ((B * 256) + G) * 256 + R; }

      [DllImport(User32)] // Win32 encapsulation
      public static extern void MoveWindow(IntPtr hCtrl, int X, int Y, int W, int H, int Flag);

      }

      ------------------
      Patrice Terrier
      mailto[email protected][email protected]</A>
      www.zapsolution.com
      Addons: WinLIFT (Skin Engine), GDImage (Graphic control), Artwork (logo creation), GDI+ Helper (GDIPLUS)


      [This message has been edited by Patrice Terrier (edited September 21, 2006).]
      Patrice Terrier
      www.zapsolution.com
      www.objreader.com
      Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

      Comment

      Working...
      X