حالة الموضوع:
مغلق
  1. ●¦ Snharib ¦●

    ●¦ Snharib ¦● V • I • P

    الأنتساب:
    ‏8 يناير 2014
    المشاركات:
    1,128
    الإعجابات المتلقاة:
    1,786
    نقاط الجائزة:
    113
    الإقامة:
    || Iraq ||




    [​IMG]

    آسعد آلله آوقآتكُم ،

    [ الدرس الرابع] - برمجة خاصية تغير ايقونهالسيرفر .[ Vb.Net ]

    [​IMG]

    طبعاً هذاً الدرسً رح يكونً الدرس الأخيـ ـر .

    في الدروسً السابقةً قمنا بـبرمجةً البرنامج مع خصائص حلوة .

    وفي ِهذا الدرس رح تكون ْبرمجة الٌخاصية الأخيرة , لـذاً تم حَصر الدورة في 4 دِروس فقطْْ لًكي تقومواً بـأُضافة خصائص ٍومميزات بدِون مساعدة .

    [​IMG]

    1- نضعً الكود التالي : في كلاس . ونقوم بـتغير أسم الكلاس الى : Class icone injector

    [NOTE]Imports System.Runtime.InteropServices
    Imports System.Security
    'Coded By : Snharib -IqTEAM
    Public Class IconInjector
    <SuppressUnmanagedCodeSecurity()> _
    Private Class NativeMethods
    <DllImport("kernel32")> _
    Public Shared Function BeginUpdateResource( _
    ByVal fileName As String, _
    <MarshalAs(UnmanagedType.Bool)> ByVal deleteExistingResources As Boolean) As IntPtr
    End Function
    <DllImport("kernel32")> _
    Public Shared Function UpdateResource( _
    ByVal hUpdate As IntPtr, _
    ByVal type As IntPtr, _
    ByVal name As IntPtr, _
    ByVal language As Short, _
    <MarshalAs(UnmanagedType.LPArray, SizeParamIndex:=5)> _
    ByVal data() As Byte, _
    ByVal dataSize As Integer) As <MarshalAs(UnmanagedType.Bool)> Boolean
    End Function
    <DllImport("kernel32")> _
    Public Shared Function EndUpdateResource( _
    ByVal hUpdate As IntPtr, _
    <MarshalAs(UnmanagedType.Bool)> ByVal discard As Boolean) As <MarshalAs(UnmanagedType.Bool)> Boolean
    End Function
    End Class
    <StructLayout(LayoutKind.Sequential)> _
    Private Structure ICONDIR
    Public Reserved As UShort
    Public Type As UShort
    Public Count As UShort
    End Structure
    <StructLayout(LayoutKind.Sequential)> _
    Private Structure ICONDIRENTRY
    Public Width As Byte
    Public Height As Byte
    Public ColorCount As Byte
    Public Reserved As Byte
    Public Planes As UShort
    Public BitCount As UShort
    Public BytesInRes As Integer
    Public ImageOffset As Integer
    End Structure
    <StructLayout(LayoutKind.Sequential)> _
    Private Structure BITMAPINFOHEADER
    Public Size As UInteger
    Public Width As Integer
    Public Height As Integer
    Public Planes As UShort
    Public BitCount As UShort
    Public Compression As UInteger
    Public SizeImage As UInteger
    Public XPelsPerMeter As Integer
    Public YPelsPerMeter As Integer
    Public ClrUsed As UInteger
    Public ClrImportant As UInteger
    End Structure
    <StructLayout(LayoutKind.Sequential, Pack:=2)> _
    Private Structure GRPICONDIRENTRY
    Public Width As Byte
    Public Height As Byte
    Public ColorCount As Byte
    Public Reserved As Byte
    Public Planes As UShort
    Public BitCount As UShort
    Public BytesInRes As Integer
    Public ID As UShort
    End Structure
    Public Shared Sub InjectIcon(ByVal exeFileName As String, ByVal iconFileName As String)
    InjectIcon(exeFileName, iconFileName, 1, 1)
    End Sub
    Public Shared Sub InjectIcon(ByVal exeFileName As String, ByVal iconFileName As String, ByVal iconGroupID As UInteger, ByVal iconBaseID As UInteger)
    Const RT_ICON = 3UI
    Const RT_GROUP_ICON = 14UI
    Dim iconFile As IconFile = iconFile.FromFile(iconFileName)
    Dim hUpdate = NativeMethods.BeginUpdateResource(exeFileName, False)
    Dim data = iconFile.CreateIconGroupData(iconBaseID)
    NativeMethods.UpdateResource(hUpdate, New IntPtr(RT_GROUP_ICON), New IntPtr(iconGroupID), 0, data, data.Length)
    For i = 0 To iconFile.ImageCount - 1
    Dim image = iconFile.ImageData(i)
    NativeMethods.UpdateResource(hUpdate, New IntPtr(RT_ICON), New IntPtr(iconBaseID + i), 0, image, image.Length)
    Next
    NativeMethods.EndUpdateResource(hUpdate, False)
    End Sub
    Private Class IconFile
    Private iconDir As New ICONDIR
    Private iconEntry() As ICONDIRENTRY
    Private iconImage()() As Byte
    Public ReadOnly Property ImageCount() As Integer
    Get
    Return iconDir.Count
    End Get
    End Property
    Public ReadOnly Property ImageData(ByVal index As Integer) As Byte()
    Get
    Return iconImage(index)
    End Get
    End Property
    Private Sub New()
    End Sub
    Public Shared Function FromFile(ByVal filename As String) As IconFile
    Dim instance As New IconFile
    Dim fileBytes() As Byte = IO.File.ReadAllBytes(filename)
    Dim pinnedBytes = GCHandle.Alloc(fileBytes, GCHandleType.Pinned)
    instance.iconDir = DirectCast(Marshal.PtrToStructure(pinnedBytes.AddrOfPinnedObject, GetType(ICONDIR)), ICONDIR)
    instance.iconEntry = New ICONDIRENTRY(instance.iconDir.Count - 1) {}
    instance.iconImage = New Byte(instance.iconDir.Count - 1)() {}
    Dim offset = Marshal.SizeOf(instance.iconDir)
    Dim iconDirEntryType = GetType(ICONDIRENTRY)
    Dim size = Marshal.SizeOf(iconDirEntryType)
    For i = 0 To instance.iconDir.Count - 1
    Dim entry = DirectCast(Marshal.PtrToStructure(New IntPtr(pinnedBytes.AddrOfPinnedObject.ToInt64 + offset), iconDirEntryType), ICONDIRENTRY)
    instance.iconEntry(i) = entry
    instance.iconImage(i) = New Byte(entry.BytesInRes - 1) {}
    Buffer.BlockCopy(fileBytes, entry.ImageOffset, instance.iconImage(i), 0, entry.BytesInRes)
    offset += size
    Next
    pinnedBytes.Free()
    Return instance
    End Function
    Public Function CreateIconGroupData(ByVal iconBaseID As UInteger) As Byte()
    Dim sizeOfIconGroupData As Integer = Marshal.SizeOf(GetType(ICONDIR)) + Marshal.SizeOf(GetType(GRPICONDIRENTRY)) * ImageCount
    Dim data(sizeOfIconGroupData - 1) As Byte
    Dim pinnedData = GCHandle.Alloc(data, GCHandleType.Pinned)
    Marshal.StructureToPtr(iconDir, pinnedData.AddrOfPinnedObject, False)
    Dim offset = Marshal.SizeOf(iconDir)
    For i = 0 To ImageCount - 1
    Dim grpEntry As New GRPICONDIRENTRY
    Dim bitmapheader As New BITMAPINFOHEADER
    Dim pinnedBitmapInfoHeader = GCHandle.Alloc(bitmapheader, GCHandleType.Pinned)
    Marshal.Copy(ImageData(i), 0, pinnedBitmapInfoHeader.AddrOfPinnedObject, Marshal.SizeOf(GetType(BITMAPINFOHEADER)))
    pinnedBitmapInfoHeader.Free()
    grpEntry.Width = iconEntry(i).Width
    grpEntry.Height = iconEntry(i).Height
    grpEntry.ColorCount = iconEntry(i).ColorCount
    grpEntry.Reserved = iconEntry(i).Reserved
    grpEntry.Planes = bitmapheader.Planes
    grpEntry.BitCount = bitmapheader.BitCount
    grpEntry.BytesInRes = iconEntry(i).BytesInRes
    grpEntry.ID = CType(iconBaseID + i, UShort)
    Marshal.StructureToPtr(grpEntry, New IntPtr(pinnedData.AddrOfPinnedObject.ToInt64 + offset), False)
    offset += Marshal.SizeOf(GetType(GRPICONDIRENTRY))
    Next
    pinnedData.Free()
    Return data
    End Function
    End Class
    End Class

    [/NOTE]

    2- نحتاج فورم جديد و ( Button 3 ) و ( TextBox 2 ) و PictureBox1

    نقوم باخفاء ال PictureBox1 .

    ثم نقوم بـترتيبهاً بهذا الشكل :

    [​IMG]

    3- نفتح كود ال زر الأول ( File1 ) ونضع بداخله الكود التالي :

    [INFO] Dim OpenFileDialog As New OpenFileDialog
    With OpenFileDialog
    .Filter = "Executable File (*.exe)|*.exe"
    .Title = "Add File ..."
    If .ShowDialog = Windows.Forms.DialogResult.OK Then
    TextBox1.Text = .FileName
    End If
    End With
    End Sub[/INFO]

    هذا الكود لفتح الملف المراد تغير ايقونته.

    4- نفتح كود ال زر الثاني ( File2 ) ونضع بداخله الكود التالي :

    [INFO] Dim OpenFileDialog1 As New OpenFileDialog
    With OpenFileDialog1
    .Filter = "Executable File (*.ico)|*.ico"
    .Title = "Add File ..."
    If .ShowDialog = Windows.Forms.DialogResult.OK Then
    TextBox2.Text = .FileName
    PictureBox1.Image = Image.FromFile(TextBox2.Text)
    End If
    End With[/INFO]

    هذا الكود لأختيار الأيقونه ( شرط بـصيغة Ico )

    5- نفتح كود ال زر الثالثChange( File2 ) ونضع بداخله الكود التالي :

    [NOTE]fichier = TextBox1.Text
    icone = TextBox2.Text
    IconInjector.InjectIcon(fichier, icone)
    MsgBox("Icon Was Changed Successful.", MsgBoxStyle.OkOnly, "Successful")
    TextBox1.Clear()
    TextBox2.Clear()[/NOTE]

    اما هذا الكود لـدمج الأيقونه بالسيرفر بأختصار تنفيذ العملية .


    6- ألان في الفورم الرئيسي Form1 نضع CheckBox ونقوم بـتسميته Icon Changer . ثم نضع بداخله الكود التالي :

    [WARNING]If CheckBox3.Checked = True Then
    Form2.Show()
    End If[/WARNING]

    لأضهار فورم تغير الأيقونه .

    [​IMG]

    .: | الخاتمة | :.

    آيهآ آلآحية , لآ زآل هنآك مآلدينآ لنقدمة لكمَ ، ولآكنَ شرحنآ آلمهم وليسَ آلكمآليآت تستطيعونُ

    آضآفة الأنتشار والتطوير وآلثيمآت وغيرهآ ، لمَ نشرحهآ لآن آلآن بآذن آلله بمقدرونَ آلجميع آضآفة


    لذاً نرجوا من الجميعً عدم ً التوقفً هنا ’ نرجو الأستمرار في تطوير البرنامج .

    تَــمَّ , ڤِي أَمان اللّٰه .

    [​IMG]

     
  2. ●¦ Snharib ¦●

    ●¦ Snharib ¦● V • I • P

    الأنتساب:
    ‏8 يناير 2014
    المشاركات:
    1,128
    الإعجابات المتلقاة:
    1,786
    نقاط الجائزة:
    113
    الإقامة:
    || Iraq ||
    رد: [ الدرس الرابع] - برمجة خاصية تغير ايقونه السيرفر . [ Vb.Net ]

    للآستفسآرآتُ : يرجىُ زيآرة آلموضوع آلتآليُ .

    (( - http://www.iq-team.org/vb/t24888.html - ))

     
حالة الموضوع:
مغلق

مشاركة هذه الصفحة