Visual Basic, .NET, ASP, VBScript
 

   
   
     

Форум - Общий форум

Страница: 1 |

 

  Вопрос: путь к файлу Добавлено: 10.01.09 11:22  

Автор вопроса:  Cooller
! Как вызвать окно поиска файла не пользуясь компонентой CommonDialog? или как прицепить её к проекту чтоб прога работала на других компах без ошибок?

Ответить

  Ответы Всего ответов: 12  

Номер ответа: 1
Автор ответа:
 VβÐ



Вопросов: 15
Ответов: 194
 Web-сайт: www.homacosoft.com
 Профиль | | #1
Добавлено: 10.01.09 12:56
апи или таскай с собой ocx

Ответить

Номер ответа: 2
Автор ответа:
 Боцман



ICQ: 295725312 

Вопросов: 53
Ответов: 830
 Web-сайт: Rus-Skipper.narod.ru
 Профиль | | #2
Добавлено: 10.01.09 14:53
Когда то писал...
  1. '
  2. 'Создайте проект, и расположите на нем два Picture.
  3. 'Запускайте и пользуйтесь.
  4.  
  5. Option Explicit
  6. ' Для диалога открытия  и сохранения файла
  7.  Type OPENFILENAME
  8.          lStructSize As Long
  9.          hwndOwner As Long
  10.          hInstance As Long
  11.          lpstrFilter As String
  12.          lpstrCustomFilter As String
  13.          nMaxCustFilter As Long
  14.          nFilterIndex As Long
  15.          lpstrFile As String
  16.          nMaxFile As Long
  17.          lpstrFileTitle As String
  18.          nMaxFileTitle As Long
  19.          lpstrInitialDir As String
  20.          lpstrTitle As String
  21.          flags As Long
  22.          nFileOffset As Integer
  23.          nFileExtension As Integer
  24.          lpstrDefExt As String
  25.          lCustData As Long
  26.          lpfnHook As Long
  27.          lpTemplateName As String
  28.        End Type
  29.  
  30.  Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
  31.          "GetOpenFileNameA" (pOPENFILENAME As OPENFILENAME) As Long
  32.  Declare Function GetSaveFileName Lib "comdlg32" Alias _
  33.          "GetSaveFileNameA" (pOPENFILENAME As OPENFILENAME) As Long
  34. '**********************************************************************
  35. ' код ошибки
  36.  Declare Function CommDlgExtendedError Lib "comdlg32" () As Long
  37.  
  38.  Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
  39.  Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
  40.  Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
  41.  Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
  42.  Declare Function GlobalFree Lib "kernel32" (ByVal hMem As Long) As Long
  43.  
  44. код в форме;
  45.  
  46. Option Explicit
  47. '******CreatePopupMenu создает новое всплывающее меню. + Function mnuMenu *********
  48. Private Declare Function CreatePopupMenu Lib "user32" () As Long
  49. Private Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As Any) As Long
  50. Private Declare Function DestroyMenu Lib "user32" (ByVal hMenu As Long) As Long
  51. Private Declare Function TrackPopupMenu Lib "user32" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal X As Long, ByVal Y As Long, ByVal nReserved As Long, ByVal hwnd As Long, lprc As Any) As Long
  52. Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
  53. Private Type POINTAPI
  54.     X As Long
  55.     Y As Long
  56. End Type
  57. '**********************************************************************************
  58. 'Функция StretchBlt копирует часть изображения от одного Picture в
  59. 'другое. Эта функция также позволяет масштабировать (сжимать, растягивать,
  60. 'выворачивать наизнанку, задавая параметры с разными знаками)
  61. Private Declare Function StretchBlt Lib "gdi32" _
  62.            (ByVal hdc As Long, ByVal X As Long, _
  63.            ByVal Y As Long, ByVal nWidth As Long, _
  64.            ByVal nHeight As Long, ByVal hSrcDC As Long, _
  65.            ByVal xSrc As Long, ByVal ySrc As Long, _
  66.            ByVal hSrcWidth As Long, ByVal nSrcHeight As Long, _
  67.            ByVal dwRop As Long) As Long
  68. Const SRCCOPY = &HCC0020 'мы же используем -Точное копирование исходного изображения
  69. '***********************************************************************************
  70. '********' обработка ошибок CmdDialog
  71. Private Const FNERR_BUFFERTOOSMALL = &H3003
  72. Private Const GMEM_MOVEABLE = &H2
  73. Private Const GMEM_ZEROINIT = &H40
  74. '*************************************************
  75. Dim ris As Byte
  76. Public Function mnuMenu()
  77. Dim kordinata As POINTAPI
  78. Dim newMenu As Long
  79. Dim klicMenu As Long
  80.     newMenu = CreatePopupMenu() ' Создадим вначале пустое меню
  81.     AppendMenu newMenu, 0, 1, "О программе" ' Добавим новые пункты к меню
  82.     AppendMenu newMenu, &H800, 0, vbNull
  83.     AppendMenu newMenu, 0, 2, "Открыть фото"
  84.     AppendMenu newMenu, 0, 3, "Сохранить фото"
  85.     AppendMenu newMenu, 0, 4, "Закрыть программу"
  86.     GetCursorPos kordinata
  87.     klicMenu = TrackPopupMenu(newMenu, 2 Or &H100, kordinata.X, kordinata.Y, 0, hwnd, 0)
  88.     If klicMenu = 1 Then MsgBox "Автор Rus-Skipper   http://Rus-Skipper.narod.ru ", 0, ""
  89.       If klicMenu = 2 Then openFoto
  90.       If klicMenu = 3 Then saveFoto
  91.       If klicMenu = 4 Then Unload Form1
  92.     DestroyMenu newMenu ' Уничтожаем наше меню
  93. End Function
  94.  Public Function openFoto()
  95. Picture2.Picture = LoadPicture() 'очищаем от рисунка что бы не было наложения с предыдущим
  96.  Dim OpenFile As OPENFILENAME
  97.  Dim lRet As Long
  98.  Dim sFilter As String
  99.  Dim errcode As Long
  100.  OpenFile.lStructSize = Len(OpenFile)
  101.  OpenFile.hwndOwner = Form1.hwnd
  102.  OpenFile.hInstance = App.hInstance
  103. ' ' Здесь устанавливаем типы файлов которые будем искать
  104.  sFilter = "Графические файлы " & Chr(0) & "*.jpg;*.bmp;*.gif" & Chr(0) & Chr(0)
  105.  OpenFile.lpstrFilter = sFilter
  106.  OpenFile.nFilterIndex = 1
  107.  OpenFile.lpstrFile = String(257, 0)
  108.  OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
  109.  OpenFile.lpstrFileTitle = OpenFile.lpstrFile
  110.  OpenFile.nMaxFileTitle = OpenFile.nMaxFile
  111.  OpenFile.lpstrInitialDir = CurDir 'начинаем поиск с  папки открытой последней
  112.  OpenFile.lpstrTitle = "Ищем Графические файлы"
  113.  OpenFile.flags = 0
  114.  lRet = GetOpenFileName(OpenFile)
  115.  If lRet = 0 Then
  116.         errcode = CommDlgExtendedError() ' получаем код ошибки для GetOpenFileName
  117.  Else
  118.     Picture1.Picture = LoadPicture(Trim(OpenFile.lpstrFile))
  119.  End If
  120.   AutoSizeFoto 'изменяем размеры и показываем фото
  121.   Form1.Caption = "Нажмите левую кнопку мыши и рисуйте"
  122.  End Function
  123. '***сохранение фото в Picture2 с измененными размерами********
  124.   Public Function saveFoto()
  125.   Dim filebox As OPENFILENAME  ' структура для управления диалоговым окном
  126. Dim fname As String  ' путь и имя файла
  127. Dim lRet As Long  ' возвращаемое значение
  128. filebox.lStructSize = Len(filebox)  ' размер структуры
  129. filebox.hwndOwner = Form1.hwnd  ' дескриптор формы
  130. filebox.hInstance = App.hInstance
  131. filebox.lpstrTitle = "Сохранение файла"  ' текст для заголовка диалогового окна
  132. ' Здесь устанавливаем видимые типы файлов У нас (*.bmp)а могут бить и (*.txt)например
  133. filebox.lpstrFilter = "Графические файлы (*.bmp)" & Chr(0) & "*.BMP" & Chr(0)
  134. filebox.nFilterIndex = 1
  135. filebox.lpstrFile = String(257, 0)   ' создаем буфер для приема пути и имени файла
  136. filebox.nMaxFile = Len(filebox.lpstrFile) - 1  ' длина для этого буфера
  137. filebox.lpstrFileTitle = filebox.lpstrFile  ' создаем буфер для приема имени выбранного файла
  138. filebox.nMaxFileTitle = filebox.nMaxFile ' длина для этого буфера
  139. filebox.lpstrDefExt = ".bmp"  ' расширение файла по умолчанию
  140. filebox.lpstrInitialDir = CurDir '=Environ("USERPROFILE") 'откроет Documents and Settings\ваша учетная запись
  141. filebox.flags = 0
  142. lRet = GetSaveFileName(filebox)
  143. If lRet <> 0 Then  '<> 0 пользователь выбрал файл
  144. ' Извлекаем имя файла из буфера и передаем его fname=(полный путь + имя и расширение)
  145. fname = Left(filebox.lpstrFile, InStr(filebox.lpstrFile, vbNullChar) - 1)
  146. SavePicture Picture2.Image, fname 'сохраняем файл из Picture2 в выбранную директорию.
  147. End If
  148.   End Function
  149. '*******изменение размеров фото и подгонка размеров формы по размерам фото
  150.  Public Function AutoSizeFoto()
  151. Dim kF As String
  152. kF = Picture1.Width / Picture1.Height 'расчет коэффициента
  153. If kF > 1.33 Then ' это коэффициент для обычного стандарта фото
  154. Picture2.Width = 600 'здесь нужная максимальная ширина в проекте
  155. Picture2.Height = Picture2.Width / kF
  156. Else
  157. Picture2.Height = 400 'здесь нужная максимальная высота в проекте
  158. Picture2.Width = Picture2.Height * kF
  159. End If
  160. Picture2.Left = 0
  161. Picture2.Top = 0
  162. Dim py As Long 'узнаем величину заголовка формы,
  163. 'для этого Form1.ScaleHeight переводим в твипы
  164. py = Form1.Height - ScaleX(Form1.ScaleHeight, vbPixels, vbTwips)
  165. Dim px As Long ' то же для ширины, определяем размер бордюра
  166. px = Form1.Width - ScaleX(Form1.ScaleWidth, vbPixels, vbTwips)
  167. 'Задаем размеры формы по полученному рисунку
  168. Form1.Width = ScaleX(Picture2.Width, vbPixels, vbTwips) + px
  169. Form1.Height = ScaleY(Picture2.Height, vbPixels, vbTwips) + ScaleY(0, vbPixels, vbTwips) + py
  170. 'копируем изоражение из Picture1 в Picture2 или точнее рисуем, но сновыми размерами
  171. StretchBlt Picture2.hdc, 0, 0, Picture2.Width, Picture2.Height, Picture1.hdc, 0, 0, Picture1.Width, Picture1.Height, SRCCOPY
  172. Picture2.Refresh ' "освежаем" рисунок для точного вывода вида, при постоянном открытии новых фото
  173. End Function
  174. Private Sub Form_Load()
  175. Form1.Caption = "Нажмите правую кнопку мыши"
  176. Form1.ScaleMode = vbPixels
  177. Picture1.ScaleMode = 3
  178. Picture2.ScaleMode = 3
  179. Picture1.AutoSize = True
  180. Picture1.Visible = False
  181. Picture1.AutoRedraw = True
  182. Picture2.AutoRedraw = True
  183. ris = 2
  184. End Sub
  185. Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  186. If Button And vbRightButton Then mnuMenu 'проверка, нажата ли правая клавиша мыши
  187. End Sub
  188. Private Sub Picture2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  189. If Button And vbRightButton Then Exit Sub 'проверка, нажата ли правая клавиша мыши
  190. Picture2.ForeColor = vbRed
  191. Picture2.PSet (X, Y) 'рисуем точку
  192. ris = 1
  193. End Sub
  194. Private Sub Picture2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  195. If ris = 2 Then Exit Sub
  196. Picture2.DrawWidth = 10
  197. Picture2.Line -(X, Y) 'рисуем линию
  198. End Sub
  199. Private Sub Picture2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  200. If Button And vbRightButton Then mnuMenu 'если правая открываем меню'
  201. ris = 2
  202. End Sub

