.686
.MODEL flat,stdcall
OPTION CASEMAP:NONE

;-------------------------------------------------------------------

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\comdlg32.inc
include \masm32\include\gdi32.inc
include \masm32\include\Comctl32.inc
include \masm32\include\shell32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\comdlg32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\Comctl32.lib
includelib \masm32\lib\shell32.lib

;-------------------------------------------------------------------

include \masm32\include\masm32.inc
includeLib \masm32\lib\masm32.lib

include XXControls.inc
includeLib XXControls.lib

;-------------------------------------------------------------------

AboutProc 			PROTO :HWND, :UINT, :WPARAM, :LPARAM
CtrlInstall			PROTO :HINSTANCE

;-------------------------------------------------------------------

include XXAbout.inc

include \masm32\MACROS\Macros.asm

      ;=============
      ; Local macros
      ;=============

      m2m MACRO M1, M2
        push M2
        pop  M1
      ENDM

      return MACRO arg
        mov eax, arg
        ret
      ENDM

$invoke MACRO Fun:REQ, A:VARARG
  IFB <A>
    invoke Fun
  else
    invoke Fun, A
  endif
  exitm <eax>
		ENDM

LOWORD MACRO bigword    ; Возврвщает младщее слово  
   mov  eax,bigword
   and  eax,0FFFFh     ;; Set to low word 
ENDM


HIWORD macro bigword    ; Возврвщает старшее слово 
   mov  eax,bigword
   shr  eax,16         ;; Get high word
endm

IF_MSG macro WMsg:REQ, DoJmp:REQ
   cmp uMsg, WMsg
   jz  DoJmp
endm

WM_CASE macro reg,msgs
   irp msg,<msgs>
      cmp reg,WM_&msg
      je @@&msg
   endm
endm

.data
XXCtrl  	db			"XXControls",0
;rever		db			"v.0.0.2.1",0
;lgFntNts    LOGFONTA    <-20, 12, 0, 0, FW_MEDIUM, 0, 0, 0, ANSI_CHARSET, OUT_RASTER_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, FF_MODERN, "Courier New">
lgFntRE     LOGFONTA    <-40, 24, 0, 0, FW_NORMAL, TRUE, 0, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, FF_MODERN, "Courier New">
lgFnt       LOGFONTA    <-13, 7, 0, 0, FW_THIN	, 0, 0, 0, ANSI_CHARSET, OUT_RASTER_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, FF_MODERN, "Courier New">
lgFntFocus  LOGFONTA    <-13, 7, 0, 0, FW_MEDIUM, 0, TRUE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, FF_MODERN, "Courier New">
email_amdtm db          "mailto:<inprj21@mail.ru>",0
email_chib  db          "mailto:<XXControls@bk.ru>",0

.data?
hWinMain	HWND		?
hInst		HINSTANCE	?
hFntRE		HFONT		?
;hFntNts	HFONT		?
hFnt        HFONT ?
hFntFocus   HFONT ?
hBmpNoiseNormal     HBITMAP ?
hBmpNoiseHover      HBITMAP ?
hBmpNoise      HBITMAP ?

.const
IDD_ABOUT	equ			800

IDC_LINK    equ 1010
IDC_LINK1   equ 1012

IDW_HOVER   equ 200
IDC_OK      equ 1200
ID_CUR1     equ 210
.code

;===========================================================================;
; Name:		DllEntry                                                ;
; Function:	Performs an undo action (if any)                        ;
;                                                                           ;
; Params:	lpEditData = Address of the RS Edit control's data structure      ;
;                                                                           ;
; Returns:  Nothing                                                         ;
;===========================================================================;

DllEntry proc hInstance:HINSTANCE, reason:DWORD, reserved1:DWORD

LOCAl iccex	:INITCOMMONCONTROLSEX

    .if reason==DLL_PROCESS_ATTACH                 ; DLL загружена
    
    	mov	iccex.dwSize,sizeof(INITCOMMONCONTROLSEX)
	    mov	iccex.dwICC,ICC_BAR_CLASSES or ICC_WIN95_CLASSES
	    invoke InitCommonControlsEx, ADDR iccex
	        
		m2m hInst, hInstance
    .elseif reason==DLL_PROCESS_DETACH             ; DLL выгружаеться


    .elseif reason==DLL_THREAD_ATTACH

    .else        ; DLL_THREAD_DETACH

    .endif
    mov  eax,TRUE
    ret
DllEntry endp

 ; --------------------------------------
 ; Create main window for about
 ; --------------------------------------

CreateXXAboutDlg proc hWin :HWND

    m2m hWinMain, hWin
    invoke DialogBoxParamA,hInst,IDD_ABOUT,hWin,ADDR AboutProc, NULL

    ret 
CreateXXAboutDlg endp

 ; =======================================================================
 ;  Процедура окна о программе
 ; =======================================================================

AboutProc proc hWin :DWORD, uMsg :DWORD, wParam :DWORD, lParam :DWORD

    LOCAL ps    :PAINTSTRUCT
    LOCAL Rct   :RECT
    LOCAL rect  :RECT
   LOCAL BtnStruct :XXBUTTON
    LOCAL hBtn      :HWND
;    LOCAL OldClr:COLORREF
    LOCAL OldFnt:HFONT
    LOCAL StrSize     :SIZEL
