freebasic.net Forum Index
FreeBASIC's Official Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log inLog in

XP Visual Styles

 
Post new topic   Reply to topic    freebasic.net Forum Index -> Windows
View previous topic :: View next topic  
Author Message
MichaelW
Hero
PostPosted: Mar 20, 2007 8:54    Post subject: XP Visual Styles Reply with quote

I just went through this as a test, so I’m posting it as an example.

To use the XP visual styles you must create an application manifest that specifies which version of ComCtl32.dll should be used. As a minimum you can use the example manifest from here:
Code:

<?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="CompanyName.ProductName.YourApplication"
    Type="win32"
/>
<description>Your application description here.</description>
<dependency>
    <dependentAssembly>
        <assemblyIdentity
            Type="win32"
            Name="Microsoft.Windows.Common-Controls"
            version="6.0.0.0"
            processorArchitecture="X86"
            publicKeyToken="6595b64144ccf1df"
            language="*"
        />
    </dependentAssembly>
</dependency>
</assembly>
 

The application-specific data in the manifest is not necessary, so it can be used exactly as shown. The manifest must be stored in a file with the name appname.exe.manifest, where appname is the actual name of the EXE.

The application resource definition should be something like this:
Code:

#define RT_MANIFEST 24
#define CREATEPROCESS_MANIFEST_RESOURCE_ID  1

CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "test.exe.manifest"
 

By using CREATEPROCESS_MANIFEST_RESOURCE_ID the manifest is included in the executable, eliminating any dependence on the manifest file (although an appropriately named manifest file placed in the same directory as the EXE can still override the manifest in the EXE).

The test app:
Code:

'=========================================================================
#include "windows.bi"
#include "win/commctrl.bi"
'=========================================================================

Function Edit( Byref text As String, _
               Byval hParent As HWND, _
               Byval x As Integer, _
               Byval y As Integer, _
               Byval w As Integer, _
               Byval h As Integer, _
               Byval cid As Integer, _
               Byval style As Integer, _
               Byval extendedStyle As Integer = 0 ) As HWND

    Return CreateWindowEx( extendedStyle, _
                           "EDIT", _
                           text, _
                           style, _
                           x, y, w, h, _
                           hParent, _
                           cast( HMENU, cid ), _
                           GetModuleHandle( null ), _
                           null )
End Function

'=========================================================================

Function WindowProc( Byval hWnd As HWND,_
                     Byval uMsg As uint,_
                     Byval wParam As WPARAM,_
                     Byval lParam As LPARAM ) As LRESULT

    Static As HWND hEdit

    Select Case uMsg

      Case WM_CREATE

        '' Each character in the password will display as a
        '' black circle if the app is using the XP visual
        '' styles, or as an asterisk (*) if not.

        hEdit = Edit( "password", hWnd, 25, 28, 100, 30, 101, _
                      WS_CHILD Or WS_VISIBLE Or ES_PASSWORD, _
                      WS_EX_CLIENTEDGE )

      Case WM_CLOSE

        PostQuitMessage( null )

      Case Else

        Return DefWindowProc( hWnd, uMsg, wParam, lParam )

    End Select

    Return 0

End Function

'=========================================================================
'' Start of implicit main.
'=========================================================================

Dim hWnd As HWND
Dim wMsg As MSG
Dim As Integer wx, wy, nWidth, nHeight
Dim wcx As WNDCLASSEX
Dim className As String = "manifest_test_class"

InitCommonControls

With wcx
  .cbSize = sizeof( WNDCLASSEX )
  .style = CS_HREDRAW Or CS_VREDRAW Or CS_BYTEALIGNWINDOW
  .lpfnWndProc = cast( WNDPROC, @WindowProc )
  .cbClsExtra = null
  .cbWndExtra = null
  .hInstance = GetModuleHandle( null )
  .hbrBackground = cast( HBRUSH,COLOR_WINDOW + 1 )
  .lpszMenuName = null
  .lpszClassName = Strptr( className )
  .hIcon = LoadIcon( null, IDI_APPLICATION )
  .hCursor = LoadCursor ( null, IDC_ARROW )
  .hIconSm = 0
End With

RegisterClassEx( @wcx )

nWidth = 160
nHeight = 120
wx = (GetSystemMetrics( SM_CXSCREEN ) / 2) - nWidth / 2
wy = (GetSystemMetrics( SM_CYSCREEN ) / 2) - nHeight / 2

hWnd = CreateWindowEx( WS_EX_OVERLAPPEDWINDOW,_
                       Strptr( className ),_
                       "Test",_
                       WS_OVERLAPPED Or WS_SYSMENU,_
                       wx, wy, nWidth, nHeight,_
                       null, null,_
                       GetModuleHandle( null ), null )

ShowWindow( hWnd, SW_SHOWNORMAL )
UpdateWindow( hWnd )

Do Until( GetMessage( @wMsg, null, 0, 0 ) = 0 )
  TranslateMessage( @wMsg )
  DispatchMessage( @wMsg )
Loop
 
 
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    freebasic.net Forum Index -> Windows All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



sf.net phatcode