The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: bonjour on March 05, 2007, 04:59:11 PM

Title: adding controls
Post by: bonjour on March 05, 2007, 04:59:11 PM
I want to add controls such as buttons and text boxes to the window but there is no output .
I dont know what is going on?
I need your help guys,
Looking forward to your posts,

.386
.model flat, stdcall
option casemap:none

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

WinMain proto :DWORD, :DWORD, :DWORD, :DWORD

.data
        ClassName db "WinClass",0
        AppName   db "Simple Window",0
        EditClassName db "edit",0
        ButtonClassName db "button",0
        ButtonText  db "click me", 0
.data?
        hInstance HINSTANCE ?
        hEdit     HINSTANCE ?
        hButton   HINSTANCE ?
       
.const
    EditID equ 1
    ButtonID equ 2     
       


.code
start:   invoke GetModuleHandle, NULL
         mov hInstance, eax
         invoke WinMain, hInstance, NULL, NULL, 0
         invoke ExitProcess, eax
         WinMain proc hInst:HINSTANCE, hPrevInst:HINSTANCE,\
                CmdLine:LPSTR, CmdShow:DWORD
                local wc:WNDCLASSEX
                local msg:MSG
                local hwnd:HWND
                mov wc.cbSize, SIZEOF WNDCLASSEX
                mov wc.style, CS_HREDRAW or CS_VREDRAW
                mov wc.lpfnWndProc, offset WndProc
                mov wc.cbClsExtra, NULL
                mov wc.cbWndExtra, NULL
                push hInstance
                pop wc.hInstance
                mov wc.hbrBackground, COLOR_WINDOW+1
                mov wc.lpszMenuName, NULL
                mov wc.lpszClassName, offset ClassName
                invoke LoadCursor, NULL, IDC_ARROW
                mov wc.hCursor, eax
                invoke LoadIcon, NULL, IDI_APPLICATION
                mov wc.hIcon, eax
                mov wc.hIconSm, eax
               .while TRUE
                    invoke GetMessage, addr msg, NULL, 0, 0
                    .break .if(!eax)
                    invoke TranslateMessage, addr msg
                    invoke DispatchMessage, addr msg
               .endw
                mov eax, msg.wParam
                ret

          WinMain endp
          WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM,\
                lParam:LPARAM
                .if uMsg == WM_DESTROY
                    invoke PostQuitMessage, 0
                .elseif uMsg == WM_CREATE
               
                    invoke CreateWindowEx, NULL, addr ButtonClassName,\
                    addr ButtonText, \
                    WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON,\
                    10, 50, 80, 30, hWnd, ButtonID,\
                    hInstance, NULL
                   
                    mov hButton, eax
                   
                    invoke CreateWindowEx,\
                    WS_EX_CLIENTEDGE, addr EditClassName,\
                    NULL, WS_CHILD or WS_VISIBLE, 10, 10,\
                    100, 20, hWnd, EditID,\
                    hInstance, NULL
                   
                    mov hEdit, eax
                .elseif uMsg == WM_COMMAND
                    mov eax, wParam
                   .if ax == ButtonID
                        shr eax, 16
                        .if ax == BN_CLICKED
                            ;some code here
                        .endif
                    .endif
                    invoke DefWindowProc, hWnd, uMsg, wParam, lParam
                    ret
                .endif
                xor eax, eax
                ret
          WndProc endp
end start


               
               
               
         
         
         

Title: Re: adding controls
Post by: ragdog on March 05, 2007, 06:52:53 PM
hi bonjour

see in Iczelion's Example Code
or in masm32 install folder --> examples
http://www.movsd.com/download/icztutes.exe

that will continue to help to you

greetz
ragdog
Title: Re: adding controls
Post by: MichaelW on March 05, 2007, 08:10:42 PM
bonjour,

Your WinMain is missing some essential components, in WndProc the call to DefWindowProc is misplaced, and there may be other problems that I didn't notice.