Habe mich mal mit den Problem beschäftigt.
Das mit den Titel fehler ist nur mit der Version von PB < 5.50 vorhanden...
Hier mal alles etwas überarbeitet und mit den FIX für die 32bit Version und Unicode (PB-v5.46)
P.S. Es werden nicht alle Styles von PB unterstützt...
Code: Alles auswählen
;-TOP
; Comment : Open window with own classname
; Authors : Edel, ts-soft, mk-soft
; Version : v1.03
; Create : 04.08.2012
; Update : 19.03.2020
; OS: : Windows
EnableExplicit
CompilerIf #PB_Compiler_Version < 550
CompilerIf #PB_Compiler_Unicode
; Fix API-Functions
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
Import "user32.lib"
CreateWindowEx_(dwExStyle,lpClassName.p-unicode,lpWindowName.p-ascii,dwStyle,X,Y,nWidth,nHeight,hWndParent,hMenu,hInstance,lpParam) As "_CreateWindowExW@48";
RegisterClass_(class) As "_RegisterClassW@4"
UnregisterClass_(handle, ClassName.p-unicode) As "_UnregisterClassW@8"
SetWindowText_(Handle, Title.p-ascii) As "_SetWindowTextW@8"
EndImport
CompilerElse
Import "user32.lib"
CreateWindowEx_(dwExStyle,lpClassName.p-unicode,lpWindowName.p-ascii,dwStyle,X,Y,nWidth,nHeight,hWndParent,hMenu,hInstance,lpParam) As "CreateWindowExW";
RegisterClass_(class) As "RegisterClassW"
UnregisterClass_(handle, ClassName.p-unicode) As "UnregisterClassW"
SetWindowText_(Handle, Title.p-ascii) As "SetWindowTextW"
EndImport
CompilerEndIf
; Fix PB-Funtion SetWindowTitle
Macro SetWindowTitle(Window, Title)
SetWindowText_(WindowID(Window), Title)
EndMacro
CompilerEndIf
CompilerEndIf
Import "window.lib"
PB_Window_ProcessEvent(a,b,c,d)
PB_Object_GetOrAllocateID(*Object,id)
PB_Window_Icon
PB_Window_Cursor
PB_Window_Objects
EndImport
Procedure OpenWindowEx(Window, x, y, Width, Height, ClassName.s, Title.s, Flags=0, Parent=0)
Protected wnd.wndclass, rc.rect, *WinObj.integer, hWnd.i, r1
If Not Flags
Flags = $14C80000
Else
Flags | $14000000
EndIf
With wnd
\style = #CS_HREDRAW|#CS_VREDRAW
\lpfnWndProc = @PB_Window_ProcessEvent()
\hInstance = GetModuleHandle_(0)
\hIcon = PB_Window_Icon
\hCursor = PB_Window_Cursor
\lpszClassName = @ClassName
\hbrBackground = #COLOR_WINDOW
\cbWndExtra = 0
\cbClsExtra = 0
EndWith
If RegisterClass_(wnd)
; Adjust Window
SetRect_(rc,0 ,0 , Width, Height)
AdjustWindowRectEx_(rc, Flags, 0, #WS_EX_WINDOWEDGE)
; Set defaults
If x = #PB_Ignore Or y = #PB_Ignore
x = #CW_USEDEFAULT
y = #CW_USEDEFAULT
EndIf
; Create window
hWnd = CreateWindowEx_(#WS_EX_WINDOWEDGE,classname,title,flags,x,y,rc\right-rc\left,rc\bottom-rc\top,parent,0,GetModuleHandle_(0),0)
; Add window object
If hWnd
*WinObj = PB_Object_GetOrAllocateID(PB_Window_Objects, Window)
*WinObj\i = hWnd
If Window = #PB_Any
SetProp_(hWnd, "PB_WindowID", *WinObj + 1)
Else
SetProp_(hWnd, "PB_WindowID", Window + 1)
EndIf
UseGadgetList(hWnd)
Else
UnregisterClass_(GetModuleHandle_(0),ClassName)
EndIf
EndIf
; Result
If Window = #PB_Any
r1 = *WinObj
Else
r1 = hWnd
EndIf
ProcedureReturn r1
EndProcedure
;- Test
Procedure Main()
Protected win1, style
style = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
win1 = OpenWindowEx(1, #PB_Ignore, #PB_Ignore ,200 ,200 ,"MyOwnApp", "Title", style)
;win1 = OpenWindow(1, #PB_Ignore, #PB_Ignore ,200 ,200 , "Title", style)
ResizeWindow(1, #PB_Ignore, #PB_Ignore, 500, 500)
ButtonGadget(0, 10, 10, 160, 30, "Find ClassName")
ButtonGadget(1, 10, 50, 160, 30, "Find Title")
SetWindowTitle(1, "Mein Programm")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
Select EventGadget()
Case 0
If FindWindow_("MyOwnApp", 0)
MessageRequester("Search", "Find over ClassName" + #LF$ + "PB-WindowID = " + Str(GetProp_(WindowID(1), "PB_WindowID") - 1))
Else
MessageRequester("Search", "Not find over ClassName")
EndIf
Case 1
If FindWindow_(0, "Mein Programm")
MessageRequester("Search", "Find over Title" + #LF$ + "PB-WindowID = " + Str(GetProp_(WindowID(1), "PB_WindowID") - 1))
Else
MessageRequester("Search", "Not find over Title")
EndIf
EndSelect
EndSelect
ForEver
EndProcedure : Main()
End