Author Topic: Optimizing DLL dialogues (modeless)  (Read 58 times)

massel_co

  • Newbie
  • *
  • Posts: 5
    • View Profile
Optimizing DLL dialogues (modeless)
« on: March 16, 2020, 04:56:21 PM »
Hi,

I have testing a little on modeless dialogues created from a DLL (a progress bar created via dll function).
There are still some points I would like to optimize:


1. Is there a better way to find out which programme (hwnd of window) is calling the DLL then my try (sources from div. forums)?
Code: [Select]
GLOBAL dwProcID AS DWORD

...

' The exported DLL function to be called from outside
FUNCTION ShowProgress(PerCent%, Text$, Status$) AS HWND EXPORT

...

  dwProcID = GetCurrentProcessId()

...

END FUNCTION

...

' Internal Callback function from DLL dialogue window
FUNCTION PDlgProc (hDlg AS HWND, Msg, wParam, lParam) AS INTEGER CALLBACK

...

  ' Check if Button was pressed
  CASE WM_COMMAND
    IF CBCTL = 3001 THEN
      hWnd = GetTopWindow(GetDesktopWindow())
      WHILE (INT) hWnd <> 0
        dwWndProcID = 0
        GetWindowThreadProcessId(hWnd, &dwWndProcID)
        ' dwProcID = process ID of DLL
        IF dwWndProcID=dwProcID THEN
          IF hDlg <> hWnd AND IsWindowVisible(hWnd) THEN
            ' Send message (WM_APP) to calling window
            SendMessage(hWnd, WM_APP,0,0)
            EXIT WHILE
          END IF
        END IF
        hWnd = GetNextWindow(hWnd, GW_HWNDNEXT)
      WEND
      ' Destroy dialog
      DestroyWindow(hDlg)
    END IF

...

What happens if there are more then one forms (Windows) of the calling programme?

2. It seems that pressing a button in a dialogue is not recognized every time. So I tried a little workaround:
Code: [Select]
SUB FormLoad()

...

  Form1 = BCX_FORM("GUIT-Test for DLL-Progress bar", 6, 18, 160, 100, _
    DS_MODALFRAME OR WS_POPUP OR WS_VISIBLE OR WS_CAPTION OR WS_SYSMENU)
  Button1 = BCX_BUTTON("Show progress bar", Form1, IDC_BUTTON1, 60, 24, 60, 20)

...

  SetProp(Button1, "oldproc", (HANDLE)GetWindowLong(Button1,GWL_WNDPROC))
  SetWindowLong(Button1, GWL_WNDPROC,(DWORD)LabelProc)

... 

  SHOW(Form1)
END SUB


BEGIN EVENTS
  SELECT CASE CBMSG
  CASE WM_MOUSEMOVE
    IF Focus THEN
     Focus = FALSE
    END IF

...

END EVENTS


CALLBACK Function LabelProc()
  DIM lpfnOldProc AS FARPROC

...

  lpfnOldProc = GetProp(hWnd, "oldproc")

  SELECT CASE Msg
  CASE WM_MOUSEMOVE
    IF NOT Focus THEN
      Focus = TRUE
    END IF

  CASE WM_LBUTTONDOWN, WM_COMMAND
    IF Focus OR CBCTL = IDC_BUTTON1 THEN

...

 END FUNCTION

Is there a better way to detect pressing the button?


For completeness the whole project including two testing applications GUI_Test (with GUI) and CON_Test (console application) is  attached here.
I would really appreciate some hints and tips for optimizing the code.
« Last Edit: March 16, 2020, 04:58:17 PM by massel_co »