Ответить

Номер ответа: 3
Автор ответа:
 Arseny



ICQ: 298826769 

Вопросов: 53
Ответов: 1732
 Профиль | | #3 Добавлено: 10.01.09 16:48
Когда то скачал... :) создай файл, например, clsDialog.cls...
  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "clsDialog"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. 'General Declarations
  15. Private Type BROWSEINFO  ' Folder Dialog
  16.    hOwner           As Long
  17.    pidlRoot         As Long
  18.    pszDisplayName   As String
  19.    lpszTitle        As String
  20.    ulFlags          As Long
  21.    lpfn             As Long
  22.    lParam           As Long
  23.    iImage           As Long
  24. End Type
  25. Private Type OPENFILENAME 'Open & Save Dialog
  26.     lStructSize As Long
  27.     hwndOwner As Long
  28.     hInstance As Long
  29.     lpstrFilter As String
  30.     lpstrCustomFilter As String
  31.     nMaxCustFilter As Long
  32.     nFilterIndex As Long
  33.     lpstrFile As String
  34.     nMaxFile As Long
  35.     lpstrFileTitle As String
  36.     nMaxFileTitle As Long
  37.     lpstrInitialDir As String
  38.     lpstrTitle As String
  39.     flags As Long
  40.     nFileOffset As Integer
  41.     nFileExtension As Integer
  42.     lpstrDefExt As String
  43.     lCustData As Long
  44.     lpfnHook As Long
  45.     lpTemplateName As String
  46. End Type
  47.  
  48. Private Type CHOOSECOLOR 'Color Dialog
  49.     lStructSize As Long
  50.     hwndOwner As Long
  51.     hInstance As Long
  52.     RGBResult As Long
  53.     lpCustColors As String
  54.     flags As Long
  55.     lCustData As Long
  56.     lpfnHook As Long
  57.     lpTemplateName As String
  58. End Type
  59.  
  60. Const LF_FACESIZE = 32 'Font Dialog
  61. Private Type LOGFONT 'Font Dialog
  62.     lfHeight As Long
  63.     lfWidth As Long
  64.     lfEscapement As Long
  65.     lfOrientation As Long
  66.     lfWeight As Long
  67.     lfItalic As Byte
  68.     lfUnderline As Byte
  69.     lfStrikeOut As Byte
  70.     lfCharSet As Byte
  71.     lfOutPrecision As Byte
  72.     lfClipPrecision As Byte
  73.     lfQuality As Byte
  74.     lfPitchAndFamily As Byte
  75.     lfFaceName(LF_FACESIZE) As Byte
  76. End Type
  77.  
  78. Private Type ChooseFont 'Font Dialog
  79.     lStructSize As Long
  80.     hwndOwner As Long
  81.     hDC As Long
  82.     lpLogFont As Long
  83.     iPointSize As Long
  84.     flags As Long
  85.     rgbColors As Long
  86.     lCustData As Long
  87.     lpfnHook As Long
  88.     lpTemplateName As String
  89.     hInstance As Long
  90.     lpszStyle As String
  91.     nFontType As Integer
  92.     MISSING_ALIGNMENT As Integer
  93.     nSizeMin As Long
  94.     nSizeMax As Long
  95. End Type
  96. ' extra font constant
  97. Const CF_INITTOLOGFONTSTRUCT = &H40&
  98. Const SCREEN_FONTTYPE = &H2000
  99. Const BOLD_FONTTYPE = &H100
  100. Const FW_BOLD = 700
  101.  
  102. Private Type PrintDlg 'PrintDialog
  103.     lStructSize As Long
  104.     hwndOwner As Long
  105.     hDevMode As Long
  106.     hDevNames As Long
  107.     hDC As Long
  108.     flags As Long
  109.     nFromPage As Integer
  110.     nToPage As Integer
  111.     nMinPage As Integer
  112.     nMaxPage As Integer
  113.     nCopies As Integer
  114.     hInstance As Long
  115.     lCustData As Long
  116.     lpfnPrintHook As Long
  117.     lpfnSetupHook As Long
  118.     lpPrintTemplateName As String
  119.     lpSetupTemplateName As String
  120.     hPrintTemplate As Long
  121.     hSetupTemplate As Long
  122. End Type
  123.  
  124. Const CCHDEVICENAME = 32 'PrintDialog
  125. Const CCHFORMNAME = 32 'PrintDialog
  126. Private Type DEVMODE 'PrintDialog
  127.     dmDeviceName As String * CCHDEVICENAME
  128.     dmSpecVersion As Integer
  129.     dmDriverVersion As Integer
  130.     dmSize As Integer
  131.     dmDriverExtra As Integer
  132.     dmFields As Long
  133.     dmOrientation As Integer
  134.     dmPaperSize As Integer
  135.     dmPaperLength As Integer
  136.     dmPaperWidth As Integer
  137.     dmScale As Integer
  138.     dmCopies As Integer
  139.     dmDefaultSource As Integer
  140.     dmPrintQuality As Integer
  141.     dmColor As Integer
  142.     dmDuplex As Integer
  143.     dmYResolution As Integer
  144.     dmTTOption As Integer
  145.     dmCollate As Integer
  146.     dmFormName As String * CCHFORMNAME
  147.     dmUnusedPadding As Integer
  148.     dmBitsPerPel As Integer
  149.     dmPelsWidth As Long
  150.     dmPelsHeight As Long
  151.     dmDisplayFlags As Long
  152.     dmDisplayFrequency As Long
  153. End Type
  154.  
  155. Private Type DEVNAMES 'PrintDialog
  156.     wDriverOffset As Integer
  157.     wDeviceOffset As Integer
  158.     wOutputOffset As Integer
  159.     wDefault As Integer
  160.     extra As String * 100
  161. End Type
  162. 'extra printer constants - for Printer Dialog
  163. Const DM_DUPLEX = &H1000&
  164. Const DM_ORIENTATION = &H1&
  165. ' memory management constants - for Printer Dialog
  166. Const GMEM_MOVEABLE = &H2
  167. Const GMEM_ZEROINIT = &H40
  168.  
  169.  
  170. ' ------------- Dialog calling functions
  171. ' -------------- Standard
  172. Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
  173. Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long
  174. Private Declare Function ChooseColorAPI Lib "comdlg32.dll" Alias "ChooseColorA" (pChoosecolor As CHOOSECOLOR) As Long
  175. Private Declare Function ChooseFont Lib "comdlg32.dll" Alias "ChooseFontA" (pChoosefont As ChooseFont) As Long
  176. Private Declare Function PrintDlg Lib "comdlg32.dll" Alias "PrintDlgA" (pPrintdlg As PrintDlg) As Long
  177. Private Declare Function WinHelp Lib "user32" Alias "WinHelpA" (ByVal hOwner As Long, ByVal lpHelpFile As String, ByVal wCommand As Long, ByVal dwData As Long) As Long
  178. ' ------------- Extended
  179. Private Declare Function SHShutDownDialog Lib "shell32" Alias "#60" (ByVal YourGuess As Long) As Long
  180. Private Declare Function SHRestartSystem Lib "shell32" Alias "#59" (ByVal hOwner As Long, ByVal sPrompt As String, ByVal uFlags As Long) As Long
  181. Private Declare Function SHRunDialog Lib "shell32" Alias "#61" (ByVal hOwner As Long, ByVal hIcon As Long, ByVal sDir As Long, ByVal szTitle As String, ByVal szPrompt As String, ByVal uFlags As Long) As Long
  182. Private Declare Function SHFormatDrive Lib "shell32" (ByVal hwndOwner As Long, ByVal iDrive As Long, ByVal iCapacity As Long, ByVal iFormatType As Long) As Long
  183. Private Declare Function SHBrowseForFolder Lib "shell32" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
  184. Private Declare Function SHChangeIconDialog Lib "shell32" Alias "#62" (ByVal hOwner As Long, ByVal szFilename As String, ByVal Reserved As Long, lpIconIndex As Long) As Long
  185. 'Private Declare Function SHFindFiles Lib "Shell32" Alias "#90" (ByVal pidlRoot As Long, ByVal pidlSavedSearchas As Long) As Boolean
  186. Private Declare Function SHObjectProperties Lib "shell32" Alias "#178" (ByVal hOwner As Long, ByVal uFlags As Long, ByVal sName As String, ByVal sParam As String) As Long
  187. 'Private Declare Function GetFileNameFromBrowse Lib "shell32" Alias "#63" (ByVal hWndOwner As Long, ByVal sFile As String, ByVal nMaxFile As Long, ByVal sInitDir As String, ByVal sDefExt As String, ByVal sFilter As String, ByVal sTitle As String) As Boolean
  188. Private Declare Function SHAbout Lib "shell32" Alias "ShellAboutA" (ByVal hOwner As Long, ByVal sAppName As String, ByVal sPrompt As String, ByVal hIcon As Long) As Long
  189. ' -------------- Extra functions for FolderDialog
  190. Private Declare Function SHSimpleIDListFromPath Lib "shell32" Alias "#162" (ByVal szPath As String) As Long
  191. Private Declare Function SHGetPathFromIDList Lib "shell32" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
  192. Private Declare Function SHFree Lib "shell32" Alias "#196" ()
  193. Private Declare Function ILFree Lib "shell32" Alias "#195" (ByVal pidlFree As Long)
  194. Private Declare Sub CoTaskMemFree Lib "ole32" (ByVal pv As Long)
  195. ' -------------- Extra functions for IconDialog
  196. Private Declare Function DestroyIcon Lib "user32" (ByVal hIcon As Long) As Long
  197. Private Declare Function CopyIcon Lib "user32" (ByVal hIcon As Long) As Long
  198. Private Declare Function ExtractIconEx Lib "shell32" Alias "ExtractIconExA" (ByVal lpszFile As String, ByVal nIconIndex As Long, phiconLarge As Long, phiconSmall As Long, ByVal nIcons As Long) As Long
  199.  
  200. ' GDI functions
  201. ' For Font Dialog
  202. Private Declare Function CreateFontIndirect Lib "gdi32" Alias "CreateFontIndirectA" (lpLogFont As LOGFONT) As Long
  203. Private Declare Function SelectObject Lib "gdi32" (ByVal hDC As Long, ByVal hObject As Long) As Long
  204. Private Declare Function GetTextFace Lib "gdi32" Alias "GetTextFaceA" (ByVal hDC As Long, ByVal nCount As Long, ByVal lpFacename As String) As Long
  205. ' For Font and Printer Dialog
  206. Private Declare Function GetDC Lib "user32" (ByVal hOwner As Long) As Long
  207.  
  208. ' user32 functions
  209. 'Private Declare Function GetActiveWindow Lib "user32" () As Long
  210.  
  211. ' kernel32 functions
  212. ' For Font Dialog
  213. Private Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (p1 As Any, p2 As Any) As Long
  214. ' For Printer Dialog
  215. Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
  216. Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
  217. Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
  218. Private Declare Function GlobalFree Lib "kernel32" (ByVal hMem As Long) As Long
  219. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
  220.  
  221.  
  222. ' common dialog action types
  223. 'Const ShowOpen = 1
  224. 'Const ShowSave = 2
  225. 'Const ShowColor = 3
  226. 'Const ShowFont = 4
  227. 'Const ShowPrinter = 5
  228. 'Const ShowHelp = 6
  229.  
  230. ' --------------- Enum Flags
  231. Public Enum CdlgExt_Flags
  232.  ' Open & Save Dialog
  233.  cdlOFNAllowMultiselect = &H200
  234.  cdlOFNCreatePrompt = &H2000
  235.  cdlOFNExplorer = &H80000
  236.  cdlOFNExtensionDifferent = &H400
  237.  cdlOFNFileMustExist = &H1000
  238.  cdlOFNHelpButton = &H10
  239.  cdlOFNHideReadOnly = &H4
  240.  cdlOFNLongNames = &H200000
  241.  cdlOFNNoChangeDir = &H8
  242.  cdlOFNNoDereferenceLinks = &H100000
  243.  cdlOFNNoLongNames = &H40000
  244.  cdlOFNNoReadOnlyReturn = &H8000
  245.  cdlOFNNoValidate = &H100
  246.  cdlOFNOverwritePrompt = &H2
  247.  cdlOFNPathMustExist = &H800
  248.  cdlOFNReadOnly = &H1
  249.  cdlOFNShareAware = &H4000
  250.  'Color Dialog
  251.  cdlCCFullOpen = &H2
  252.  cdlCCHelpButton = &H8
  253.  cdlCCPreventFullOpen = &H4
  254.  cdlCCRGBInit = &H1
  255. ' Printer Dialog
  256.  cdlPDAllPages = &H0
  257.  cdlPDCollate = &H10
  258.  cdlPDDisablePrintToFile = &H80000
  259.  cdlPDHelpButton = &H800
  260.  cdlPDHidePrintToFile = &H100000
  261.  cdlPDNoPageNums = &H8
  262.  cdlPDNoSelection = &H4
  263.  cdlPDNoWarning = &H80
  264.  cdlPDPageNums = &H2
  265.  cdlPDPrintSetup = &H40
  266.  cdlPDPrintToFile = &H20
  267.  cdlPDReturnDC = &H100
  268.  cdlPDReturnDefault = &H400
  269.  cdlPDReturnIC = &H200
  270.  cdlPDSelection = &H1
  271.  cdlPDUseDevModeCopies = &H40000
  272. ' Font Dialog
  273.  cdlCFANSIOnly = &H400
  274.  cdlCFApply = &H200
  275.  cdlCFBoth = &H3
  276.  cdlCFEffects = &H100
  277.  cdlCFFixedPitchOnly = &H4000
  278.  cdlCFForceFontExist = &H10000
  279.  cdlCFHelpButton = &H4
  280.  cdlCFLimitSize = &H2000
  281.  cdlCFNoFaceSel = &H80000
  282.  cdlCFNoSimulations = &H1000
  283.  cdlCFNoSizeSel = &H200000
  284.  cdlCFNoStyleSel = &H100000
  285.  cdlCFNoVectorFonts = &H800
  286.  cdlCFPrinterFonts = &H2
  287.  cdlCFScalableOnly = &H20000
  288.  cdlCFScreenFonts = &H1
  289.  cdlCFTTOnly = &H40000
  290.  cdlCFWYSIWYG = &H8000
  291. ' Other Dialog
  292.  'Restart Dialog
  293.  Restart_Logoff = &H0
  294.  Restart_ShutDown = &H1
  295.  Restart_Reboot = &H2
  296.  Restart_Force = &H4
  297.  ' Run Dialog
  298.  Run_NoBrowse = &H10
  299.  Run_NoDefault = &H20
  300.  Run_CalcDir = &H40
  301.  Run_NoLable = &H80
  302.  ' Properties Dialog
  303.  ObjProp_Printer = &H100
  304.  ObjProp_File = &H200
  305.  ObjProp_System = &H400
  306.  ObjProp_RecBin = &H700
  307.  ObjProp_Screen = &H800
  308.  ' Browse for Folder Dialog
  309.  Folder_COMPUTER = &H1000
  310.  Folder_PRINTER = &H2000
  311.  Folder_INCLUDEFILES = &H4001
  312. End Enum
  313. 'Enum Help Commands
  314. Public Enum CdlgExt_HelpCommand
  315.  HelpCommandHelp = &H102&
  316.  HelpContents = &H3&
  317.  HelpContext = &H1
  318.  HelpContextPOPUP = &H8&
  319.  HelpForceFile = &H9&
  320.  HelpHelpOnHelp = &H4
  321.  HelpIndex = &H3
  322.  HelpKeyHelp = &H101
  323.  HelpPartialKey = &H105&
  324.  HelpQuit = &H2
  325.  HelpSetContents = &H5&
  326.  HelpSetIndex = &H5
  327.  HelpMultiKey = &H201&
  328.  HelpSetWinPos = &H203&
  329. End Enum
  330.  
  331. Private RetValue As Long 'General
  332. Const MAX_PATH = 260 'General
  333. Private OFN As OPENFILENAME ' Open & Save Dialog
  334.  
  335. 'Внутренние переменные для свойств:
  336. Private mFileName As String
  337. Private mFileTitle As String
  338. Private mhOwner As Long
  339. Private mDialogTitle As String
  340. Private mFilter As String
  341. Private mInitDir As String
  342. Private mDefaultExt As String
  343. Private mFilterIndex As Long
  344. Private mHelpFile As String
  345. Private mHelpCommand As CdlgExt_HelpCommand
  346. Private mHelpKey As Long
  347. Private mRGBResult As Long
  348. Private mItalic As Boolean
  349. Private mUnderline As Boolean
  350. Private mStrikethru As Boolean
  351. Private mFontName As String
  352. Private mFontSize As Long
  353. Private mBold As Boolean
  354. Private mDialogPrompt As String
  355. Private mFlags As CdlgExt_Flags
  356. Private mCancelError As Boolean
  357. Private mhIcon As Long
  358. Private mAppName As String
  359.  
  360. ' Let/Get Properties: General
  361. Public Property Let CancelError(ByVal vData As Boolean)
  362.    mCancelError = vData
  363. End Property
  364.  
  365. Public Property Get CancelError() As Boolean
  366.   CancelError = mCancelError
  367. End Property
  368.  
  369. Public Property Get hOwner() As Long
  370.     hOwner = mhOwner
  371. End Property
  372.  
  373. Public Property Let hOwner(ByVal New_hOwner As Long)
  374.     mhOwner = New_hOwner
  375. End Property
  376.  
  377. Public Property Get flags() As CdlgExt_Flags
  378.     flags = mFlags
  379. End Property
  380.  
  381. Public Property Let flags(ByVal New_Flags As CdlgExt_Flags)
  382.     mFlags = New_Flags
  383. End Property
  384.  
  385. Public Property Get DialogTitle() As String
  386.    DialogTitle = mDialogTitle
  387. End Property
  388.  
  389. Public Property Let DialogTitle(sTitle As String)
  390.    mDialogTitle = sTitle
  391. End Property
  392.  
  393. Public Property Get DialogPrompt() As String
  394.     DialogPrompt = mDialogPrompt
  395. End Property
  396.  
  397. Public Property Let DialogPrompt(ByVal New_Prompt As String)
  398.     mDialogPrompt = New_Prompt
  399. End Property
  400.  
  401. Public Property Get AppName() As String
  402.     AppName = mAppName
  403. End Property
  404.  
  405. Public Property Let AppName(ByVal New_AppName As String)
  406.     mAppName = New_AppName
  407. End Property
  408.  
  409. Public Property Let hIcon(ByVal vData As Long)
  410.     mhIcon = vData
  411. End Property
  412.  
  413. Public Property Get hIcon() As Long
  414.    hIcon = mhIcon
  415. End Property
  416.  
  417. ' Font Properties
  418. Public Property Get Bold() As Boolean
  419.   Bold = mBold
  420. End Property
  421.  
  422. Public Property Let Bold(bBold As Boolean)
  423.    mBold = bBold
  424. End Property
  425.  
  426. Public Property Get FontName() As String
  427.    FontName = mFontName
  428. End Property
  429.  
  430. Public Property Let FontName(sName As String)
  431.    mFontName = sName
  432. End Property
  433.  
  434. Public Property Get FontSize() As Long
  435.   FontSize = mFontSize
  436. End Property
  437.  
  438. Public Property Let FontSize(lSize As Long)
  439.    mFontSize = lSize
  440. End Property
  441.  
  442. Public Property Get Italic() As Boolean
  443.   Italic = mItalic
  444. End Property
  445.  
  446. Public Property Let Italic(BItalic As Boolean)
  447.    mItalic = BItalic
  448. End Property
  449.  
  450. Public Property Get StrikeThru() As Boolean
  451.    StrikeThru = mStrikethru
  452. End Property
  453.  
  454. Public Property Let StrikeThru(bStrikethru As Boolean)
  455.    mStrikethru = bStrikethru
  456. End Property
  457.  
  458. Public Property Get Underline() As Boolean
  459.    Underline = mUnderline
  460. End Property
  461.  
  462. Public Property Let Underline(bUnderline As Boolean)
  463.    mUnderline = bUnderline
  464. End Property
  465.  
  466. ' Open , Save, Folder, Icon
  467.  
  468. Public Property Get DefaultExt() As String
  469.    DefaultExt = mDefaultExt
  470. End Property
  471.  
  472. Public Property Let DefaultExt(sDefExt As String)
  473.    mDefaultExt = DefaultExt
  474. End Property
  475.  
  476. Public Property Get FileName() As String
  477.    FileName = mFileName
  478. End Property
  479.  
  480. Public Property Let FileName(sFileName As String)
  481.    mFileName = sFileName
  482. End Property
  483.  
  484. Public Property Get FileTitle() As String
  485.    FileTitle = mFileTitle
  486. End Property
  487.  
  488. Public Property Let FileTitle(sTitle As String)
  489.    mFileTitle = sTitle
  490. End Property
  491.  
  492. Public Property Get Filter() As String
  493.    Filter = mFilter
  494. End Property
  495.  
  496. Public Property Let Filter(sFilter As String)
  497.    mFilter = sFilter
  498. End Property
  499.  
  500. Public Property Get FilterIndex() As Long
  501.    FilterIndex = mFilterIndex
  502. End Property
  503.  
  504. Public Property Let FilterIndex(lIndex As Long)
  505.     mFilterIndex = lIndex
  506. End Property
  507.  
  508. Public Property Get InitDir() As String
  509.    InitDir = mInitDir
  510. End Property
  511.  
  512. Public Property Let InitDir(sDir As String)
  513.     mInitDir = sDir
  514. End Property
  515.  
  516. ' Help Properties
  517. Public Property Get HelpCommand() As CdlgExt_HelpCommand
  518.    HelpCommand = mHelpCommand
  519. End Property
  520.  
  521. Public Property Let HelpCommand(lCommand As CdlgExt_HelpCommand)
  522.    mHelpCommand = lCommand
  523. End Property
  524.  
  525. Public Property Get HelpFile() As String
  526.    HelpFile = mHelpFile
  527. End Property
  528.  
  529. Public Property Let HelpFile(sFile As String)
  530.    mHelpFile = sFile
  531. End Property
  532.  
  533. Public Property Get HelpKey() As Long
  534.    HelpKey = mHelpKey
  535. End Property
  536.  
  537. Public Property Let HelpKey(sKey As Long)
  538.    mHelpKey = sKey
  539. End Property
  540.  
  541. 'Color Dialog
  542. Public Property Get RGBResult() As Long
  543.    RGBResult = mRGBResult
  544. End Property
  545.  
  546. Public Property Let RGBResult(lValue As Long)
  547.    mRGBResult = lValue
  548. End Property
  549. ' ShutDown Dialog
  550. Public Function ShowShutDown()
  551.    SHShutDownDialog mhOwner
  552. End Function
  553. ' Restart Dialog
  554. Public Function ShowRestart()
  555.   Dim uFlag As Long
  556.   uFlag = mFlags And (&H0 Or &H1 Or &H2 Or &H4)
  557.   SHRestartSystem mhOwner, mDialogPrompt, uFlag
  558. End Function
  559. ' Run Dialog
  560. Public Function ShowRun(Optional ByVal hIcon As Long)
  561.   Dim uFlag As Long
  562.   uFlag = mFlags And (&H10 Or &H20 Or &H40 Or &H80)
  563.   uFlag = uFlag / 16
  564.   SHRunDialog mhOwner, mhIcon, 0, mDialogTitle, mDialogPrompt, uFlag
  565. End Function
  566. ' FormatFloppy  Dialog
  567. Public Function ShowFormat(Optional ByVal iDrive As Long, Optional ByVal iCapacity As Long, Optional ByVal iFormatType As Long) As Long
  568.   ShowFormat = SHFormatDrive(mhOwner, iDrive, iCapacity, iFormatType)
  569. End Function
  570.  
  571. ' SelectIcon Dialog
  572. Public Function ShowIcon(Optional ByVal LargeIcon As Boolean)
  573.    Dim nIconIdx As Long, OldFileName As String
  574.    Dim hSmallIcon As Long, hLargeIcon As Long, NewIcon As Long
  575.    If Right(mFileName, 1) = "\" Then Exit Function
  576.    OldFileName = mFileName
  577.    mFileName = mFileName & String$(MAX_PATH - Len(mFileName), 0) 'FileName  must be maximum lenth
  578.    If SHChangeIconDialog(0, mFileName, 0, nIconIdx) Then
  579.       If ExtractIconEx(mFileName, nIconIdx, hLargeIcon, hSmallIcon, 1) > 0 Then
  580.          NewIcon = IIf(LargeIcon, hLargeIcon, hSmallIcon)
  581.          mhIcon = CopyIcon(NewIcon)
  582.          DestroyIcon hSmallIcon
  583.          DestroyIcon hLargeIcon
  584.       End If
  585.    End If
  586.    mFileName = OldFileName
  587. End Function
  588. 'SelectFolder  Dialog
  589. Public Function ShowFolder(Optional ByVal TopFolder As String) As String
  590.   Dim bi As BROWSEINFO
  591.   Dim pidl As Long, path As String, pos As Integer, uFlag As Long
  592.   TopFolder = TopFolder & Chr$(0)
  593.   bi.hOwner = mhOwner
  594.   bi.pidlRoot = SHSimpleIDListFromPath(TopFolder) 'Translate String (Path) to pointer (pidl)
  595.   bi.lpszTitle = mDialogPrompt
  596.   uFlag = mFlags And (&H1000 Or &H2000 Or &H4001)
  597.   If uFlag < Folder_COMPUTER Then
  598.      bi.ulFlags = &H1
  599.   Else
  600.      bi.ulFlags = uFlag
  601.   End If
  602.   pidl = SHBrowseForFolder(bi) ' Get pidl for selected folder
  603.   path = String$(MAX_PATH, 0)
  604.   ' translate pidl to Path
  605.   If SHGetPathFromIDList(ByVal pidl, ByVal path) Then
  606.      pos = InStr(path, Chr$(0))
  607.      InitDir = Left(path, pos - 1)
  608.   End If
  609.   Call CoTaskMemFree(pidl) ' Free Memory
  610. End Function
  611.  
  612. ' ObjectProp  Dialog
  613. Public Function ShowObjectProp(Optional ByVal sObjectName As String, Optional ByVal sTab As String)
  614.   Dim uFlag As Long, sObj As String
  615.   Dim pidl As Long, sPath As String
  616.   uFlag = mFlags And (&H100 Or &H200 Or &H400 Or &H700 Or &H800)
  617.   uFlag = uFlag / 256
  618.   Select Case uFlag
  619.          Case 1, 2
  620.               sObj = sObjectName 'File or Printer selected
  621.          Case 7
  622.               uFlag = 2
  623.               sObj = "c:\recycled"
  624.          Case 8
  625.               uFlag = 0 'Screen Selected
  626.               Call Shell("rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,0", vbNormalFocus)
  627.          Case Else ' In all other cases show system properties
  628.               uFlag = 2
  629.               sObj = ""
  630.   End Select
  631.   If uFlag > 0 Then SHObjectProperties mhOwner, uFlag, sObj, sTab
  632. End Function
  633.  
  634. 'About Dialog
  635. Public Function ShowAbout()
  636.     If mAppName = "" Then mAppName = Chr$(0)
  637.     SHAbout mhOwner, mAppName, mDialogPrompt, mhIcon
  638. End Function
  639. ' Standard  Dialogs
  640. Public Sub ShowOpen()
  641.   Dim iDelim As Integer
  642.   InitOFN
  643.   RetValue = GetOpenFileName(OFN)
  644.   If RetValue > 0 Then
  645.      iDelim = InStr(OFN.lpstrFileTitle, vbNullChar)
  646.      If iDelim Then mFileTitle = Left$(OFN.lpstrFileTitle, iDelim - 1)
  647.      iDelim = InStr(OFN.lpstrFile, vbNullChar)
  648.      If iDelim Then mFileName = Left$(OFN.lpstrFile, iDelim - 1)
  649.   Else
  650.      If mCancelError Then Err.Raise 0
  651.   End If
  652. End Sub
  653. Public Sub ShowSave()
  654.   Dim iDelim As Integer
  655.   InitOFN
  656.   RetValue = GetSaveFileName(OFN)
  657.   If RetValue > 0 Then
  658.      iDelim = InStr(OFN.lpstrFileTitle, vbNullChar)
  659.      If iDelim Then mFileTitle = Left$(OFN.lpstrFileTitle, iDelim - 1)
  660.      iDelim = InStr(OFN.lpstrFile, vbNullChar)
  661.      If iDelim Then mFileName = Left$(OFN.lpstrFile, iDelim - 1)
  662.   Else
  663.      If mCancelError Then Err.Raise 0
  664.   End If
  665. End Sub
  666. Private Sub InitOFN()
  667.   Dim sTemp As String, i As Integer
  668.   Dim uFlag As Long
  669.   uFlag = mFlags And (&H1 Or &H2 Or &H4 Or &H8 Or &H10 Or &H100 Or &H200 Or &H400 Or &H800 Or &H1000 Or &H2000 Or &H4000 Or &H8000 Or &H40000 Or &H80000 Or &H100000 Or &H200000)
  670.   With OFN
  671.        .lStructSize = Len(OFN)
  672.        .hwndOwner = mhOwner
  673.        .flags = uFlag
  674.        .lpstrDefExt = mDefaultExt
  675.        sTemp = mInitDir
  676.        If sTemp = "" Then sTemp = App.path
  677.        .lpstrInitialDir = sTemp
  678.        sTemp = mFileName
  679.        .lpstrFile = sTemp & String$(255 - Len(sTemp), 0)
  680.        .nMaxFile = 255
  681.        .lpstrFileTitle = String$(255, 0)
  682.        .nMaxFileTitle = 255
  683.         sTemp = mFilter
  684.         For i = 1 To Len(sTemp)
  685.             If Mid(sTemp, i, 1) = "|" Then
  686.                Mid(sTemp, i, 1) = vbNullChar
  687.             End If
  688.         Next
  689.         sTemp = sTemp & String$(2, 0)
  690.         .lpstrFilter = sTemp
  691.         .nFilterIndex = mFilterIndex
  692.         .lpstrTitle = mDialogTitle
  693.         .hInstance = App.hInstance
  694.  End With
  695. End Sub
  696. Public Sub ShowHelp()
  697.  mHelpKey = &H101
  698.  RetValue = WinHelp(mhOwner, mHelpFile, mHelpCommand, mHelpKey)
  699. End Sub
  700. Public Sub ShowColor()
  701.   Dim CC As CHOOSECOLOR
  702.   Dim CustomColors() As Byte
  703.   Dim uFlag As Long
  704.   ReDim CustomColors(0 To 16 * 4 - 1) As Byte
  705.   For i = LBound(CustomColors) To UBound(CustomColors)
  706.      CustomColors(i) = 255 ' white
  707.   Next i
  708.   uFlag = mFlags And (&H1 Or &H2 Or &H4 Or &H8)
  709.   With CC
  710.        .lStructSize = Len(CC)
  711.        .hwndOwner = mhOwner
  712.        .hInstance = App.hInstance
  713.        .lpCustColors = StrConv(CustomColors, vbUnicode)
  714.        .flags = uFlag
  715.        .RGBResult = mRGBResult
  716.        RetValue = ChooseColorAPI(CC)
  717.        If RetValue = 0 Then
  718.           If mCancelError Then Err.Raise (RetValue)
  719.        Else
  720.           CustomColors = StrConv(.lpCustColors, vbFromUnicode)
  721.           mRGBResult = .RGBResult
  722.        End If
  723.   End With
  724. End Sub
  725. Public Sub ShowFont()
  726.   Dim CF As ChooseFont
  727.   Dim LF As LOGFONT
  728.   Dim TempByteArray() As Byte
  729.   Dim ByteArrayLimit As Long
  730.   Dim OldhDC As Long
  731.   Dim FontToUse As Long
  732.   Dim tbuf As String * 80
  733.   Dim x As Long
  734.   Dim uFlag As Long
  735.   uFlag = mFlags And (&H1 Or &H2 Or &H3 Or &H4 Or &H100 Or &H200 Or &H400 Or &H800 Or &H1000 Or &H2000 Or &H4000 Or &H8000 Or &H10000 Or &H20000 Or &H40000 Or &H80000 Or &H100000 Or &H200000)
  736.   TempByteArray = StrConv(mFontName & vbNullChar, vbFromUnicode)
  737.   ByteArrayLimit = UBound(TempByteArray)
  738.   With LF
  739.      For x = 0 To ByteArrayLimit
  740.         .lfFaceName(x) = TempByteArray(x)
  741.      Next
  742.     .lfHeight = mFontSize * 1.3
  743.     .lfItalic = mItalic * -1
  744.     .lfUnderline = mUnderline * -1
  745.     .lfStrikeOut = mStrikethru * -1
  746.     If mBold Then .lfWeight = FW_BOLD
  747.   End With
  748.   With CF
  749.       .lStructSize = Len(CF)
  750.       .hwndOwner = mhOwner
  751.       .hDC = GetDC(mhOwner)
  752.       .lpLogFont = lstrcpy(LF, LF)
  753.       If Not uFlag Then
  754.          .flags = cdlCFScreenFonts
  755.       Else
  756.          .flags = uFlag Or cdlCFWYSIWYG
  757.       End If
  758.      .flags = .flags Or cdlCFEffects Or CF_INITTOLOGFONTSTRUCT
  759.      .rgbColors = mRGBResult
  760.      .lCustData = 0
  761.      .lpfnHook = 0
  762.      .lpTemplateName = 0
  763.      .hInstance = 0
  764.      .lpszStyle = 0
  765.      .nFontType = SCREEN_FONTTYPE
  766.      .nSizeMin = 0
  767.      .nSizeMax = 0
  768.      .iPointSize = mFontSize * 10
  769.     End With
  770.     RetValue = ChooseFont(CF)
  771.     If RetValue = 0 Then
  772.        If mCancelError Then Err.Raise (RetValue)
  773.     Else
  774.        With LF
  775.             mItalic = .lfItalic * -1
  776.             mUnderline = .lfUnderline * -1
  777.             mStrikethru = .lfStrikeOut * -1
  778.        End With
  779.        With CF
  780.             mFontSize = .iPointSize \ 10
  781.             mRGBResult = .rgbColors
  782.             If .nFontType And BOLD_FONTTYPE Then
  783.                 mBold = True
  784.             Else
  785.                 mBold = False
  786.             End If
  787.        End With
  788.        FontToUse = CreateFontIndirect(LF)
  789.        If FontToUse = 0 Then Exit Sub
  790.           OldhDC = SelectObject(CF.hDC, FontToUse)
  791.           RetValue = GetTextFace(CF.hDC, 79, tbuf)
  792.           mFontName = Mid$(tbuf, 1, RetValue)
  793.        End If
  794. End Sub
  795. Public Sub ShowPrinter()
  796.   Dim PD As PrintDlg
  797.   Dim DM As DEVMODE
  798.   Dim DN As DEVNAMES
  799.   Dim lpDevMode As Long, lpDevName As Long
  800.   Dim objPrinter As Printer, NewPrinterName As String
  801.   Dim strSetting As String
  802.   Dim uFlag As Long
  803.   uFlag = mFlags And (&H0 Or &H1 Or &H2 Or &H4 Or &H8 Or &H10 Or &H20 Or &H40 Or &H80 Or &H100 Or &H200 Or &H400 Or &H800 Or &H40000 Or &H80000 Or &H100000)
  804.   ' Use PrintDialog to get the handle to a memory
  805.   ' block with a DevMode and DevName structures
  806.     With PD
  807.       .lStructSize = Len(PD)
  808.       .hwndOwner = mhOwner
  809.       .hDC = GetDC(mhOwner)
  810.       .flags = uFlag
  811.     End With
  812.   ' Set the current orientation and duplex setting
  813.     On Error GoTo ErrorHandler
  814.     With DM
  815.         .dmDeviceName = Printer.DeviceName
  816.         .dmSize = Len(DM)
  817.         .dmFields = DM_ORIENTATION Or DM_DUPLEX
  818.         .dmOrientation = Printer.Orientation
  819.          On Error Resume Next
  820.         .dmDuplex = Printer.Duplex
  821.          On Error GoTo 0
  822.     End With
  823.   ' Allocate memory for the initialization hDevMode structure
  824.   ' and copy the settings gathered above into this memory
  825.     PD.hDevMode = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, Len(DM))
  826.     lpDevMode = GlobalLock(PD.hDevMode)
  827.     If lpDevMode > 0 Then
  828.        CopyMemory ByVal lpDevMode, DM, Len(DM)
  829.        RetValue = GlobalUnlock(lpDevMode)
  830.     End If
  831.   ' Set the current driver, device, and port name strings
  832.     With DN
  833.         .wDriverOffset = 8
  834.         .wDeviceOffset = .wDriverOffset + 1 + Len(Printer.DriverName)
  835.         .wOutputOffset = .wDeviceOffset + 1 + Len(Printer.Port)
  836.         .wDefault = 0
  837.     End With
  838.     With Printer
  839.          DN.extra = .DriverName & vbNullChar & .DeviceName & vbNullChar & .Port & vbNullChar
  840.     End With
  841.   ' Allocate memory for the initial hDevName structure
  842.   ' and copy the settings gathered above into this memory
  843.     PD.hDevNames = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, Len(DN))
  844.     lpDevName = GlobalLock(PD.hDevNames)
  845.     If lpDevName > 0 Then
  846.        CopyMemory ByVal lpDevName, DN, Len(DN)
  847.        RetValue = GlobalUnlock(lpDevName)
  848.     End If
  849.   ' Call the print dialog up and let the user make changes
  850.     RetValue = PrintDlg(PD)
  851.     If RetValue = 0 Then
  852.       If mCancelError Then Err.Raise (RetValue)
  853.     Else
  854.    ' get the DC for user API operations
  855.        mhOwner = PD.hDC
  856.    ' get the DevName structure.
  857.        lpDevName = GlobalLock(PD.hDevNames)
  858.        CopyMemory DN, ByVal lpDevName, 45
  859.        RetValue = GlobalUnlock(lpDevName)
  860.        GlobalFree PD.hDevNames
  861.    ' Next get the DevMode structure and set the printer
  862.    ' properties appropriately
  863.        lpDevMode = GlobalLock(PD.hDevMode)
  864.        CopyMemory DM, ByVal lpDevMode, Len(DM)
  865.        RetValue = GlobalUnlock(PD.hDevMode)
  866.        GlobalFree PD.hDevMode
  867.        NewPrinterName = UCase$(Left(DM.dmDeviceName, InStr(DM.dmDeviceName, vbNullChar) - 1))
  868.        If Printer.DeviceName <> NewPrinterName Then
  869.           For Each objPrinter In Printers
  870.               If UCase$(objPrinter.DeviceName) = NewPrinterName Then
  871.                  Set Printer = objPrinter
  872.                End If
  873.           Next
  874.        End If
  875.        On Error Resume Next
  876.      ' Set printer object properties according to selections made
  877.      ' by user
  878.        With Printer
  879.            .Copies = DM.dmCopies
  880.            .Duplex = DM.dmDuplex
  881.            .Orientation = DM.dmOrientation
  882.        End With
  883.        On Error GoTo 0
  884.     End If
  885. ExitSub:
  886.     Exit Sub
  887. ErrorHandler:
  888.     MsgBox Err.Description, vbExclamation, "Printer Error"
  889.     Resume ExitSub
  890. End Sub
  891.  
  892. ' Использование: Private dlg As New clsDialog
  893.  

