المساعدة - البحث - قائمة الأعضاء - التقويم
نسخة كاملة: XP Styles in VB6
برمجة - شبكات - كمبيوتر - منتديات الفريق العربي للبرمجة > منتديات لغات البرمجة العام > منتدى مبرمجي لغة Microsoft Visual Basic 6 وما قبلها من إصدارات > قسم الدروس والمواضيع الهامة
msayed2004
بعد استئذان الأخ HnHn هقدم لكم درس بس بالأنجليزية و يارب يكون سهل :

[LTR]
This tutorial is about enabling XP styles for the VB standard controls only, also will not work for the Frame control


Since VB6 is an old language (in comparison with last windows version) it does not support drawing the XP styles on its controls and because Microsoft no more support VB6 we should not except a direct solution for this issue.

إقتباس(Steve McMahon)
The New XP Styles

The Windows XP Visual Styles are provided by ComCtl32.dll version 6 or later. (In fact, anyone who is as old as me and remembers back to Visual Basic 3 may find this familiar, since the exciting 3D control look which was provided with Windows 95 was also implemented in the same way). Note that unlike previous versions of this DLL, version 6 is not redistributable - which sadly means you can only use the visual styles on an operating system that has this version installed. At the time of writing this means XP only.

ComCtl32 does not apply the latest styles to the client area of an application by default. In order to enable it, you need to ensure that your application is linked to ComCtl32.dll (by calling the ComCtl InitCommonControls API call) and then you need to provide a Manifest which specifies that the new version of the control styles should be used.


To show XP styles in our VB6 products we need to do 3 steps :
1-Including a special manifest file with our project.
2-Initialize the common controls by calling the InitCommonControlsEx API (supported by comctl32.dll).
3-Protect our application from possible GPF (General Protection Fault) while closing the application.

1-The manifest file should be in the same directory (folder) of our application this file should be named as follow :
If our application name (including the extension) is Test.exe the manifest file should be Test.exe.manifest.

Contents of the manifest file :
كود
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

   <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">

   <assemblyIdentity

       version="1.0.0.0"

       processorArchitecture="X86"

       name="*"

       type="win32"

   />

   <description>XP Styles</description>

   <dependency>

       <dependentAssembly>

           <assemblyIdentity

               type="win32"

               name="Microsoft.Windows.Common-Controls"

               version="6.0.0.0"

               processorArchitecture="X86"

               publicKeyToken="6595b64144ccf1df"

               language="*"

           />

       </dependentAssembly>

   </dependency>

   </assembly>


2-Initialize the common controls : do this once at the start of your application :
كود
'APIs declarations:

   Private Type tagInitCommonControlsEx

      lngSize As Long

      lngICC As Long

   End Type

   Private Declare Function InitCommonControlsEx Lib "comctl32.dll" (iccex As tagInitCommonControlsEx) As Boolean

   Private Const ICC_USEREX_CLASSES = &H200


Now we just need to call the following function :

كود
Private Function InitCommonControlsVB() As Boolean

      On Error Resume Next

      Dim iccex As tagInitCommonControlsEx

      

      With iccex

          .lngSize = LenB(iccex)

          .lngICC = ICC_USEREX_CLASSES

      End With

      

      InitCommonControlsEx iccex

      InitCommonControlsVB = (Err.Number = 0)

      On Error GoTo 0

   End Function


Warning : Including the manifest file without initializing the common controls will result in the following error :



3-After using the previous method to give your application XP styles it mau crash when you close it (GPF) hence we should prevent this , this can be done by calling the SetErrorMode API (supported by kernel32.dll) & set the mode to SEM_NOGPFAULTERRORBOX

كود
'APIs declarations:

   Public Const SEM_NOGPFAULTERRORBOX = &H2

   Public Declare Function SetErrorMode Lib "kernel32" (ByVal wMode As Long) As Long


then we can just call it :
كود
SetErrorMode SEM_NOGPFAULTERRORBOX


but this should be carried out just outside the IDE (Integrated Development Environment) =outside the VB design environment = as EXE

To detect if we are in the IDE or not we can use a simple method (by Steve McMahon) :
كود
'In the General part of the declarations area:

   Public m_bInIDE As Boolean


