DataWindow Column Width
Example Code
str_size from structure
1 2 3 4 |
global type str_size from structure ulong cx ulong cy end type |
w_main from window
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
forward global type w_main from window end type type cb_library from commandbutton within w_main end type type cb_1 from commandbutton within w_main end type type dw_columns from datawindow within w_main end type type dw_datawindows from datawindow within w_main end type type st_text from statictext within w_main end type end forward global type w_main from window integer width = 2158 integer height = 1840 boolean titlebar = true string title = "DataWindow Column Width Checker" boolean controlmenu = true boolean minbox = true boolean maxbox = true boolean resizable = true long backcolor = 67108864 string icon = "AppIcon!" boolean center = true cb_library cb_library cb_1 cb_1 dw_columns dw_columns dw_datawindows dw_datawindows st_text st_text end type global w_main w_main type prototypes Protected: Function ULong GetDC(ULong hWnd) Library "USER32.DLL" Function Long ReleaseDC(ULong hWnd, ULong hdcr) Library "USER32.DLL" Function ULong SelectObject(ULong hdc, ULong hWnd) Library "GDI32.DLL" Function Boolean GetTextExtentPoint32A(ULong hdcr, String lpString, Long nCount, Ref str_size size) Library "GDI32.DLL" Alias For "GetTextExtentPoint32A;Ansi" end prototypes type variables protected: string is_libraryname end variables forward prototypes protected function integer of_getdatawindows () protected function integer of_getcolumns (string as_datawindowname) protected function integer of_getcolumnwidth (string as_fontname, integer ai_len, integer ai_fontsize, integer ai_weight, boolean ab_italic, boolean ab_underline) end prototypes protected function integer of_getdatawindows ();//==================================================================== // Function: w_main.of_getdatawindows() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: //-------------------------------------------------------------------- // Returns: integer //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2023/03/12 //-------------------------------------------------------------------- // Usage: w_main.of_getdatawindows ( ) //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== String ls_filename, ls_datawindows If GetFileOpenName ( "Select a PBL", is_libraryname, ls_filename, 'PBL', 'PowerBuilder Library (*.pbl),*.pbl;PowerBuilder Dynamic Library (*.pbd),*.pbd;All files (*.*),*.*' ) < 1 Then Return -1 dw_datawindows.Reset() dw_columns.Reset() ls_datawindows = LibraryDirectory ( is_libraryname, DirDataWindow! ) dw_datawindows.ImportString ( ls_datawindows ) Return 1 end function protected function integer of_getcolumns (string as_datawindowname);//==================================================================== // Function: w_main.of_getcolumns() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // string as_datawindowname //-------------------------------------------------------------------- // Returns: integer //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2023/03/12 //-------------------------------------------------------------------- // Usage: w_main.of_getcolumns ( string as_datawindowname ) //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== Boolean lb_underline, lb_italic Integer li_index, li_count, li_fontsize, li_fontweight Integer li_actualwidth, li_desiredwidth, li_row, li_len String ls_syntax, ls_errors, ls_columnname, ls_fontname, ls_datatype datastore lds_temp ls_syntax = LibraryExport ( is_libraryname, as_datawindowname, ExportDataWindow! ) dw_columns.Reset() lds_temp = Create datastore lds_temp.Create ( ls_syntax, ls_errors ) If lds_temp.Object.DataWindow.Units <> '0' Then MessageBox ( "Warning", "This utility only works for DataWindows that are stored in PBU Units" ) End If li_count = Integer ( lds_temp.Object.DataWindow.Column.Count ) For li_index = 1 To li_count //Get column info ls_columnname = lds_temp.Describe ( '#' + String ( li_index ) + '.name' ) ls_fontname = lds_temp.Describe ( '#' + String ( li_index ) + '.Font.Face' ) If ls_fontname = '!' Then Continue //Not shown on datawindow ls_datatype = lds_temp.Describe ( '#' + String ( li_index ) + '.Coltype' ) If Left ( Lower ( ls_datatype ), 4 ) <> 'char' Then Continue //Not a string datatype li_len = Integer ( Mid ( ls_datatype, 6, Len ( ls_datatype ) - 6 ) ) li_fontsize = Integer ( lds_temp.Describe ( '#' + String ( li_index ) + '.Font.Height' ) ) li_fontweight = Integer ( lds_temp.Describe ( '#' + String ( li_index ) + '.Font.Weight' ) ) lb_italic = ( Lower ( lds_temp.Describe ( '#' + String ( li_index ) + '.Font.Italic' ) ) = 'yes' ) lb_underline = ( Lower ( lds_temp.Describe ( '#' + String ( li_index ) + '.Font.Underline' ) ) = 'yes' ) li_actualwidth = Integer ( lds_temp.Describe ( '#' + String ( li_index ) + '.Width' ) ) li_desiredwidth = PixelsToUnits ( of_getcolumnwidth( ls_fontname, li_len, li_fontsize, li_fontweight, lb_italic, lb_underline ), XPixelsToUnits! ) //Add it to the datawindow li_row = dw_columns.InsertRow ( 0 ) dw_columns.Object.columnname[li_row] = ls_columnname dw_columns.Object.actualwidth[li_row] = li_actualwidth dw_columns.Object.desiredwidth[li_row] = li_desiredwidth Next Destroy lds_temp Return 1 end function protected function integer of_getcolumnwidth (string as_fontname, integer ai_len, integer ai_fontsize, integer ai_weight, boolean ab_italic, boolean ab_underline);//==================================================================== // Function: w_main.of_getcolumnwidth() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // string as_fontname // integer ai_len // integer ai_fontsize // integer ai_weight // boolean ab_italic // boolean ab_underline //-------------------------------------------------------------------- // Returns: integer //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2023/03/12 //-------------------------------------------------------------------- // Usage: w_main.of_getcolumnwidth ( string as_fontname, integer ai_len, integer ai_fontsize, integer ai_weight, boolean ab_italic, boolean ab_underline ) //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== Constant Integer WM_GETFONT = 49 // hex 0x0031 String ls_text ULong lul_Hdc, lul_Handle, lul_hFont str_size lstr_Size st_text.FaceName = as_fontname st_text.TextSize = -ai_FontSize st_text.Weight = ai_weight st_text.Italic = ab_Italic st_text.Underline = ab_Underline lul_Handle = Handle(st_text) lul_Hdc = GetDC(lul_Handle) lul_hFont = Send(lul_Handle, WM_GETFONT, 0, 0) SelectObject(lul_Hdc, lul_hFont) //Let's use Ws, they're pretty wide ls_text = Fill ( 'W', ai_len ) If Not GetTextExtentpoint32A(lul_Hdc, ls_text, ai_len, lstr_Size ) Then ReleaseDC(lul_Handle, lul_Hdc) Return -1 End If ReleaseDC(lul_Handle, lul_Hdc) Return lstr_Size.cx end function on w_main.create this.cb_library=create cb_library this.cb_1=create cb_1 this.dw_columns=create dw_columns this.dw_datawindows=create dw_datawindows this.st_text=create st_text this.Control[]={this.cb_library,& this.cb_1,& this.dw_columns,& this.dw_datawindows,& this.st_text} end on on w_main.destroy destroy(this.cb_library) destroy(this.cb_1) destroy(this.dw_columns) destroy(this.dw_datawindows) destroy(this.st_text) end on type cb_library from commandbutton within w_main integer x = 1627 integer y = 792 integer width = 411 integer height = 112 integer taborder = 40 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" string text = "Select Library" end type event clicked;of_getdatawindows() end event type cb_1 from commandbutton within w_main integer x = 50 integer y = 788 integer width = 626 integer height = 112 integer taborder = 30 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" string text = "Get With DataWindow" end type event clicked;Boolean lb_underline, lb_italic Integer li_index, li_count, li_fontsize, li_fontweight Integer li_actualwidth, li_desiredwidth, li_row, li_len String ls_syntax, ls_errors, ls_columnname, ls_fontname, ls_datatype datawindow lds_temp dw_columns.Reset() lds_temp = dw_datawindows //lds_temp.Create ( ls_syntax, ls_errors ) If lds_temp.Object.DataWindow.Units <> '0' Then MessageBox ( "Warning", "This utility only works for DataWindows that are stored in PBU Units" ) End If li_count = Integer ( lds_temp.Object.DataWindow.Column.Count ) For li_index = 1 To li_count //Get column info ls_columnname = lds_temp.Describe ( '#' + String ( li_index ) + '.name' ) ls_fontname = lds_temp.Describe ( '#' + String ( li_index ) + '.Font.Face' ) If ls_fontname = '!' Then Continue //Not shown on datawindow ls_datatype = lds_temp.Describe ( '#' + String ( li_index ) + '.Coltype' ) If Left ( Lower ( ls_datatype ), 4 ) <> 'char' Then Continue //Not a string datatype li_len = Integer ( Mid ( ls_datatype, 6, Len ( ls_datatype ) - 6 ) ) li_fontsize = Integer ( lds_temp.Describe ( '#' + String ( li_index ) + '.Font.Height' ) ) li_fontweight = Integer ( lds_temp.Describe ( '#' + String ( li_index ) + '.Font.Weight' ) ) lb_italic = ( Lower ( lds_temp.Describe ( '#' + String ( li_index ) + '.Font.Italic' ) ) = 'yes' ) lb_underline = ( Lower ( lds_temp.Describe ( '#' + String ( li_index ) + '.Font.Underline' ) ) = 'yes' ) li_actualwidth = Integer ( lds_temp.Describe ( '#' + String ( li_index ) + '.Width' ) ) li_desiredwidth = PixelsToUnits ( of_getcolumnwidth( ls_fontname, li_len, li_fontsize, li_fontweight, lb_italic, lb_underline ), XPixelsToUnits! ) //Add it to the datawindow li_row = dw_columns.InsertRow ( 0 ) dw_columns.Object.columnname[li_row] = ls_columnname dw_columns.Object.actualwidth[li_row] = li_actualwidth dw_columns.Object.desiredwidth[li_row] = li_desiredwidth Next //Destroy lds_temp Return 1 end event type dw_columns from datawindow within w_main integer x = 32 integer y = 944 integer width = 2048 integer height = 736 integer taborder = 10 string dataobject = "d_columns" boolean hscrollbar = true boolean vscrollbar = true borderstyle borderstyle = stylelowered! end type type dw_datawindows from datawindow within w_main integer x = 18 integer y = 16 integer width = 2048 integer height = 736 integer taborder = 10 string dataobject = "d_datawindows" boolean hscrollbar = true boolean vscrollbar = true borderstyle borderstyle = stylelowered! end type event doubleclicked;string ls_datawindowname IF row > 0 THEN ls_datawindowname = this.object.datawindowname[row] of_getcolumns ( ls_datawindowname ) END IF end event type st_text from statictext within w_main boolean visible = false integer x = 2121 integer y = 240 integer width = 402 integer height = 64 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Arial" long textcolor = 33554432 long backcolor = 67108864 boolean focusrectangle = false end type |
Datawindow d_datawindows
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
release 10.5; datawindow(units=0 timer_interval=0 color=67108864 processing=1 HTMLDW=no print.printername="" print.documentname="" print.orientation = 0 print.margin.left = 0 print.margin.right = 0 print.margin.top = 0 print.margin.bottom = 0 print.paper.source = 0 print.paper.size = 0 print.canusedefaultprinter=yes print.prompt=no print.buttons=no print.preview.buttons=no print.cliptext=no print.overrideprintjob=no print.collate=yes print.preview.outline=yes hidegrayline=no grid.lines=0 ) header(height=68 color="536870912" ) summary(height=0 color="536870912" ) footer(height=0 color="536870912" ) detail(height=72 color="536870912" ) table(column=(type=char(40) updatewhereclause=yes name=datawindowname dbname="datawindowname" ) column=(type=datetime updatewhereclause=yes name=modified dbname="modified" ) column=(type=char(256) updatewhereclause=yes name=comments dbname="comments" ) ) text(band=header alignment="2" text="Datawindow Name" border="6" color="33554432" x="9" y="8" height="56" width="1111" html.valueishtml="0" name=datawindowname_t visible="1" font.face="Arial" font.height="-8" font.weight="400" font.family="2" font.pitch="2" font.charset="0" background.mode="1" background.color="536870912" ) column(band=detail id=1 alignment="0" tabsequence=32766 border="5" color="33554432" x="9" y="8" height="56" width="1111" format="[general]" html.valueishtml="0" name=datawindowname visible="1" edit.limit=0 edit.case=any edit.focusrectangle=no edit.autoselect=yes edit.autohscroll=yes font.face="Arial" font.height="-8" font.weight="400" font.family="2" font.pitch="2" font.charset="0" background.mode="2" background.color="1073741824" ) htmltable(border="1" ) htmlgen(clientevents="1" clientvalidation="1" clientcomputedfields="1" clientformatting="0" clientscriptable="0" generatejavascript="1" encodeselflinkargs="1" netscapelayers="0" pagingmethod=0 generatedddwframes="1" ) xhtmlgen() cssgen(sessionspecific="0" ) xmlgen(inline="0" ) xsltgen() jsgen() export.xml(headgroups="1" includewhitespace="0" metadatatype=0 savemetadata=0 ) import.xml() export.pdf(method=0 distill.custompostscript="0" xslfop.print="0" ) export.xhtml() |
Datawindow d_columns
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
release 10.5; datawindow(units=0 timer_interval=0 color=67108864 processing=1 HTMLDW=no print.printername="" print.documentname="" print.orientation = 0 print.margin.left = 0 print.margin.right = 0 print.margin.top = 0 print.margin.bottom = 0 print.paper.source = 0 print.paper.size = 0 print.canusedefaultprinter=yes print.prompt=no print.buttons=no print.preview.buttons=no print.cliptext=no print.overrideprintjob=no print.collate=yes print.preview.outline=yes hidegrayline=no grid.lines=0 ) header(height=72 color="536870912" ) summary(height=0 color="536870912" ) footer(height=0 color="536870912" ) detail(height=76 color="536870912" ) table(column=(type=char(40) updatewhereclause=yes name=columnname dbname="columnname" ) column=(type=number updatewhereclause=yes name=actualwidth dbname="actualwidth" ) column=(type=number updatewhereclause=yes name=desiredwidth dbname="desiredwidth" ) ) text(band=header alignment="2" text="Column Name" border="6" color="33554432" x="9" y="8" height="56" width="1097" html.valueishtml="0" name=columnname_t visible="1" font.face="Arial" font.height="-8" font.weight="400" font.family="2" font.pitch="2" font.charset="0" background.mode="1" background.color="536870912" ) text(band=header alignment="2" text="Actual Width" border="6" color="33554432" x="1115" y="8" height="56" width="352" html.valueishtml="0" name=actualwidth_t visible="1" font.face="Arial" font.height="-8" font.weight="400" font.family="2" font.pitch="2" font.charset="0" background.mode="1" background.color="536870912" ) text(band=header alignment="2" text="Desired Width" border="6" color="33554432" x="1477" y="8" height="56" width="407" html.valueishtml="0" name=desiredwidth_t visible="1" font.face="Arial" font.height="-8" font.weight="400" font.family="2" font.pitch="2" font.charset="0" background.mode="1" background.color="536870912" ) column(band=detail id=1 alignment="0" tabsequence=32766 border="5" color="33554432" x="9" y="8" height="56" width="1097" format="[general]" html.valueishtml="0" name=columnname visible="1" edit.limit=0 edit.case=any edit.focusrectangle=no edit.autoselect=yes edit.autohscroll=yes font.face="Arial" font.height="-8" font.weight="400" font.family="2" font.pitch="2" font.charset="0" background.mode="2" background.color="1073741824" ) column(band=detail id=2 alignment="1" tabsequence=32766 border="5" color="33554432" x="1115" y="8" height="56" width="352" format="[general]" html.valueishtml="0" name=actualwidth visible="1" edit.limit=0 edit.case=any edit.focusrectangle=no edit.autoselect=yes edit.autohscroll=yes font.face="Arial" font.height="-8" font.weight="400" font.family="2" font.pitch="2" font.charset="0" background.mode="2" background.color="1073741824" ) column(band=detail id=3 alignment="1" tabsequence=32766 border="5" color="33554432" x="1477" y="8" height="56" width="407" format="[general]" html.valueishtml="0" name=desiredwidth visible="1" edit.limit=0 edit.case=any edit.focusrectangle=no edit.autoselect=yes edit.autohscroll=yes font.face="Arial" font.height="-8" font.weight="400" font.family="2" font.pitch="2" font.charset="0" background.mode="2" background.color="1073741824" ) htmltable(border="1" ) htmlgen(clientevents="1" clientvalidation="1" clientcomputedfields="1" clientformatting="0" clientscriptable="0" generatejavascript="1" encodeselflinkargs="1" netscapelayers="0" pagingmethod=0 generatedddwframes="1" ) xhtmlgen() cssgen(sessionspecific="0" ) xmlgen(inline="0" ) xsltgen() jsgen() export.xml(headgroups="1" includewhitespace="0" metadatatype=0 savemetadata=0 ) import.xml() export.pdf(method=0 distill.custompostscript="0" xslfop.print="0" ) export.xhtml() |
Find Projects On Github click here
Good Luck!
Subscribe
Login
0 Comments