News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Problems making child window.

Started by xandaz, September 02, 2019, 09:18:15 PM

Previous topic - Next topic

xandaz

   Hi there guys. It's been a while and i've been trying to get back on track. I was trying to make a child window but pretty much as a normal window. the idea was to make Toolwindow for the main. i cant understand what i'm missing. Help is appreciatted. i thank you guys in advance.

.586
.model flat,stdcall
option casemap:none

__UNICODE__     equ     TRUE

WinMain     PROTO :DWORD,:DWORD,:DWORD,:DWORD

include     \masm32\include\windows.inc
include     \masm32\include\user32.inc
include     \masm32\include\kernel32.inc

includelib  \masm32\lib\user32.lib
includelib  \masm32\lib\kernel32.lib

include      \masm32\macros\macros.asm

.const

; --- Main Window related ---

MainWindowWidth     equ     500
MainWindowHeight    equ     400

; --- Movement related ---

_move_left       equ         10b
_move_right      equ         01b


.data
hInstance       dd          ?
CommandLine     dd          ?

; --- Main Window ---

hwnd            dd          ?
wcMainWindow    WNDCLASSEX  <sizeof WNDCLASSEX,CS_HREDRAW+CS_VREDRAW,\
                            offset WndProc,0,0,?,?,?,COLOR_WINDOW,\
                            0,offset MainWindowClass,?>
UCSTR           MainWindowClass,"MainWindowClass",0
UCSTR           MainWindowName,"MainWindow",0
WindowPosX      dd          ?
WindowPosY      dd          ?
ScreenWidth     dd          ?
ScreenHeight    dd          ?

; --- ToolWindow related ---

UCSTR           ToolBoxClassName,"ToolBoxClass",0
wcToolBox       WNDCLASSEX      <sizeof WNDCLASSEX,CS_BYTEALIGNWINDOW,\
                                offset WndProc2,0,0,?,?,?,COLOR_WINDOW,0,\
                                offset ToolBoxClassName,0>
UCSTR           ToolWindowName,"ToolBox",0
hToolWindow     HWND            ?
                       
.code
    start:
        invoke  GetModuleHandle,0
        mov     hInstance,eax
        invoke  GetCommandLine
        mov     CommandLine,eax
        invoke  WinMain,0,hInstance,0,SW_SHOWNORMAL
        invoke  ExitProcess,eax

WinMain PROC    hPrevInst:DWORD,hInst:DWORD,CmdLine:DWORD,CmdShow:DWORD

        local   msg:MSG

        push    hInst
        pop     wcMainWindow.hInstance
        push    hInst
        pop     wcToolBox.hInstance
        invoke  LoadIcon,0,IDI_APPLICATION
        mov     wcMainWindow.hIcon,eax
        mov     wcMainWindow.hIconSm,eax
        invoke  LoadCursor,0,IDC_ARROW
        mov     wcMainWindow.hCursor,eax
        invoke  RegisterClassEx,addr wcMainWindow
        invoke  GetSystemMetrics,SM_CYSCREEN
        mov     ScreenHeight,eax
        shr     eax,1
        sub     eax,MainWindowHeight/2
        push    eax
        invoke  GetSystemMetrics,SM_CXSCREEN
        mov     ScreenWidth,eax
        shr     eax,1
        sub     eax,MainWindowWidth/2
        pop     ebx
        mov     WindowPosX,eax
        mov     WindowPosY,ebx
        invoke  CreateWindowEx,0,addr MainWindowClass,addr MainWindowName,\
                        WS_OVERLAPPEDWINDOW,eax,ebx,MainWindowWidth,MainWindowHeight,\
                        0,0,hInstance,0
        mov     hwnd,eax
        push    eax
        invoke  LoadCursor,0,IDC_ARROW
        mov     wcToolBox.hCursor,eax
        invoke  RegisterClassEx,addr wcToolBox
        invoke  CreateWindowEx,0,addr wcToolBox,addr ToolWindowName,\
                        WS_CHILD+WS_CAPTION,0,0,100,400,hwnd,0,hInst,0
        mov     hToolWindow,eax
        invoke  ShowWindow,eax,SW_SHOWNORMAL
        pop     eax
        invoke  ShowWindow,eax,CmdShow
        invoke  UpdateWindow,hwnd
msg_loop:                       
        invoke  GetMessage,addr msg,NULL,0,0
        or      eax,eax
        jz      end_msg_loop
        invoke  TranslateMessage,addr msg
        invoke  DispatchMessage,addr msg
        jmp     msg_loop
end_msg_loop:
        mov     eax,msg.wParam
        ret
       
WinMain endp

WndProc     PROC    hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

        local   rect:RECT
        local   ps:PAINTSTRUCT
        local   hDC:HDC
       
        .if     uMsg==WM_DESTROY
            invoke  PostQuitMessage,0
        .elseif uMsg==WM_CREATE
            mov edi,lParam
            .if [edi.CREATESTRUCT.hWndParent]==NULL
            .endif
        .elseif uMsg==WM_PAINT
            invoke  BeginPaint,hWnd,addr ps
            mov hDC,eax
            invoke  EndPaint,hWnd,addr ps                                       
        .else
            invoke  DefWindowProc,hWnd,uMsg,wParam,lParam
            ret
        .endif
        xor     eax,eax
        ret

WndProc     endp

WndProc2    PROC    hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

    invoke  DefWindowProc,hWnd,uMsg,wParam,lParam
    ret

WndProc2     endp
end start

fearless

Probably need to include a value for the hMenu parameter - usually a resource id for the child window, so something other than 0.


.const

IDC_TOOLBOX equ 1000

invoke  CreateWindowEx,0,addr wcToolBox,addr ToolWindowName,\
                        WS_CHILD+WS_CAPTION,0,0,100,400,hwnd,IDC_TOOLBOX,hInst,0

BugCatcher


xandaz

    You classes were registered and changing hMenu to other than zero doent seem to work. the multiwin example from MASM32 sdk has a menu attached to the window. i guess i'll try that. thanks guys

HSE

The problem is that instead name class you write the class. Change to: invoke  CreateWindowEx,0,addr ToolBoxClassName ,addr ToolWindowName,\
                        WS_CHILD+WS_CAPTION,0,0,100,400,hwnd,0,hInstance,0
        mov     hToolWindow,eax
Equations in Assembly: SmplMath

xandaz

    yup. Ty. That was the problem. ty for help