كود
Public Property Get InIDE() As Boolean

      Debug.Assert (IsInIDE())

      InIDE = m_bInIDE

   End Property

  

   Private Function IsInIDE() As Boolean

      m_bInIDE = True

      IsInIDE = m_bInIDE

   End Function


Now we can use the property InIDE to detect if we are in the IDE or not (Returns true if we are in the IDE & False if not).

So we can call the SetErrorMode as follow :
كود
If Not InIDE() Then

      SetErrorMode SEM_NOGPFAULTERRORBOX

   End If


GPF snapshots :






-----------------------------------------------------------------

Standard VB Frame problems with XP styles :

The lack of hDC property for the VB frame cause 3 problems :
  • It does not show XP syles even with the above code.
  • It flicker with mouse movement.
  • Controls on it appear in a weird manner (see the following snapshot) , this mainly occur to the Option buttons and command buttons borders but with some themes it occur to other controls


The 3rd problem can be resolved by using another container (ex.: a border-less Picture-Box)over the frame to hold (contain) the controls instead of the frame itself.

The only available way to avoid all these problems is to use another frame control , here is a free , open sourced & efficient frame :

Replacent Frame Control for XP

-----------------------------------------------------------------

Other controls that show XP styles with no effort (All by VB & All are open sourced) :

LaVolpe Buttons

dcButton ActiveX Control

McToolBar 2.3

XTab

Candy Button

vbAccelerator Toolbar and CoolMenu Control v3.5

vbAccelerator Progress Bar Control

Media Progress Bar

vbAccelerator Explorer Bar Control

vbAccelerator No Status Bar Control

vbAccelerator TabStrip Control

vbAccelerator Visual Studio Style Tab Control

vbAccelerator MDITabs Control

-----------------------------------------------------------------

For easier and faster XP styles addition I made a project that can be added to your VB projects templates
كود
<Program Files path>Microsoft Visual StudioVB98TemplateProjects


Click here to download a self extracting file contain that project

This will add 4 files :
  • frmMain.frm
  • MainMod.bas
  • Standard EXE with XP Styles.vbp
  • Standard EXE with XP Styles.vbw
When you open your VB 6 a new item will appear in the New Project window named : Standard EXE with XP Styles.

Select it and you will have a project with a form (frmMain) and module (MainMod).

When you select to save your project VB will not ask you to save the module , I have no solution for this problem but you can save it manually or make any change in that module then undo it then the VB will ask you to save it with the rest of the project.

[/LTR]
حريف برمجة
عمو محمد فينك ياسيدى انت تشرح باى لغة انشلة اللغة الفرقشتانية laugh.gif هو الشرح ده كان فى المنتدى التانى ولا ايه wink_smile.gif
حريف برمجة
انا كنت استعمل هذة الطريقة منذ قديم الازل لكننى لم اكن اعرف ما هو الملف manifest وكل تلك الجمل يمكن ان تتلخص فى كلمتين اثنين لمن لا يريد الاطالة

اولا كود الخاص باستخدام الادوات القياسية الخاصة بالويندوس

كود
Declare Sub InitCommonControls Lib "comctl32" ()

Private Sub Form_Load()
InitCommonControls
End Sub


طبعا مع تسمية اسم الملف التنفيزى بعد ترجمته باسم المكتبة manifest

واعزرنى اخ محمد فهناك الكثيرون من لا يتقنون اللغة الانجليزية واذا كان عندك الوقت للترجمة ارجو ان تفعل اذا كان ذلك لن يؤثر عليك shades_smile.gif sad.gif sad.gif sad.gif
msayed2004
صعب أنى أترجم كل ده

إقتباس(حريف برمجة @ Mar 9 2007, 11:01 PM) [snapback]605617[/snapback]
هو الشرح ده كان فى المنتدى التانى ولا ايه wink_smile.gif



ايوه كان فى منتدى تانى بس برده أنا اللى كنت كاتبه من الأول للآخر wink_smile.gif و المره دى معدل عليه كمان.

