With the help form kev in this topic: http://www.blitzbasic.com/Community/posts.php?topic=50175 I 've gotten some windows controls on a BlitzMax window.
This thing runs in debugmode, but exits silently in Non debugmode. Can somebody spot an error or two ?
[EDIT]: Try writing something in the textboxes to make it exit.
And yes, it's messy, I know... :)
This thing runs in debugmode, but exits silently in Non debugmode. Can somebody spot an error or two ?
[EDIT]: Try writing something in the textboxes to make it exit.
And yes, it's messy, I know... :)
Strict Import "-luser32" 'Import "-lkernel32" Extern Function GetSysColorBrush:Int(nIndex:Int) = "GetSysColorBrush@4" Function SendMessage:Int(hWnd:Int,MSG:Int,wParam:Int,lParam:Int) = "SendMessageA@16" Function CreateFontA:Int(nHeight,nWidth,nEscapement,nOrientation ,fnWeight, fdwItalic,dwUnderline , fdwStrikeOut,fdwCharSet, fdwOutputPrecision , fdwClipPrecision,fdwQuality, fdwPitchAndFamily, lpszFace:Byte Ptr) = "CreateFontA@56" Function GetLastError:Int() = "GetLastError@0" Function GetWindowDC:Int(hWnd) = "GetWindowDC@4" Function SelectObject:Int(hWnd,obj) = "SelectObject@8" Function FindWindow(lpClassName:Byte Ptr, lpWindowName:Byte Ptr) = "FindWindowA@8" Function GetWindowLong :Int(hWnd ,nIndex)= "GetWindowLongA@8" Function SetWindowLong :Int(hWnd ,nIndex,lNewLong )= "SetWindowLongA@12" Function SetWindowLongPtr :Int(hWnd ,nIndex,lNewLong:Byte Ptr )= "SetWindowLongA@12" Function CallWindowProc:Int(lpPrevWndFunc,hWnd,uMsg,wParam,lParam) = "CallWindowProcA@20" Function GetSysColor:Int(index) = "GetSysColor@4" End Extern Const BN_CLICKED = 0 Const EN_CHANGE = $300 Const ES_NUMBER = $2000 Const COLOR_BTNFACE = 15 Const WS_CAPTION = $C00000 Const WS_SYSMENU = $80000 Const WS_VISIBLE = $10000000 Const WS_MINIMIZEBOX = $20000 Const WS_MAXIMIZEBOX = $10000 Const WS_CHILD = $40000000 'Const WM_DESTROY = 2 'Const WM_GETTEXT = $D 'Const WM_SETFONT = $30 'Const WM_KEYDOWN = $100 'Const WM_COMMAND = $111 Global gApptitle$ = "My window" AppTitle = gApptitle Graphics 600,400,0,0 AppTitle = gApptitle Global window = FindWindow("BBDX7Device Window Class",gApptitle ) DebugLog window Const GWL_STYLE = -16 Const WS_CLIPCHILDREN = $2000000 Local winstyle = GetWindowLong(window , GWL_STYLE) SetWindowLong(window , GWL_STYLE, WS_CLIPCHILDREN | winstyle ) 'change the style so that controls are not overdrawn Global lpParamADDR:Byte Ptr 'Local window = CreateWindowExA( 0,Byte Ptr classname$,Byte Ptr windowTitle$,WS_CAPTION | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU | WS_VISIBLE,100,100,400,350,0,0,GetModuleHandleA(0),lpParamADDR ) Global btnOk = CreateWindowExA( 0 ,Byte Ptr "BUTTON",Byte Ptr "Ok",WS_CHILD | WS_VISIBLE,250,250,100,20,window ,0,GetModuleHandleA(0),lpParamADDR) Global btnCancel = CreateWindowExA( 0 ,Byte Ptr "BUTTON",Byte Ptr "Cancel",WS_CHILD | WS_VISIBLE,250,250+24,100,20,window ,0,GetModuleHandleA(0),lpParamADDR) Global lblHeadline = CreateWindowExA( 0 ,Byte Ptr "STATIC",Byte Ptr "I am the label, I am spanning the top",WS_CHILD | WS_VISIBLE,10,10,300,20,window ,0,GetModuleHandleA(0),lpParamADDR) Const WS_BORDER = $800000 Const WS_THICKFRAME = $40000 Const WS_DLGFRAME = $400000 Global box = CreateWindowExA( 0 ,Byte Ptr "EDIT",Byte Ptr "Only numbers here!",WS_CHILD | WS_VISIBLE | WS_BORDER | ES_NUMBER,10,10+40,300,20,window ,0,GetModuleHandleA(0),lpParamADDR) Global box2 = CreateWindowExA( 0 ,Byte Ptr "EDIT",Byte Ptr "I am box, I am",WS_CHILD | WS_VISIBLE | WS_BORDER ,10,10+40+40,300,20,window ,0,GetModuleHandleA(0),lpParamADDR) 'Global myfont = CreateFontA(-16,12,0,0 ,400, 0,0 , 0,0, 4 , 0,0, 0, Byte Ptr "Arial" + Chr(0) ) Global myfont = GetStockObject(12) 'ANSI_VAR_FONT SendMessage lblHeadline ,WM_SETFONT,myfont ,1 SendMessage btnOk ,WM_SETFONT,myfont ,1 SendMessage btnCancel ,WM_SETFONT,myfont ,1 SendMessage box ,WM_SETFONT,myfont ,1 SendMessage box2 ,WM_SETFONT,myfont ,1 Global textBank:TBank = CreateBank(300) Global thetext:String Const GWL_WNDPROC = -4 Global backcolor backcolor = GetSysColor(COLOR_BTNFACE ) Local r = backcolor & $FF Local g = (backcolor & $FF00) Shr 8 Local b = (backcolor & $FF0000) Shr 16 SetClsColor r,g,b Cls Cls DebugLog backcolor Global textbuffer$ Global oldproc= SetWindowLongPtr (window , GWL_WNDPROC, WinProc) 'DebugLog "GetLastError() " + GetLastError() Print "oldproc " + oldproc While Not KeyHit(key_escape) 'Repeat SetColor Rnd(255) , Rnd(255) ,Rnd(255) DrawLine Rand(1000),Rand(1000),Rand(1000),Rand(1000) Flip Wend DebugLog "here it ends" End ' Function WinProc:Int(hWnd:Int,Msg:Int,wParam:Int,lParam:Int) Select Msg Case WM_CLOSE Case WM_DESTROY Print "old proc restored" SetWindowLong(hwnd,GWL_WNDPROC, oldproc) Case WM_KEYDOWN 'DebugLog "Keydown " + wParam + " " + lParam DebugLog "you pressed " + Chr$(wParam) Select wParam Case 27 ' ESC ' SendMessage hWnd,WM_CLOSE,0,0 End Select Case WM_CREATE DebugLog "WM_CREATE" Case WM_INITDIALOG DebugLog "WM_INITDIALOG" Case WM_COMMAND DebugLog "command " + lParam Select lParam Case btnOk If HIWORD(wparam)= BN_CLICKED ' notify does Not work in non debug mode ' well it works, but you can't click it ' ' Notify "You clicked Ok" EndIf Case btnCancel If HIWORD(wparam)= BN_CLICKED ' notify does Not work in non debug mode ' well it works, but you can't click it ' Notify "You clicked cancel" EndIf Case box , box2 If HIWORD(wparam)= EN_CHANGE DebugLog "box " + lParam SendMessage lParam ,WM_GETTEXT,BankSize(textbank)-2,Int(BankBuf(textbank)) thetext$ = String.FromCString(BankBuf(textbank)) DebugLog thetext EndIf End Select Default 'DebugLog Msg End Select If oldproc<>0 Then Return CallWindowProc(oldproc, hwnd, Msg, Wparam, Lparam) End Function Function LOWORD(value) Return value And $FFFF End Function Function HIWORD(value) Return (value Shr 16) End Function