Hi
I'm trying to make a program with one "main" window and a few other windows that should always be in front of the main window and clip to the main window.
Some time ago when testing out WinFBX I got it working with this code:
Quote
' Init Main Window
dwStyle = WS_VISIBLE or WS_OVERLAPPEDWINDOW OR WS_CLIPCHILDREN OR WS_CLIPSIBLINGS or WS_MAXIMIZE
dwExStyle = WS_EX_CONTROLPARENT OR WS_EX_CLIENTEDGE
MainWindow.Create(NULL, "Main window", @MainWindow_WndProc, 50, 50, 1000, 800, dwStyle, dwExStyle)
MainWindow.Brush = CreateSolidBrush(BGR(92, 92, 92))
UpdateWindow MainWindow.hWindow
' Init Tool Window
dwStyle = WS_VISIBLE or WS_CAPTION or WS_MAXIMIZEBOX or WS_CHILD or WS_SIZEBOX or WS_CLIPSIBLINGS or WS_HSCROLL or WS_VSCROLL
dwExStyle = WS_EX_TOOLWINDOW
ToolWindow.Create(MainWindow.hWindow, "Tool", @ToolWindow_WndProc, 300, 200, 800, 600, dwStyle, dwExStyle)
Is it possible to do the same in the WinFBE using the designer?
Hi,
Yes, creating such applications is pretty straight forward in WinFBE. I have attached a simple project that shows the basics of how to do it.
The popup window "frmTool1" set the BorderStyle to "FormBorderStyle.FixedToolWindow".
To display the popup tool window, you will want to display it modeless and make frmMain as the owner form.
frmTool1.Show( frmMain )
Note: The above displays the form as modeless. If you need to display a modal form, then you would use:
frmTool1.ShowDialog( frmMain )
Hope this helps!
Thank you, that was easy =)
Is it also possible to add the default scrollbars with WS_HSCROLL / WS_VSCROLL on a window in the designer? I tried to make the Toolwindow a child window, but that didn't change anything, like when adding "WS_CHILD" will make the tool windows position relative to the parent window(plus clip the child window to the size of the parent).
Also before seeing your code, I tried:
Quote
frmTool1.Parent = frmMain.hWindow
frmTool1.Show
But this gives a compiler error for "No matching overload...Parent()". Should this have worked?
You set the "ChildForm" property to TRUE for frmTool1 and then display it as a child frmMain
Function frmMain_Load( ByRef sender As wfxForm, ByRef e As EventArgs ) As LRESULT
frmTool1.ShowChild( frmMain )
Function = 0
End Function
The overload error occurs because Parent is not defined as an object but rather a pointer (because of some limitations with FB's ByRef).
The following two syntaxes should work:
frmTool1.Parent = @frmMain
frmTool1.hWindowParent= frmMain.hWindow
I don't think I built into the designer a way to add default scrollbars. I'll put that on my To Do list.
When I try this, I get a child window placed on the main window(which is probably what most would want). I'm trying to create a movable child window like in this code(that follows and clips to the main window):
Quote
#define UNICODE
#INCLUDE ONCE "Afx\CWindow.inc"
USING Afx
declare FUNCTION MainWindow_WndProc (BYVAL hwnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT
declare FUNCTION ToolWindow_WndProc (BYVAL hwnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT
Dim shared MainWindow as CWindow
Dim shared ToolWindow as CWindow
' // Set process DPI aware
AfxSetProcessDPIAware
dim AS UINT dwStyle, dwExStyle
' Init Main Window
dwStyle = WS_VISIBLE or WS_OVERLAPPEDWINDOW
dwExStyle = 0
MainWindow.Create(NULL, "Main", @MainWindow_WndProc, 50, 50, 1000, 800, dwStyle, dwExStyle)
MainWindow.Brush = CreateSolidBrush(BGR(92, 92, 92))
UpdateWindow MainWindow.hWindow
' Init ToolWindow
dwStyle = WS_HSCROLL or WS_VSCROLL or WS_CHILD or WS_VISIBLE or WS_CAPTION
dwExStyle = WS_EX_TOOLWINDOW
ToolWindow.Create(MainWindow.hWindow, "Tool", @ToolWindow_WndProc, 300, 200, 500, 500, dwStyle, dwExStyle)
ToolWindow.Brush = CreateSolidBrush(BGR(250, 250, 250))
UpdateWindow ToolWindow.hWindow
DIM uMsg AS MSG
' // Message loop
WHILE .GetMessageW(@uMsg, NULL, 0, 0)
' // Processes accelerator keys for menu commands
IF MainWindow.AccelHandle = NULL OR .TranslateAcceleratorW(MainWindow.hWindow, MainWindow.AccelHandle, @uMsg) = 0 THEN
' // Translates virtual-key messages into character messages.
.TranslateMessage @uMsg
' // Dispatches a message to a window procedure.
.DispatchMessageW @uMsg
END IF
WEND
'____________________________________________________________________________________________________
FUNCTION MainWindow_WndProc (BYVAL hwnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT
SELECT CASE uMsg
CASE WM_COMMAND
SELECT CASE GET_WM_COMMAND_ID(wParam, lParam)
CASE IDCANCEL
' // If ESC key pressed, close the application by sending an WM_CLOSE message
IF GET_WM_COMMAND_CMD(wParam, lParam) = BN_CLICKED THEN
SendMessageW hwnd, WM_CLOSE, 0, 0
EXIT FUNCTION
END IF
END SELECT
CASE WM_DESTROY
' // End the application
PostQuitMessage(0)
EXIT FUNCTION
END SELECT
' // Default processing of Windows messages
FUNCTION = DefWindowProcW(hWnd, uMsg, wParam, lParam)
END FUNCTION
'____________________________________________________________________________________________________
FUNCTION ToolWindow_WndProc (BYVAL hwnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT
SELECT CASE uMsg
CASE WM_COMMAND
SELECT CASE GET_WM_COMMAND_ID(wParam, lParam)
CASE IDCANCEL
END SELECT
CASE WM_DESTROY
EXIT FUNCTION
END SELECT
' // Default processing of Windows messages
FUNCTION = DefWindowProcW(hWnd, uMsg, wParam, lParam)
END FUNCTION
Hi,
Attached is a project that emulates the code that you posted. I had to modify the child form's styles in its Load event. I have also attached a screenshot of the running program.
That's excellent! Nice to have such flexibility on top of the designer.
A few small notes/possible bugs(from a first time user):
- Unlike when selecting "FormBorderStyle.FixedToolWindow", selecting "FormBorderStyle.SizableToolWindow shows (in the designer) a form without a caption(but it shows up correctly when running the code).
- Is it correct behavior that when double clicking on the caption box of a "FormBorderStyle.FixedToolWindow" it maximizes the ToolWindow?
Under Help->Form (wfxForm)->Events , maybe add a small note about activating Events in the designer before trying to use them in the code. Its a bit embarrassing, but the first time I wanted to test the events I tried to create the event functions manually in the form code =)
Under Help->Form (wfxForm)->During form creation, there is two events called "FormLoad" and "FormFormActivated", that should probably be just "Load" and "Activated" ?
Thanks for the feedback! I'll work through them tomorrow and get the corrections made.