vb translation to pb?

Windows specific forum
roherter
User
User
Posts: 17
Joined: Fri Mar 10, 2006 9:49 am
Contact:

vb translation to pb?

Post by roherter »

Can anyone help me to change this vb-code to pb??

Code: Select all



'var for exposed property
Private m_lvInitialView As Long

'windows version constants
Private Const VER_PLATFORM_WIN32_NT As Long = 2
Private Const OSV_LENGTH As Long = 76
Private Const OSVEX_LENGTH As Long = 88
Public OSV_VERSION_LENGTH As Long 'our const to hold appropriate OSV length

Private Type OSVERSIONINFO
  OSVSize         As Long
  dwVerMajor      As Long
  dwVerMinor      As Long
  dwBuildNumber   As Long
  PlatformID      As Long
  szCSDVersion    As String * 128
End Type

'windows messages & notifications etc
Private Const WM_COMMAND = &H111
Public Const WM_NOTIFY As Long = &H4E&
Public Const WM_INITDIALOG As Long = &H110
Public Const CDN_FIRST As Long = -601
Public Const CDN_INITDONE As Long = (CDN_FIRST - &H0&)
Public Const MAX_PATH As Long = 260

'openfilename constants
Public Const OFN_ENABLEHOOK As Long = &H20
Public Const OFN_EXPLORER As Long = &H80000
Public Const OFN_ENABLESIZING As Long = &H800000
Public Const OFN_EX_NOPLACESBAR As Long = &H1

'constants for listview view state
'provided by Brad Martinez
Public Const SHVIEW_ICON As Long = &H7029
Public Const SHVIEW_LIST As Long = &H702B
Public Const SHVIEW_REPORT As Long = &H702C
Public Const SHVIEW_THUMBNAIL As Long = &H702D
Public Const SHVIEW_TILE As Long = &H702E

'this is the version 5+ definition of
'the OPENFILENAME structure containing
'three additional members providing
'additional options on Windows 2000
'or later. The SetOSVersion routine
'will assign either OSV_LENGTH (76)
'or OSVEX_LENGTH (88) to the OSV_VERSION_LENGTH
'variable declared above. This variable, rather
'than Len(OFN) is used to assign the required
'value to the OPENFILENAME structure's nStructSize
'member which tells the OS if extended features
'- primarily the Places Bar - are supported.
Public Type OPENFILENAME
  nStructSize       As Long
  hwndOwner         As Long
  hInstance         As Long
  sFilter           As String
  sCustomFilter     As String
  nMaxCustFilter    As Long
  nFilterIndex      As Long
  sFile             As String
  nMaxFile          As Long
  sFileTitle        As String
  nMaxTitle         As Long
  sInitialDir       As String
  sDialogTitle      As String
  flags             As Long
  nFileOffset       As Integer
  nFileExtension    As Integer
  sDefFileExt       As String
  nCustData         As Long
  fnHook            As Long
  sTemplateName     As String
  pvReserved        As Long
  dwReserved        As Long
  flagsEx           As Long
End Type

Public OFN As OPENFILENAME

'defined As Any to support either the
'OSVERSIONINFO or OSVERSIONINFOEX structure
Private Declare Function GetVersionEx Lib "kernel32" _
   Alias "GetVersionExA" _
  (lpVersionInformation As Any) As Long
 
Public Declare Function GetOpenFileName Lib "comdlg32.dll" _
   Alias "GetOpenFileNameA" _
  (pOpenfilename As OPENFILENAME) As Long

Private Declare Function FindWindowEx Lib "user32" _
   Alias "FindWindowExA" _
  (ByVal hWndParent As Long, _
   ByVal hWndChildAfter As Long, _
   ByVal lpClassName As String, _
   ByVal lpWindowName As String) As Long

Private Declare Function GetParent Lib "user32" _
  (ByVal hwnd As Long) As Long

Private Declare Function SendMessage Lib "user32" _
   Alias "SendMessageA" _
   (ByVal hwnd As Long, _
    ByVal wMsg As Long, _
    ByVal wParam As Long, _
    lParam As Any) As Long



Public Function FARPROC(pfn As Long) As Long
 
  'A dummy procedure that receives and returns
  'the return value of the AddressOf operator.
 
  'Obtain and set the address of the callback
  'This workaround is needed as you can't assign
  'AddressOf directly to a member of a user-
  'defined type, but you can assign it to another
  'long and use that (as returned here)

  FARPROC = pfn

End Function


