News:

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

piping to child windows, and right click menus

Started by Slugsnack, July 22, 2009, 07:25:09 AM

Previous topic - Next topic

Slugsnack

hi

i am going to be piping the contents of 4 different applicatoins to mine. namely :
- ping.exe
- tracert.exe
- telnet.exe
- putty.exe

they will be all piped onto the same main window. i intend to have 4 chlid windows and have edit controls within them. my user wants to be able to move and resize the piped output. i think if i put the 4 child dialogs then they SHOULD be movable.. and probably resizable but how can i make it so the edit control inside which is having the contents piped changes size with it ? i thought of handling the size change and then using setwindowpos to set the edit control to the same size as the child window constantly, any other ideas ? can't test it right now cause i'm at work ( i prrobably should be working.. )

also does anyone know how to implement a right-click menu for the edit controls ? i want it so a menu will come up and i can handle which menu item is clicked

MichaelW

I haven't tried to keep up with what you are doing, but this demonstrates a resizable dialog with an edit control that fills the client area, and a "right-click" menu implemented in a subclass procedure for the edit control. I put right-click in quotes because the code actually checks only for a right-button release event. Also, the edit control will flash when the window is resized (but not quite as bad as notepad does, on my Windows 2000 system), and I know of no way to eliminate this, with an edit control.


; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
IDC_EDIT equ 100
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
      hInstance     dd 0
      origEditProc  dd 0
      hwndEdit      dd 0
      hmenuPop      dd 0
    .code
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

EditProc proc hwnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

    LOCAL pt:POINT

    SWITCH uMsg

      CASE WM_RBUTTONUP

        mov eax, lParam
        movzx eax, ax
        mov pt.x, eax
        mov eax, lParam
        shr eax, 16
        mov pt.y, eax

        invoke ClientToScreen, hwnd, ADDR pt

        invoke TrackPopupMenu, hmenuPop, TPM_LEFTALIGN or TPM_RETURNCMD or \
                               TPM_TOPALIGN or TPM_HORPOSANIMATION,
                               pt.x,
                               pt.y,
                               0,
                               hwnd,
                               0

        .IF eax
           invoke MessageBox, hwnd, str$(eax), chr$("Selected ID"), 0
        .ENDIF

      DEFAULT

        invoke CallWindowProc, origEditProc, hwnd, uMsg, wParam, lParam

    ENDSW

    ret

EditProc endp

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

DlgProc proc hwndDlg:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD

    LOCAL rc:RECT

    SWITCH uMsg

      CASE WM_INITDIALOG

        invoke GetDlgItem, hwndDlg, IDC_EDIT
        mov hwndEdit, eax
        invoke SetWindowLong, hwndEdit, GWL_WNDPROC, EditProc
        mov origEditProc, eax

        invoke CreatePopupMenu
        mov hmenuPop, eax

        invoke AppendMenu, hmenuPop, MF_STRING, 1001, chr$("Option &1")
        invoke AppendMenu, hmenuPop, MF_STRING, 1002, chr$("Option &2")
        invoke AppendMenu, hmenuPop, MF_SEPARATOR, 0, 0
        invoke AppendMenu, hmenuPop, MF_STRING, 1003, chr$("Option &3")

      CASE WM_COMMAND

        SWITCH wParam

          CASE IDCANCEL

            invoke EndDialog, hwndDlg, 0

        ENDSW

      CASE WM_SIZE

        invoke GetClientRect, hwndDlg, ADDR rc

        invoke MoveWindow, hwndEdit, 0, 0, rc.right, rc.bottom, TRUE

      CASE WM_CLOSE

        invoke EndDialog, hwndDlg, 0

    ENDSW

    return 0

DlgProc endp

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

    invoke GetModuleHandle, NULL
    mov hInstance, eax

    Dialog "TEST","MS Sans Serif",10, \
            WS_OVERLAPPEDWINDOW or WS_CLIPCHILDREN or DS_CENTER, \
            1,0,0,100,80,1024

    DlgEdit WS_BORDER or ES_MULTILINE or ES_WANTRETURN or WS_TABSTOP or \
            WS_HSCROLL or WS_VSCROLL or ES_AUTOVSCROLL or ES_AUTOVSCROLL or \
            WS_CLIPSIBLINGS,0,0,0,0,IDC_EDIT

    CallModalDialog hInstance,0,DlgProc,NULL

    exit

; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start

eschew obfuscation

Slugsnack

aha perfect michael, that is just what i was looking for.

TrackPopupMenu + AppendMenu and yeahhh MoveWindow seems nicer than SetWindowPos.

thanks !

Slugsnack

hmm if i am using resources how can i embed one dialog within another ? like a child window ? my current method is to create one dialog then make it a child dialog then set its  parent.. but there should be a way at compile time where i can put it inside it ?! i'm using resed btw

// edit : i think i'm gonna create a hidden modeless child dialog with createdialog then with createdialogboxparam i can create the main modal one.. brb gonna try that

booya it worked. i ended up using createdialogparam instead of createdialog. i dunno how to make those macros work in masm.. just have to use the standard function instead. but as you can see it works well : )


Slugsnack

mmm i'm having some problems again !



that is 4 child windows within the main one. is it possible to not make it mess up like that without constantly sending redraw messages to all 4 windows ?

Tedd

Try adding WS_CLIPSIBLINGS to the window style when you create the parent.
No snowflake in an avalanche feels responsible.

Slugsnack

thanks Tedd it works perfect now ; ) i added WS_CLIPCHILDREN to the main window and WS_CLIPSIBLINGS to each of the child windows


Slugsnack

michael, i was just writing my code now and i was wondering why do you get the client rectangle again ? you can just read it off from lParam

MichaelW

To save time I frequently recycle old code, and in this case I used what I found first. Using the client size from lParam is significantly easier only with the aid of macros.


LOCAL rc:RECT
invoke GetClientRect, hwndDlg, ADDR rc
invoke MoveWindow, hwndEdit, 0, 0, rc.right, rc.bottom, TRUE


mov ecx, lParam
mov edx, ecx
movzx ecx, cx
shr edx, 16
invoke MoveWindow, hwndEdit, 0, 0, ecx, edx, TRUE


loword MACRO arg
    IFNDEF __loword_macro_return_var__
      .data
        __loword_macro_return_var__ dd 0
      .code
    ENDIF
    push arg
    pop __loword_macro_return_var__
    and __loword_macro_return_var__, 0ffffh
    EXITM <__loword_macro_return_var__>
ENDM

hiword MACRO arg
    IFNDEF __hiword_macro_return_var__
      .data
        __hiword_macro_return_var__ dd 0
      .code
    ENDIF
    push arg
    pop __hiword_macro_return_var__
    shr __hiword_macro_return_var__, 16
    EXITM <__hiword_macro_return_var__>
ENDM

invoke MoveWindow, hwndEdit, 0, 0, loword(lParam), hiword(lParam), TRUE


eschew obfuscation