Получить hwnd окна экземпляра - VB
Формулировка задачи:
Всем привет, подскажите как получить хендл окна экземпляра? Допустим всего запусков программы было только 2. из них надо вернуть хендл первого окна
Заранее спасибо
Решение задачи: «Получить hwnd окна экземпляра»
textual
Листинг программы
Option Explicit Private Declare Function CreateFileMapping Lib "kernel32" Alias "CreateFileMappingA" (ByVal hFile As Long, lpFileMappingAttributes As Any, ByVal flProtect As Long, ByVal dwMaximumSizeHigh As Long, ByVal dwMaximumSizeLow As Long, ByVal lpName As String) As Long Private Declare Function MapViewOfFile Lib "kernel32" (ByVal hFileMappingObject As Long, ByVal dwDesiredAccess As Long, ByVal dwFileOffsetHigh As Long, ByVal dwFileOffsetLow As Long, ByVal dwNumberOfBytesToMap As Long) As Long Private Declare Function UnmapViewOfFile Lib "kernel32" (ByVal lpBaseAddress As Long) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Private Declare Function GetMem4 Lib "msvbvm60" (Src As Any, Dst As Any) As Long Private Const ERROR_ALREADY_EXISTS = 183& Private Const PAGE_READWRITE = 4& Private Const FILE_MAP_WRITE = &H2 Dim hMap As Long Private Sub Form_Load() Dim ptr As Long, e As Long, hPrev As Long hMap = CreateFileMapping(-1, ByVal 0&, PAGE_READWRITE, 0, 4, "MyPrevAppInst"): e = Err.LastDllError If hMap = 0 Then MsgBox "Err create file mapping": End ptr = MapViewOfFile(hMap, FILE_MAP_WRITE, 0, 0, 0) If ptr = 0 Then MsgBox "Projection error" CloseHandle hMap End End If If e = ERROR_ALREADY_EXISTS Then ' Ýêçåìïëÿð óæå Г§Г*ГЇГіГ№ГҐГ* GetMem4 ByVal ptr, hPrev UnmapViewOfFile ptr CloseHandle hMap MsgBox "Ýêçåìïëÿð Г§Г*ГЇГіГ№ГҐГ* hwnd: " & hPrev End End If GetMem4 CLng(Me.hWnd), ByVal ptr UnmapViewOfFile ptr End Sub Private Sub Form_Unload(Cancel As Integer) CloseHandle hMap End Sub
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д