Ответить

Номер ответа: 4
Автор ответа:
 Winand



Вопросов: 87
Ответов: 2795
 Web-сайт: winandfx.narod.ru
 Профиль | | #4
Добавлено: 10.01.09 17:50
А, так вот что имелось под фразой "поиск файла"

Ответить

Номер ответа: 5
Автор ответа:
 Боцман



ICQ: 295725312 

Вопросов: 53
Ответов: 830
 Web-сайт: Rus-Skipper.narod.ru
 Профиль | | #5
Добавлено: 10.01.09 17:59
Winand пишет:
А, так вот что имелось под фразой "поиск файла"

А что у CommonDialog есть уже и другие варианты?

Ответить

Номер ответа: 6
Автор ответа:
 Cooller



Вопросов: 11
Ответов: 32
 Профиль | | #6 Добавлено: 10.01.09 22:01
а как ocx зарегить в системе? rundll32?

Ответить

Номер ответа: 7
Автор ответа:
 Боцман



ICQ: 295725312 

Вопросов: 53
Ответов: 830
 Web-сайт: Rus-Skipper.narod.ru
 Профиль | | #7
Добавлено: 10.01.09 22:41
Cooller пишет:
 как ocx зарегить в системе? rundll32?

Ну вот опять 25
Холодомор что-ли действует?
Где вопрос и где ответ???