بس ماكنش فى الـ vbforums
حريف برمجة
انا بعد كدة هعمل بحث فى جوجل على Msayed2004 عشان الاقى موضيعك الى انت مشتتها laugh.gif

انا مش شايف ليه رد الاعضاء هو الموضوع صعب اوى كدة
dj-siba
ما فـــائدة XP Styles ؟
msayed2004
إقتباس(dj-siba @ Mar 10 2007, 01:27 PM) [snapback]605795[/snapback]
ما فـــائدة XP Styles ؟


فى مبرمجين VB كتيير و اجهم مشاكل مع عملائهم بسبب كده لأنهم بيحبوا كل برامجهم تاخد نفس الـ Theme اللى بيحبوها


وفى الأول و الآخر ده موضوع جمالى لمشروعك و بالحل اللى أنا حطه فى آخر المشروع محدش هيتعب فيها
HnHn








يعطيك العافيه اخ msayed2004 على ما تقدم من معلومات ممتعه بحق وخصوصا انها مبنيه على

الشفرات فقط .. وهذا بحد ذاته يقلص عملية اضافة الاداوت في البرامج وقد تفيد من هم لا يعرفون سو السرعة في انجاز ما يريدون laugh.gif

على العموم اخ حريف برمجة اول المتفاعلين مع الموضوع وهذا ليس بغريب عليك الله يعطيك العافيه

وفعلا كما تقدمت اخ msayed2004

ان هناك من هم يفضل الشكليات في برامجه وانا احدهم cool.gifلآنها تعطي دافع على كمال الوجه الاخر من البرنامج وتميز المبرمج

وذوقه وكنت آنا ذاك لأتقن عملية اخذ ثيمات XP استخدم شفرة التلامس وهو صنف من أصناف

API يسمى بـ INITCOMMONCONTROLSEX_TYPE

كما ذكرتموها ولكن بطريقة مختلفه وكانت تركيبتها كالتالي ..... كنوع من الاضافة للموضوع ان كنت تسمح طبعا

حيث سنحتاج الى Module1 نضع بداخله الآتي

كود
Public Type INITCOMMONCONTROLSEX_TYPE
    dwSize As Long
    dwICC As Long
End Type
Public Declare Function InitCommonControlsEx Lib "comctl32.dll" (lpInitCtrls As _
    INITCOMMONCONTROLSEX_TYPE) As Long
Public Const ICC_INTERNET_CLASSES = &H800



وقم برسم اداوت على الفورم من اي نوع كــ

Option1
Command1
Text1
Combo1
VScroll1



وفي حدث Form_Initialize


كود
Private Sub Form_Initialize()
    Dim comctls As INITCOMMONCONTROLSEX_TYPE
    Dim retval As Long
    With comctls
        .dwSize = Len(comctls)
        .dwICC = ICC_INTERNET_CLASSES
    End With
    retval = InitCommonControlsEx(comctls)
End Sub


وكما تفضل الاخ حريف برمجة فالشفرات متعددة فمنها ما هو مختصر ومنها ما هو مطول وذلك راجع على من ابتكرها وانت بمقدورك ان تبتكر افضل منها ... فهي البرمجة وهي المتعه

ولو تلاحظ الشفرة التي وضعتها أنا ووضعها الاخ msayed2004 والآخ حريف البرمجه انها تعتمد على بدرجه الأولى على مكتبة comctl32.dll

وهذه هي المكتبات الرئيسة لنظم التشغيل Windows. وباقي الملفات تعتبر فرعية لاداء اغراض معينة. فمكتبة COMCTL32.DLL هي خاصة بادوات Windows الشائعة Windows Common Controls والتي ظهرت منذ الاصدار Win95

يعني ان هذه الشفرة ستتماشى مع كل اصدارات XP بما فيها الفيستا بما ان هذه المكتبة موجودة


هذا ما اردت المشاركة به من اجل تدعيم الموضوع بما أنه يتكلم على نفس الجانب ... وبالتوفيق للجميع