Public Function IsWin2000Plus() As Boolean

  'returns True if running Windows 2000 or later
   Dim osv As OSVERSIONINFO

   osv.OSVSize = Len(osv)

   If GetVersionEx(osv) = 1 Then
   
      IsWin2000Plus = (osv.PlatformID = VER_PLATFORM_WIN32_NT) And _
                      (osv.dwVerMajor = 5 And osv.dwVerMinor >= 0)
 
   End If

End Function


Public Property Let OFN_SetInitialView(ByVal initview As Long)

   m_lvInitialView = initview
   
End Property


Public Function OFNHookProc(ByVal hwnd As Long, _
                            ByVal uMsg As Long, _
                            ByVal wParam As Long, _
                            ByVal lParam As Long) As Long

   Dim hWndParent As Long
   Dim hwndLv As Long
   Static bLvSetupDone As Boolean
   
   Select Case uMsg
      Case WM_INITDIALOG
        'Initdialog is set when the dialog
        'has been created and is ready to
        'be displayed, so set our flag
        'to prevent re-executing the code
        'in the wm_notify message. This is
        'required as the dialog receives a
        'number of WM_NOTIFY messages throughout
        'the life of the dialog. If this is not
        'done, and the user chooses a different
        'view, on the next WM_NOTIFY message
        'the listview would be reset to the
        'initial view, probably ticking off
        'the user. The variable is declared
        'static to preserve values between
        'calls; it will be automatically reset
        'on subsequent showing of the dialog.
         bLvSetupDone = False
         
        'other WM_INITDIALOG code here, such
        'as caption or button changing, or
        'centering the dialog.
     
      Case WM_NOTIFY
               
            If bLvSetupDone = False Then
               
             'hwnd is the handle to the dialog
             'hwndParent is the handle to the common control
             'hwndLv is the handle to the listview itself
               hWndParent = GetParent(hwnd)
               hwndLv = FindWindowEx(hWndParent, 0, "SHELLDLL_DefView", vbNullChar)
               
               If hwndLv > 0 Then
                  Call SendMessage(hwndLv, WM_COMMAND, ByVal m_lvInitialView, ByVal 0&)
                 
                 'since we found the lv hwnd, assume the
                 'command was received and set the flag
                 'to prevent recalling this routine
                  bLvSetupDone = True
               End If  'hwndLv

            End If  'bLvSetupDone

         Case Else
         
   End Select

End Function


Public Sub SetOSVersion()
 
   Select Case IsWin2000Plus()
      Case True
         OSV_VERSION_LENGTH = OSVEX_LENGTH '5.0+ structure size
     
      Case Else
         OSV_VERSION_LENGTH = OSV_LENGTH 'pre-5.0 structure size
   End Select

End Sub
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

I assume you are trying to change the view of the OpenFileRequester. If so, take a look here http://www.purebasic.fr/english/viewtop ... 878#133878

That code should help sort things out for you. ;)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Bonne_den_kule
Addict
Addict
Posts: 841
Joined: Mon Jun 07, 2004 7:10 pm

Post by Bonne_den_kule »

I can convert it for you if Sparkies link dosent help you.
roherter
User
User
Posts: 17
Joined: Fri Mar 10, 2006 9:49 am
Contact:

Post by roherter »

It´s rigth thanks for your link sparkie!

But I will use Thumbnail view in explorerlistgadget?

Bonne_den_kule:I would be Happy if you can change the Vb-Code in PB-Code!
Bonne_den_kule
Addict
Addict
Posts: 841
Joined: Mon Jun 07, 2004 7:10 pm

Post by Bonne_den_kule »

I have translated, but since I don't know what it do, you have to specify the global 'm_lvInitialView' variable. The code dosent do anything, because some parts of the code are missing.
Here is the code:

Code: Select all

Global m_lvInitialView = 0

 Procedure OFNHookProc(WindowID, Message, wParam, lParam)
  Result=#PB_ProcessPureBasicEvents 
  Static bLvSetupDone = #False
  Select Message
    Case #WM_INITDIALOG
      bLvSetupDone = #False
      
    Case #WM_NOTIFY
      If Not bLvSetupDone
        hWndParent = GetParent_(WindowID) 
        hwndLv = FindWindowEx_(hWndParent, 0, @"SHELLDLL_DefView", 0)
        If hwndLv > 0
          SendMessage_(hwndLv, #WM_COMMAND, m_lvInitialView, 0)
          bLvSetupDone = #True
        EndIf
      EndIf
      
  EndSelect
  ProcedureReturn result
EndProcedure

SetWindowCallback(@OFNHookProc())
Post Reply