View difference between Paste ID: vLvLL7rQ and H5E4uR8K
SHOW: | | - or go back to the newest paste.
1
#define fbc -s console
2
'default.rc
3
4
#include once "windows.bi"
5
#include once "win\commctrl.bi"
6
#include once "crt.bi"
7
8
'*************** Enumerating our control id's ***********
9
enum WindowControls
10
  wcMain
11
  wcButton  
12
  wcEdit
13
  wcLast
14
end enum
15
16
dim shared as hwnd CTL(wcLast)       'controls
17
dim shared as hinstance APPINSTANCE  'instance
18
dim shared as hfont MyFont           'fonts
19
dim shared as string sAppName        'AppName (window title 'prefix')
20
21
declare sub WinMain()
22
23
sAppName = "GUI Example"
24
InitCommonControls()
25
APPINSTANCE = GetModuleHandle(null)
26
WinMain() '<- main function
27
28
' *************** Procedure Function ****************
29
function WndProc ( hWnd as HWND, message as UINT, wParam as WPARAM, lParam as LPARAM ) as LRESULT
30
  
31
  select case( message )
32
  case WM_CREATE 'Window was created
33
    if CTL(wcMain) then return 0
34
    CTL(wcMain) = hwnd
35
36-
    scope 'Calculate Client Area Size
36+
37-
      dim as rect RcWnd=any,RcCli=any,RcDesk=any
37+
38-
      GetClientRect(hWnd,@RcCli)
38+
39-
      GetClientRect(GetDesktopWindow(),@RcDesk)
39+
40-
      GetWindowRect(hWnd,@RcWnd)
40+
41-
      'Window Rect is in SCREEN coordinate.... make right/bottom become WID/HEI
41+
42-
      with RcWnd
42+
43-
        .right  -= .left : .bottom -= .top        
43+
44-
        .right += (.right-RcCli.right)  'add difference cli/wnd 
44+
45-
        .bottom += (.bottom-RcCli.bottom) 'add difference cli/wnd 
45+
46-
        var iCenterX = (RcDesk.right-.right)\2
46+
47-
        var iCenterY = (RcDesk.bottom-.bottom)\2        
47+
48-
        SetWindowPos(hwnd,null,iCenterX,iCenterY,.right,.bottom,SWP_NOZORDER)
48+
49-
      end with
49+
50-
    end scope      
50+
51
    CreateControl( wcButton , null , "button" , "Click"       , cStyle      , 10 , 10 , 80 , 24   )        
52
    CreateControl( wcEdit   , cBrd , "edit"   , "Hello World " , cTxtStyle  , 10 , 44 , 320 , 240 )
53
    
54
    ' **** Creating a font ****
55
    var hDC = GetDC(hWnd) 'can be used for other stuff that requires a temporary DC
56
    var nHeight = -MulDiv(12, GetDeviceCaps(hDC, LOGPIXELSY), 72) 'calculate size matching DPI
57
    
58
    MyFont = CreateFont(nHeight,0,0,0,FW_NORMAL,0,0,0,DEFAULT_CHARSET,0,0,DRAFT_QUALITY or ANTIALIASED_QUALITY,0,"Verdana")
59
    ' **** Setting this font for all controls ****
60
    for CNT as integer = wcMain to wcLast-1
61
      SendMessage(CTL(CNT),WM_SETFONT,cast(wparam,MyFont),true)      
62
    next CNT
63
    SendMessage(CTL(wcEdit),EM_SETLIMITTEXT,0,0)
64
    
65
    ReleaseDC(hWnd,hDC)    
66
    
67
    SetFocus(hwnd)
68
    
69
  case WM_COMMAND 'Event happened to a control (child window)
70
    
71
    select case hiword(wparam)        
72
    case EN_CHANGE
73
      print SendMessage(CTL(wcEdit),WM_GETTEXTLENGTH,0,0)
74
    case BN_CLICKED 'button click
75
      select case lparam
76
      case CTL(wcButton)      
77
        Messagebox( hwnd , "Bye" , "Bye" , MB_ICONINFORMATION )
78
        PostQuitMessage(0)
79
      end select
80
    end select
81
  
82
  case WM_DESTROY 'Windows was closed/destroyed
83
    PostQuitMessage(0) ' to quit
84
    return 0 
85
  end select
86
  
87
  ' *** if program reach here default predefined action will happen ***
88
  return DefWindowProc( hWnd, message, wParam, lParam )
89
    
90
end function
91
92
' *********************************************************************
93
' *********************** SETUP MAIN WINDOW ***************************
94
' ******************* This code can be ignored ************************
95
' *********************************************************************
96
97
sub WinMain ()
98
  
99
  dim wMsg as MSG
100
  dim wcls as WNDCLASS
101
  dim as HWND hWnd  
102
    
103
  '' Setup window class  
104
    
105
  with wcls
106
    .style         = CS_HREDRAW or CS_VREDRAW
107
    .lpfnWndProc   = @WndProc
108
    .cbClsExtra    = 0
109
    .cbWndExtra    = 0
110
    .hInstance     = APPINSTANCE
111
    .hIcon         = LoadIcon( APPINSTANCE, "FB_PROGRAM_ICON" )
112
    .hCursor       = LoadCursor( NULL, IDC_ARROW )    
113
    .hbrBackground = GetSysColorBrush( COLOR_BTNFACE )
114
    .lpszMenuName  = NULL
115
    .lpszClassName = strptr( sAppName )
116
  end with
117
    
118
  '' Register the window class     
119
  if( RegisterClass( @wcls ) = FALSE ) then
120
    MessageBox( null, "Failed to register wcls!", sAppName, MB_ICONINFORMATION )
121
    exit sub
122
  end if
123
    
124
  '' Create the window and show it  
125
  const cStyleEx = 0 'WS_EX_COMPOSITED or WS_EX_LAYERED
126
  const cStyle   = WS_VISIBLE or WS_TILEDWINDOW or WS_CLIPCHILDREN
127
  dim as RECT tWndRc = (0,0,640,480)
128
  AdjustWindowRectEx( @tWndRc , cStyle , FALSE , cStyleEx )  
129
  hWnd = CreateWindowEx(cStyleEx,sAppName,sAppName,cStyle, _
130
  200,200,tWndRc.right-tWndRc.left,tWndRc.bottom-tWndRc.top,null,null,APPINSTANCE,0)
131
  
132
  '' Process windows messages
133
  ' *** all messages(events) will be read converted/dispatched here ***
134
  UpdateWindow( hWnd )
135
  
136
  while( GetMessage( @wMsg, NULL, 0, 0 ) <> FALSE )    
137
    'if IsDialogMessage( hWnd ,@wMsg ) then continue while
138
    TranslateMessage( @wMsg )
139
    DispatchMessage( @wMsg )    
140-
  '' Create the window and show it
140+
141-
  'WS_EX_COMPOSITED or WS_EX_LAYERED
141+
142-
  hWnd = CreateWindowEx(0,sAppName,sAppName, WS_VISIBLE or WS_TILEDWINDOW or WS_CLIPCHILDREN, _
142+
143-
  200,200,640,480,null,null,APPINSTANCE,0)  
143+
144