حريف برمجة
لم اكن اعلم ان الموضوع سياخذ كل هذا القدرمن الاهمية وشكرا لم اخى HnHn على تشجيعك وعلى اضافتك المتميزة ولكن للعلم تجميل البرامج من المواضيع المهمة جدا ويمكن ان يكون احد البرامج على قدر كبير من الكفائة ولكن شكلة ليس كما ينبغى وياخذ اسيضا شكل الاكس بي باخنصار ان البرنامج التجارى الذى يعمل على الاكس بى وياخذ شكل ويندوس 9x هو برنامج غبى ومبرمجة اغبى فاصبح المستخدمين الان ينظرون للبرنامج من حيث الواجهة

ولكن كما اجمع الجميع ان استخدام الادوات غير مجدى لاسباب كثيرة منها انها ثقيلة على المعالج ويمكن سرقتها من البرنامج فيكفى اخذ ملف الاداه من مجلد البرنامج ولكن الطرق لم تنتهى عند هذا الحد فهناك فكرة اخرى وهى دمج الاداه مع البرنامج اى عمل user control ويتم ترجمتها مع الملف التنفيزى ولذك يمكننا الخروج عن شكل الويندوس اكس بى التقليدى + ان برامجنا ستعمل بنفس الزيم مع نظم التشغيل الاقدم (النوافز)
msayed2004
أضافة متميزه من الأخ هانى كما عهدنا منه , شاكر جدا ليك و لكل المهتمين بالموضوع.
Montuia
كان شرحا تفصيلا رائع نأمل ان تكون جميع الموضيع بهذا الشرح
اشكرك بشده
Keep Going..=>
Arab Organ
ماأشتغلت معي الطريقه ... يمكن انا مافهمت؟
msayed2004
حاول تستعمل الـ Template لاحظ أن الويندوز لازم يكون بيدعم الـ XP Styles و تجرب الموضوع ده كـ EXE و ليس من داخل الـ VB
A7med_prof
للأفاده راجع : XP Style for Visual Basic

بالتوفيق ,,,,,,,,,

A7med_prof
م/محمود عبدالعزيز
بارك الله فيك
Xpert2005
عايز أعرف حاجة بالنسبة للملف manifest يعني لازم يكون موجود امام الملف التنفيذي؟
يعني مفيش طريقة أستغني بيها عن وجوده يعني ؟
msayed2004
لأ

و عندك حلين يا أما طريقتى أو حفظة كـ Resources و أستخراجة (أبطأ) , عموما أنت مش محتاجة بعد تطبيق الـ Styles على الأدوات.
DreamNet
السلام عليكم ورحمة الله وبركاته

على ذكر ال resources عندي ملف فيه ال manifest ولا تحتاج الى استخراجه
هل تصدقون ؟

يعني فقط عليك اضافته الى مشروعك وعمل InitCommonControls وستحصل على نفس النتيجة

سأرفقه في المرة القادمة ان شاء الله
msayed2004
موجود على موقع http://www.vbaccelerator.com/home/index.asp لكن أعتقد أنه من الضرورى أستخراجة , عموما نراجع المشروع اللى على الموقع.
DreamNet
أهلا مجددا

كنت أفكر مثلك أخي لكن عليك تجربة الملف

في الموقع الذي أوردته يتحدث عن الطريقة
إقتباس
A more robust method is to compile the manifest as a resource in your application. To do this, the manifest must appear as resource type RT_MANIFEST (24) with id CREATEPROCESS_MANIFEST_RESOURCE_ID (1). For some bizarre reason, you must also ensure that the resulting XML file is an even multiple of 4 bytes long. So for example, if your file is actually 597 bytes you need to add padding spaces to make up the file size to 600 bytes before compiling. The Resource examples demonstrate how to create this resource file using a resource compiler script (.rc file) and RC.exe.


بالتوفيق ان شاء الله للجميع
Xpert2005
فعلا أنا جربت الملف
وطلع عندي نفس النتيجة بدون ماستخرج الملف من الروسورس

طيب ممكن أستفيد من الطريقة دي في وضع ملف الصوت

متشكرين على الملف
هذه "نسخة - خفيفة" من محتويات الرئيسية للإستعراض الكامل مع المزيد من الصور والخيارات الرجاء إضغط هنا.
Invision Power Board © 2001-2009 Invision Power Services, Inc.