Ответить

Номер ответа: 8
Автор ответа:
 Боцман



ICQ: 295725312 

Вопросов: 53
Ответов: 830
 Web-сайт: Rus-Skipper.narod.ru
 Профиль | | #8
Добавлено: 10.01.09 23:49
Я только намекну можно???

regsvr32 comdlg32.ocx
Писать это в блокноте, потом сохранить в файл с расширением .bat

Ответить

Номер ответа: 9
Автор ответа:
 Cooller



Вопросов: 11
Ответов: 32
 Профиль | | #9 Добавлено: 10.01.09 23:52
а с помощью api возможно?

Ответить

Номер ответа: 10
Автор ответа:
 Arseny



ICQ: 298826769 

Вопросов: 53
Ответов: 1732
 Профиль | | #10 Добавлено: 11.01.09 08:01
Cooller пишет:
а с помощью api возможно?

ты хоть ответы читаешь? Код с моего поста - запихивай в файл с расширением *.cls, цепляй этот файл к проекту, как модуль класса. Пример использования - в самом конце кода.

Ответить

Номер ответа: 11
Автор ответа:
 Cooller



Вопросов: 11
Ответов: 32
 Профиль | | #11 Добавлено: 11.01.09 20:06
Ок, разобрался. Спасибо за ответы, тему можно закрыть...

Ответить

Номер ответа: 12
Автор ответа:
 Winand



Вопросов: 87
Ответов: 2795
 Web-сайт: winandfx.narod.ru
 Профиль | | #12
Добавлено: 11.01.09 20:39
Боцман, я просто всегда считал, что "поиск файла" - это именно процесс поиска файла по заданным юзером параметрам.
а коммон диалог - для открытия(выбора) файла. Вот так и не разобралсо в сути вопроса.

Ответить

Страница: 1 |

Поиск по форуму



© Copyright 2002-2011 VBNet.RU | Пишите нам