News:

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

flat button

Started by Jango, March 18, 2012, 11:10:27 AM

Previous topic - Next topic

Jango

 i have seen in couple of application the flat button which are coded in masm.  i  heard about flatbutton.lib, but unable to find out over google.  may i know how to do this or if anyone got the lib please share. :8)

hutch--

You need to add the button style


BS_FLAT
Specifies that the button is two-dimensional; it does not use the default shading to create a 3-D image.


Reference here.

http://msdn.microsoft.com/en-us/library/windows/desktop/bb775951(v=vs.85).aspx
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Jango

Actually, I know about this style, but it does not give me the desired output.  I want the output like this one.


Gunner

Those are static controls and the frame is drawn with DrawFocusRect?
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

Jango

i checked the source of this one, it is like this

.386
.model flat, stdcall  ;32 bit memory model
option casemap :none  ;case sensitive



include windows.inc
include kernel32.inc
include user32.inc
include Comctl32.inc
include shell32.inc

includelib kernel32.lib
includelib user32.lib
includelib Comctl32.lib
includelib shell32.lib
includelib flatbutton.lib;-------------------------------> what is this?


DlgProc PROTO :HWND,:UINT,:WPARAM,:LPARAM
InitFlatButton  proto   stdcall :DWORD

.const

IDD_DIALOG1 equ 101
BotaoFlat01 equ 1003
BotaoFlat02 equ 1004
BotaoFlat03         equ 1005

;#########################################################################

.data?

hInstance dd ?

;#########################################################################

.data

Texto db 'Você clicou no Botão Flat02',0
Titulo db 'Exemplo de Botão Flat',0

.code

start:

invoke GetModuleHandle,NULL
mov hInstance,eax
    invoke InitFlatButton,hInstance ;---------------------------> might be this is doing something.
    ;invoke InitCommonControls
invoke DialogBoxParam,hInstance,IDD_DIALOG1,NULL,addr DlgProc,NULL
invoke ExitProcess,eax

DlgProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM

mov eax,uMsg

.if eax==WM_CLOSE
invoke EndDialog,hWin,0

.elseif eax==WM_COMMAND
movzx edx,word ptr wParam[2]
movzx eax,word ptr wParam[0]
.if edx == BN_CLICKED
.if eax == BotaoFlat02
invoke MessageBox,hWin,addr Texto,addr Titulo,MB_ICONINFORMATION



.endif
.endif
.endif

.if
xor eax,eax ;False
ret

.endif
xor eax,eax
inc eax ;True
ret


DlgProc endp

end start


If that is static one, so why Button click msg?  my bad luck is this, that lib is not with it so no idea how this is going on.

Gunner

You could try the XXControls library, not sure of the original link but have it here:
http://www.gunnerinc.com/files/masm32stuff/XXControls.zip
http://www.gunnerinc.com/files/masm32stuff/XXControlsTXTeng.zip

They should help do what you want
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

ragdog

Hi

Here is a other example but it easy to use it with DrawFocusRect

http://www.aogosoft.com/Periodical/20071116/FlatButton.rar

dedndave

XxControls does give you a flat button - but that is not the code you have
the code you show may be related to FlatButton.ocx - an activeX control

both are overkill - lol
it is pretty easy to do like Rob suggested using DrawFocusRect
there are also a few functions in the masm32 library, which i have not played with
FrameCtrl, FrameGrp, FrameWindow

donkey

#8
Probably just a user defined control. This should do it:

InitFlatButtons FRAME
LOCAL cc_wcx :WNDCLASSEX

invoke RtlZeroMemory,offset cc_wcx,SIZEOF WNDCLASSEX
invoke GetModuleHandle,0
mov D[cc_wcx.hInstance],eax
mov D[cc_wcx.cbSize],SIZEOF WNDCLASSEX
mov D[cc_wcx.lpszClassName],OFFSET UDC_Class
mov D[cc_wcx.cbClsExtra],0
mov D[cc_wcx.style],0
mov D[cc_wcx.cbWndExtra],8
mov D[cc_wcx.lpfnWndProc],OFFSET FlatBtnproc
mov D[cc_wcx.hbrBackground],COLOR_BTNFACE+1
invoke RegisterClassEx,ADDR cc_wcx

