November 25, 2020, 05:13:06 AM

Author Topic: [bb] CreateWindow style flags helper by Dan [ 1+ years ago ]  (Read 630 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : CreateWindow style flags helper
Author : Dan
Posted : 1+ years ago

Description : I wrote a small tool program to help me with the B+ <a href="../bpdocs/commandefa4.html?name=CreateWindow&ref=gui_cat" target="_blank"> CreateWindow [/url] style flag numbers.

Code :
Code: BlitzBasic
  1. ;Gui written with GUIde 1.4 for BlitzPlus
  2.  
  3. ; Decls file needed:
  4. ;.lib "user32.dll"
  5. ;
  6. ;api_GetWindowLong%(hwnd%,nIndex%):"GetWindowLongA"
  7. ;api_SetWindowLong%(hwnd%,nIndex%,dwNewLong%):"SetWindowLongA"
  8. ;
  9. AppTitle "B+ Window Flag Editor"
  10.  
  11. Global EditWindow
  12. Global chbCheckBox0
  13. Global chbCheckBox1
  14. Global chbCheckBox2
  15. Global chbCheckBox3
  16. Global chbCheckBox4
  17. Global chbCheckBox5
  18. Global txtfield
  19. Global Result=0
  20. Global Oldkey$="0"
  21. Global Btnok
  22. Global btnCancel
  23.  
  24. ; Code for text only textfield used from seldon
  25. Const GWL_STYLE=-16
  26. Const ES_NUMBER=8192
  27.                
  28.  
  29. EditWindow=CreateWindow("Window Flag Editor",0,00,220,145,0,9)
  30.         chbCheckBox0=CreateButton("Titlebar",3,0,111,16,EditWindow,2)
  31.                 SetGadgetLayout chbCheckBox0,1,0,1,0
  32.         chbCheckBox1=CreateButton("Resizable",3,16,96,16,EditWindow,2)
  33.                 SetGadgetLayout chbCheckBox1,1,0,1,0
  34.         chbCheckBox2=CreateButton("+Menu",3,33,96,16,EditWindow,2)
  35.                 SetGadgetLayout chbCheckBox2,1,0,1,0
  36.         chbCheckBox3=CreateButton("+Status",3,50,96,16,EditWindow,2)
  37.                 SetGadgetLayout chbCheckBox3,1,0,1,0
  38.         chbCheckBox4=CreateButton("Its Tool window",3,67,96,16,EditWindow,2)
  39.                 SetGadgetLayout chbCheckBox4,1,0,1,0
  40.         chbCheckBox5=CreateButton("window shape is in Client coordinate",3,83,189,16,EditWindow,2)
  41.                 SetGadgetLayout chbCheckBox5,1,0,1,0
  42.         txtfield=CreateTextField(173,14,25,20,EditWindow)
  43.                 SetGadgetText txtfield,"0"
  44.         h_txtfield=QueryObject(txtfield,1)
  45.         api_SetWindowLong(h_txtfield,GWL_STYLE,api_GetWindowLong(h_txtfield,GWL_STYLE) Or ES_NUMBER)
  46.         CreateLabel("Flag Nr: (press enter to show)",121,17,40,50,EditWindow,0)
  47.                 SetGadgetLayout txtfield,1,0,1,0
  48.     Btnok=CreateButton("Ok",0,0,0,0,EditWindow,4)           ; Size and Position set to 0 to hide this button, Flag 4 = Default OK button
  49.                 SetGadgetLayout Btnok,1,0,1,0
  50.     btnCancel=CreateButton("Abbruch",0,0,0,0,EditWindow,5)  ; ; Size and Position set to 0 to hide this button, Flag 5 = Default Cancel button
  51.                 SetGadgetLayout btnCancel,1,0,1,0
  52.  
  53. ;-mainloop--------------------------------------------------------------
  54.  
  55. Repeat
  56.         id=WaitEvent()
  57.         Select id
  58.                 Case $401                                                                       ; interacted with gadget
  59.                         DoGadgetAction( EventSource() )
  60.                 Case $803                                                                       ; close gadget
  61.                         Exit
  62.     End Select
  63. Forever
  64.  
  65. End
  66.  
  67. ; * Mainloop end
  68.  
  69. Function SetCheckbox(nr)
  70. ; Checks or uncheck the Checkboxes according to the binary value of the number entered
  71. ; as only 6 states are allowed, only 6 binary places are needed
  72.     VBin$=Right$(Bin(nr),6)
  73.     SetButtonState  chbCheckBox0,Mid$(VBin$,6,1)
  74.     SetButtonState  chbCheckBox1,Mid$(VBin$,5,1)
  75.     SetButtonState  chbCheckBox2,Mid$(VBin$,4,1)
  76.     SetButtonState  chbCheckBox3,Mid$(VBin$,3,1)
  77.     SetButtonState  chbCheckBox4,Mid$(VBin$,2,1)
  78.     SetButtonState  chbCheckBox5,Mid$(VBin$,1,1)
  79.     CalcResult
  80.  
  81. End Function
  82.  
  83. Function CalcResult()
  84. ;Calculates the result variable from the checkbox states
  85. ; Decimal 1 = binary 00001  ; 16 = 010000 ; 32 = 100000
  86. Result=0  ; Resets the result variable
  87.           If ButtonState(chbCheckBox0) = 1    ; if the checkbox is checked add the decimal value to the result (see binary meanings of it)
  88.             Result=Result+1
  89.           Else
  90.             If Result=>1 Then Result=Result-1 ; if checkbox isnt checked, check if result is greater than the value  (to prevent going into minus)
  91.           EndIf
  92.           If ButtonState(chbCheckBox1) = 1
  93.             Result=Result+2
  94.           Else
  95.             If Result=>2 Then Result=Result-2
  96.           EndIf
  97.           If ButtonState(chbCheckBox2) = 1
  98.              Result=Result+4
  99.           Else
  100.            If Result=>4 Then Result=Result-4
  101.           EndIf
  102.           If ButtonState(chbCheckBox3) = 1
  103.             Result=Result+8
  104.           Else
  105.             If Result=>8 Then Result=Result-8
  106.           EndIf
  107.           If ButtonState(chbCheckBox4) = 1
  108.             Result=Result+16
  109.           Else
  110.             If Result=>16 Then Result=Result-16
  111.           EndIf
  112.           If ButtonState(chbCheckBox5) = 1
  113.             Result=Result+32
  114.           Else
  115.             If Result=>32 Then Result=Result-32
  116.           EndIf
  117.          
  118.           SetGadgetText txtfield,Result       ;Update the textfield
  119.           Oldkey$=Result                      ;and the Oldkey$ with the result
  120. End Function
  121. ;-gadget actions--------------------------------------------------------
  122.  
  123. Function DoGadgetAction( gadget )
  124.         Select gadget
  125.                 Case chbCheckBox0       ; user changed checkbox 1
  126.             CalcResult
  127.                 Case chbCheckBox1       ; user changed checkbox 2
  128.                     CalcResult
  129.                 Case chbCheckBox2       ; user changed checkbox 3
  130.                     CalcResult
  131.                 Case chbCheckBox3       ; user changed checkbox 4
  132.                     CalcResult
  133.                 Case chbCheckBox4       ; user changed checkbox 5
  134.                     CalcResult
  135.                 Case chbCheckBox5       ; user changed checkbox 6
  136.                     CalcResult
  137.         Case txtfield       ;something is written in the textbox
  138.                   If  Len(TextFieldText$(txtfield))<=2 ; if the text length is 2
  139.                         Oldkey$= TextFieldText$(txtfield) ; save the textfield value in oldkey$
  140.                       Else
  141.                         SetGadgetText txtfield,Oldkey$    ; if higher than 2 sets the textfield value to the oldkey$ variable and this prevents more chars to be written !
  142.                   EndIf
  143.          Case Btnok     ;Button Ok was pressed
  144.               SetCheckbox(Oldkey$)  ; Hidden OK button was pressed ! needed when the enter key is in the textfield
  145.               SetGadgetText txtfield,Oldkey$
  146.          Case btnCancel ;Button Cancel was pressed and the Textfield is active
  147.                 Oldkey$="0"
  148.                 SetCheckbox(Oldkey$)
  149.                 SetGadgetText txtfield,Oldkey$
  150.         End Select
  151.  
  152.         SetStatusText EditWindow,"Window flag number is:"+Result  ;Show the result in the toolbar
  153.        
  154. End Function


Comments :


virtlands(Posted 1+ years ago)

 Thanks, I tried it in BlitzPlus, and it works fine.I don't know what Window flags numbers are yet, but I'll figure it out eventually.


Dan(Posted 1+ years ago)

 Its for the B+ Gui Command:<a href="../bpdocs/commandefa4.html?name=CreateWindow&ref=gui_cat" target="_blank"> CreateWindow [/url] for the Style Flag.To easily get the right number if you need to change the window appearance.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal