Can't I place a button on a form without using a dialog ?
Bob
Yes, it's generally easier with a dialog, but you can do basically anything with an application window that you can do with a dialog. MASM32 includes a set of procedures to simplify this somewhat, and this quick-and-dirty example uses the PushButton procedure.
;==============================================================================
include \masm32\include\masm32rt.inc
;==============================================================================
.data
hInstance HINSTANCE 0
hWnd HWND 0
wcx WNDCLASSEX <>
msg MSG <>
className db "test",0
.code
;==============================================================================
include \masm32\procs\button.asm
;==============================================================================
WindowProc proc hwnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
SWITCH uMsg
CASE WM_CREATE
invoke PushButton,chr$("OK"),hwnd,180,120,50,30,100
CASE WM_COMMAND
SWITCH wParam
CASE 100, IDCANCEL
invoke DestroyWindow, hwnd
ENDSW
CASE WM_CLOSE
invoke DestroyWindow, hwnd
CASE WM_DESTROY
invoke PostQuitMessage, NULL
DEFAULT
invoke DefWindowProc, hwnd, uMsg, wParam, lParam
ret
ENDSW
return 0
WindowProc endp
;==============================================================================
start:
;==============================================================================
invoke GetModuleHandle, NULL
mov hInstance, eax
mov wcx.cbSize, SIZEOF WNDCLASSEX
mov wcx.style, CS_BYTEALIGNCLIENT
mov wcx.lpfnWndProc, OFFSET WindowProc
mov wcx.cbClsExtra, NULL
mov wcx.cbWndExtra, NULL
push hInstance
pop wcx.hInstance
mov wcx.hbrBackground, COLOR_WINDOW + 1
mov wcx.lpszMenuName, NULL
mov wcx.lpszClassName, OFFSET className
invoke LoadIcon, NULL, IDI_APPLICATION
mov wcx.hIcon, eax
invoke LoadCursor, NULL, IDC_ARROW
mov wcx.hCursor, eax
mov wcx.hIconSm, 0
invoke RegisterClassEx, addr wcx
invoke CreateWindowEx, 0,
ADDR className,
chr$("Test"),
WS_VISIBLE or WS_OVERLAPPED or WS_SYSMENU,
100,100,400,300,
NULL, NULL,
NULL, NULL
mov hWnd, eax
invoke ShowWindow, hWnd, SW_SHOWDEFAULT
invoke UpdateWindow, hWnd
msgLoop:
invoke GetMessage, ADDR msg, NULL, 0, 0
.IF eax > 0
invoke IsDialogMessage, hWnd, ADDR msg
.IF eax == 0
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.ENDIF
jmp msgLoop
.ENDIF
exit msg.wParam
;==============================================================================
end start
you can also create a button, as well as most other controls, by using CreateWindowEx with the correct predefined system class name string
; Control Type String
;---------------------------------------------------
; Button Control 'Button'
; Edit Box 'Edit'
; Static Control 'Static'
; List Box 'Listbox'
; Scroll Bar 'Scrollbar'
; Combo Box 'ComboBox'
; Header Control 'SysHeader32'
; List View 'SysListView32'
; Tree View 'SysTreeView32'
; Hot Key 'msctls_hotkey32'
; Up-Down Control 'msctls_updown32'
; Animation Control 'SysAnimate32'
; Extended Combo Box 'ComboBoxEx32'
; Tab Control 'SysTabControl32'
; Month Calendar Control 'SysMonthCal32'
; Progress Bar 'msctls_progress32'
; ReBar Control 'ReBarWindow32'
; Tool Tip 'tooltips_class32'
; Track Bar 'msctls_trackbar32'
; Status Bar 'msctls_statusbar32'
; Tool Bar 'ToolbarWindow32'
; Date/Time Picker 'SysDateTimePick32'
; IP Address Control 'SysIPAddress32'
; Page Scroller Control 'SysPager'
; Drag List Message String 'commctrl_DragListMsg'
there are a few others
for any given class, there are special style constants that may be used
for buttons.....
http://msdn.microsoft.com/en-us/library/windows/desktop/bb775951%28v=vs.85%29.aspx (http://msdn.microsoft.com/en-us/library/windows/desktop/bb775951%28v=vs.85%29.aspx)
if you create a button this way, it may also be desirable to select a specific font
i generally use one of the stock fonts
http://msdn.microsoft.com/en-us/library/windows/desktop/dd144925%28v=vs.85%29.aspx (http://msdn.microsoft.com/en-us/library/windows/desktop/dd144925%28v=vs.85%29.aspx)
one advantage of doing it this way is you can specify the size and location in pixels :P