News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Floating Window

Started by Darrel, October 21, 2006, 07:52:18 PM

Previous topic - Next topic

Darrel

I want to make a floating window like the Find Window with notepad. It is to remain on top of the main window but also allow the main window to be the active window. It should also be hidden when the main window is minimized. I have tried using the WM_WINDOWPOSCHANGING message to see when either window is becoming the top window but the WINDOWPOS.hwndInsertAfter member does not contain HWND_TOP as expected.

Thanks for your time and consideration.

Darrel

MichaelW

#1
AFAIK the Find window for notepad is just a normal modeless dialog with notepad as the owner window. A quick and dirty example:

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    include \masm32\include\masm32rt.inc

    ; This extends the dialog macros to do modeless dialogs.
    ;
    CallModelessDialog MACRO Instance,Parent,DlgProc,lParamInit

      invoke CreateDialogIndirectParam,Instance,esi,Parent,
                                       ADDR DlgProc,lParamInit
      push eax                ;; preserve return value
      invoke GlobalFree,esi   ;; free memory
      pop eax                 ;; restore return value
      pop edi
      pop esi

    ENDM

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
        hInst     dd  0
        hMainDlg  dd  0
        hChildDlg dd  0
        msg       MSG <>
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

ChildDialogProc proc hDlg:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

    .if uMsg == WM_INITDIALOG

    .elseif uMsg == WM_CLOSE

      invoke DestroyWindow, hDlg

    .endif

    xor eax, eax
    ret

ChildDialogProc endp
   
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

MainDialogProc proc hDlg:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

    .if uMsg == WM_INITDIALOG

      Dialog "Child Dialog","MS Sans Serif",10, \
              WS_OVERLAPPED or WS_SYSMENU or DS_CENTER or WS_VISIBLE, \
              0,0,0,120,90,1024
      CallModelessDialog hInst,hDlg,ChildDialogProc,NULL
      mov hChildDlg, eax

    .elseif uMsg == WM_CLOSE

      invoke DestroyWindow, hDlg

    .elseif uMsg == WM_DESTROY

      invoke PostQuitMessage,0

    .endif

    xor eax, eax
    ret

MainDialogProc endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    invoke GetModuleHandle, 0
    mov hInst, eax

    ; A modeless dialog must include the WS_VISIBLE style to be visible.
    ;
    Dialog "Main Dialog","MS Sans Serif",10, \
            WS_OVERLAPPEDWINDOW or DS_CENTER or WS_VISIBLE, \
            0,0,0,200,150,1024
    CallModelessDialog hInst,0,MainDialogProc,0
    mov hMainDlg, eax

  msgLoop:
 
    invoke GetMessage,ADDR msg,0,0,0
    .IF (eax != 0)
        invoke IsDialogMessage,hMainDlg,ADDR msg
        .IF (eax == 0)
            invoke IsDialogMessage,hChildDlg,ADDR msg
        .ENDIF
        jmp msgLoop
    .ENDIF
   
    exit

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

end start
eschew obfuscation

Darrel


hutch--

Michael,

Thanks for the "CallModelessDialog" macro, I would be more than pleased to add it to the DIALOGS include file if its OK with you.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

MichaelW

QuoteI would be more than pleased to add it to the DIALOGS include file if its OK with you.

Sure. Starting with the CallModalDialog macro and having to change 29 characters was hard work :)

eschew obfuscation

hutch--

Gratsie,

The deed is done.  :bg
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

asmfan

I would also suggest using SetWindowPos on child widow with SWP_NOACTIVATE flag
Russia is a weird place