;    LOLOR OldBkM:DWORD  
    
   .if uMsg == WM_COMMAND
		mov	eax,wParam
		mov	edx,eax
		shr	edx,16
		
		.if	dx == BN_CLICKED
    
            .if eax == IDC_OK
            

e_t:    
               invoke DeleteObject,hBmpNoiseNormal
               invoke DeleteObject,hBmpNoiseHover
               invoke DeleteObject, hFnt
               invoke DeleteObject, hFntFocus
;    	       invoke DeleteObject, hFntNts
        	   invoke DeleteObject, hFntRE
        
               invoke EndDialog, hWin, 0
               return TRUE
               
            .elseif eax == IDC_LINK  ; to Chib e-mail
    		      invoke ShellExecute, 0, 0, ADDR email_chib, 0, 0, SW_SHOWNORMAL
    		.elseif eax == IDC_LINK1  ; to amdtm e-mail
    		      invoke ShellExecute, 0, 0, ADDR email_amdtm, 0, 0, SW_SHOWNORMAL
    		 
            .endif
            
        .endif 
        
   .elseif uMsg == WM_CLOSE 
   
        jmp e_t
   
   .elseif uMsg == WM_INITDIALOG
   
;   	  mov hFntNts, $invoke ( CreateFontIndirect, ADDR lgFntNts )
   	  mov hFntRE, $invoke ( CreateFontIndirect, ADDR lgFntRE )
      
;========================Link==========================================
		mov BtnStruct.hIcon_normal, NULL
		mov BtnStruct.hIcon_hover, NULL
		mov BtnStruct.m_border, FALSE
		
		invoke CreateFontIndirect, ADDR lgFnt
		mov hFnt, eax
		mov BtnStruct.hFont_normal, eax
		invoke CreateFontIndirect, ADDR lgFntFocus
   	    mov hFntFocus, eax
		mov BtnStruct.hFont_hover, eax
		
		invoke LoadCursor, NULL, IDC_HAND
		mov BtnStruct.hCursor_hover, eax		
				
		invoke FindResource, hInst, IDW_HOVER, RT_RCDATA
		invoke LoadResource, hInst, eax
		
		mov BtnStruct.Sound_hover, eax
		
		RGB 0, 0, 255
		mov BtnStruct.hover_clr, eax
		RGB 128, 128, 0
		mov BtnStruct.push_clr, eax		
		RGB 128, 0, 96
		mov BtnStruct.normal_clr, eax
				
		mov hBtn, $invoke ( GetDlgItem, hWin, IDC_LINK )
		invoke RedrawButton, hBtn, ADDR BtnStruct      

		mov hBtn, $invoke ( GetDlgItem, hWin, IDC_LINK1 )
		invoke RedrawButton, hBtn, ADDR BtnStruct   

;========================Noise==========================================
@@:      
        invoke memfill, ADDR BtnStruct, sizeof(XXBUTTON), 0 ; BtnStruct set null

		mov BtnStruct.m_border, TRUE
				
		mov hBtn, $invoke ( GetDlgItem, hWin, IDC_OK )
		invoke GetWindowRect, hBtn, ADDR Rct
        invoke CreateFillBmp, FILL_NOISE, ADDR Rct, 12, 25, 0, 0            
        mov BtnStruct.hBitmap_normal, eax
        mov hBmpNoiseNormal, eax
        mov BtnStruct.hBitmap_hover, edx
        mov hBmpNoiseHover, edx
		
		invoke RedrawButton, hBtn, ADDR BtnStruct      
      
      
         
        ; frame
        invoke GetClientRect,hWin,ADDR Rct
        invoke CopyRect, ADDR rect, ADDR Rct
        m2m rect.bottom, Rct.top
        add rect.bottom, 70
        add rect.left, 2
        sub rect.right, 2
      
        invoke CreateFillBmp, FILL_NOISE, ADDR rect, 30, 0, 0, 0            
        mov hBmpNoise, eax
      
      
    .elseif uMsg == WM_SYSCOLORCHANGE
        
        invoke DeleteObject,hBmpNoiseNormal
        invoke DeleteObject,hBmpNoiseHover
        invoke DeleteObject,hBmpNoise
        
        invoke CreateFillBmp, FILL_NOISE, ADDR rect, 30, 0, 0, 0            
        mov hBmpNoise, eax     
        jmp @b
        
   .elseif uMsg == WM_PAINT
   
      invoke BeginPaint,hWin,ADDR ps
      invoke GetClientRect,hWin,ADDR Rct
      invoke DrawEdge,ps.hdc,ADDR Rct,EDGE_ETCHED,BF_RECT
      
      ; frame
      invoke CopyRect, ADDR rect, ADDR Rct
      m2m rect.bottom, Rct.top
      add rect.bottom, 70
      add rect.left, 2
      sub rect.right, 2
      
      invoke DrawDDB, ps.hdc, ADDR rect, hBmpNoise 
      
      ; text      
      invoke SetBkMode, ps.hdc, TRANSPARENT      
      
      invoke GetSysColor, COLOR_GRAYTEXT
      invoke SetTextColor, ps.hdc, eax
      invoke SelectObject, ps.hdc, hFntRE
      invoke szLen, ADDR XXCtrl
      invoke TextOut, ps.hdc, 20, 7, ADDR XXCtrl, eax
      
      invoke EndPaint,hWin,ADDR ps
                      
   .endif
    
    xor eax, eax    
    ret
    
AboutProc endp

end DllEntry