ret

UDC_Class: db "FLTBTNCLASS",0
ENDF

FlatBtnproc FRAME hwnd,uMsg,wParam,lParam
uses ebx
LOCAL ps:PAINTSTRUCT
LOCAL rect:RECT
LOCAL BtnText[256]:%TCHAR
LOCAL TE:TRACKMOUSEEVENT

.WM_CREATE
cmp D[uMsg],WM_CREATE
jne >>.WM_SETFONT
invoke GetStockObject,DEFAULT_GUI_FONT
invoke SetWindowLong,[hwnd],4,eax
invoke SetWindowLong,[hwnd],0,FALSE
jmp >>.DEFPROC

.WM_SETFONT
cmp D[uMsg],WM_SETFONT
jne >>.WM_LBUTTONUP
invoke SetWindowLong,[hwnd],4,[wParam]
cmp D[lParam],TRUE
jne >
invoke InvalidateRect,[hwnd],NULL,TRUE
:
xor eax,eax
ret

.WM_LBUTTONUP
cmp D[uMsg],WM_LBUTTONUP
jne >>.WM_MOUSEMOVE
invoke GetDlgCtrlID,[hwnd]
mov ebx,eax
invoke GetParent,[hwnd]
invoke PostMessage,eax,WM_COMMAND,ebx,[hwnd]
jmp >>.DEFPROC

.WM_MOUSEMOVE
cmp D[uMsg],WM_MOUSEMOVE
jne >>.WM_MOUSELEAVE
invoke SetWindowLong,[hwnd],0,TRUE
cmp eax,TRUE
je >>.DEFPROC
invoke InvalidateRect,[hwnd],NULL,TRUE
mov D[TE.cbSize],SIZEOF TRACKMOUSEEVENT
mov D[TE.dwFlags],TME_LEAVE
mov eax,[hwnd]
mov [TE.hwndTrack],eax
mov D[TE.dwHoverTime],NULL
invoke TrackMouseEvent,offset TE
jmp >>.DEFPROC

.WM_MOUSELEAVE
cmp D[uMsg],WM_MOUSELEAVE
jne >>.WM_PAINT
invoke SetWindowLong,[hwnd],0,FALSE
invoke InvalidateRect,[hwnd],NULL,TRUE
jmp >>.DEFPROC

.WM_PAINT
cmp D[uMsg],WM_PAINT
jne >>.DEFPROC
invoke BeginPaint,[hwnd],offset ps
invoke GetWindowLong,[hwnd],4
invoke SelectObject,[ps.hdc],eax
push eax
invoke GetClientRect,[hwnd],offset rect
invoke GetWindowText,[hwnd],offset BtnText,256
invoke SetTextColor,[ps.hdc],0
invoke SetBkMode,[ps.hdc],TRANSPARENT
invoke DrawText,[ps.hdc],addr BtnText,-1,offset rect,DT_CENTER + DT_VCENTER + DT_SINGLELINE
invoke GetWindowLong,[hwnd],0
cmp eax,TRUE
jne >>
invoke DrawFocusRect,[ps.hdc],offset rect
:
pop eax
invoke SelectObject,[ps.hdc],eax
invoke EndPaint,[hwnd],offset ps
xor eax,eax
inc eax
ret

.DEFPROC
invoke DefWindowProc,[hwnd],[uMsg],[wParam],[lParam]
ret
endf


Call InitFlatButtons at the start of your application and create the buttons with the class name "FLTBTNCLASS". A normal button WM_COMMAND message will be sent when you click on the button (actually when you release the mouse button as per the Windows ABI). The buttons do not move or have any borders at all.

Edgar

EDIT: Added the ability to set the button font.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable