2024 Technology Preview Program:
Master powerful new features and shape the latest BIM-enabled innovations
2020-02-02
05:43 PM
- last edited on
2022-10-04
04:22 PM
by
Daniel Kassai
#include "APICommon.h" #include "ResourceIDs.hpp" #include "DG.h" #include <windows.h> // Window callback procedure LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_DESTROY: PostQuitMessage(0); break; default: return ::DefWindowProc(hWnd, uMsg, wParam, lParam); } return 0; } // creating a window with the Windows API HWND CreateWindow(WNDCLASS wc, HWND hwndMainWindow) { // Create the window. HWND hwnd = ::CreateWindowEx(0, wc.lpszClassName, L"", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hwndMainWindow, NULL, wc.hInstance, NULL); if (hwnd == NULL) { return 0; } ::ShowWindow(hwnd, SW_MAXIMIZE); return hwnd; } bool OpenBrowser() { HWND hwndMainWindow = ACAPI_GetMainWindow(); // disable the main window of Archicad ::EnableWindow(hwndMainWindow, FALSE); // get instance of application HINSTANCE hInstance = ACAPI_GetExtensionInstance(); // create window class WNDCLASS wc = { }; wc.lpfnWndProc = WindowProc; wc.hInstance = hInstance; wc.lpszClassName = L"Browser Window Class"; // register window class if (!::RegisterClass(&wc)) { return false; } bool bResult = false; DG::Browser* browser = nullptr; // create a modal window HWND hWndBrowser = CreateWindow(wc, hwndMainWindow); if (hWndBrowser != nullptr) { RECT rect; const BOOL bRect = GetWindowRect(hWndBrowser, &rect); if (bRect) { const DG::Rect dgRect((short)rect.left, (short)rect.top, (short)rect.right, (short)rect.bottom); // create browser in modal window browser = new DG::Browser(dgRect); browser->SetUpForNativeWindow(hWndBrowser, dgRect); browser->LoadURL("https://google.com/"); // Main message loop: MSG msg; while (::GetMessage(&msg, NULL, 0, 0)) { ::TranslateMessage(&msg); ::DispatchMessage(&msg); } bResult = true; } } // unregister window class, freeing the memory ::UnregisterClass(wc.lpszClassName, hInstance); // enable the main window of Archicad ::EnableWindow(hwndMainWindow, TRUE); // TODO: crashes if deleted //delete browser; return bResult; }
Solved! Go to Solution.
2020-02-04 02:40 PM
2020-02-02 06:59 PM
Martin wrote:Would there be a problem creating the window using the ARCHICAD API rather than the Windows API? I believe your efforts are much more likely to be successful if you use one API for your UI workflow.
I'd like to use the DG::Browser embedded in a modal window created by the Windows API.
2020-02-04 01:14 AM
2020-02-04 11:21 AM
2020-02-04 01:40 PM
#include "DialogBrowser.h" #include "APICommon.h" #include "ResourceIDs.hpp" #include "DG.h" #include "DGModule.hpp" DG::Browser* browser; // ----------------------------------------------------------------------------- // browser dialog handler (callback) // ----------------------------------------------------------------------------- static short DGCALLBACK DialogBrowserHandler( short message, short dialogID, short item, DGUserData /*userData*/, DGMessageData /*msgData*/) { short result = 0; switch (message) { case DG_MSG_INIT: { HWND hWndMain = ACAPI_GetMainWindow(); if (hWndMain) { HWND hWndDialog = GetWindow(hWndMain, GW_HWNDPREV); if (hWndDialog) { RECT rect; if (GetWindowRect(hWndDialog, &rect)) { // create browser in modal window const DG::Rect dgRect((short)rect.left, (short)rect.top, (short)rect.right, (short)rect.bottom); browser = new DG::Browser(dgRect); browser->LoadURL("https://google.com/"); } } } } break; case DG_MSG_CLICK: { switch (item) { case DG_OK: case DG_CANCEL: result = item; break; } } break; case DG_MSG_CLOSE: { result = item; } break; } return result; } bool OpenBrowser() { // Get the browser dialog from our resource file const short result = DGModalDialog(ACAPI_GetOwnResModule(), ID_DIALOG_BROWSER, ACAPI_GetOwnResModule(), DialogBrowserHandler, 0); return result; }And the .grc:
2020-02-04 02:05 PM
Browser (const Panel& panel, short item);
2020-02-04 02:18 PM
2020-02-04 02:40 PM