Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CreateControl
#1
I really dig this quite a lot!

Just to make sure I've got the idea right:
CreateControl([Exstyle][Class][Text][Style][x][y][cx][cy][Hwnd][Id])

I've noticed that the x y cx cy do not work the same as when they are in the dialog editor...then I noticed this:
Function DE_CreateControl
Code:
Copy      Help
function# Exstyle $Class $Text Style x y cx cy Hwnd Id [Bottom] [DlgUnits] [invisible]

if DlgUnits
,x=MulDiv(x d.dbx 4)
,y=MulDiv(y d.dby 8)
,cx=MulDiv(cx d.dbx 4)
,cy=MulDiv(cy d.dby 8)
,
if Bottom
,RECT r; GetClientRect(Hwnd &r)
,y=r.bottom-cy; x=0

if(!invisible) Style|WS_VISIBLE

int h=CreateWindowExW(Exstyle @Class @Text (Style|WS_CHILD|WS_CLIPSIBLINGS) x y cx cy Hwnd Id _hinst 0)
if(!h) ret

if(Bottom) EnumChildWindows Hwnd &DE_GB h ;;send all groupboxes to bottom

SendMessage(h WM_SETFONT _hfont 0)
ret h

I don't quite get what you are doing and why you would put the math in like this.

It just makes it weird because I was going to use dialog editor to layout the new controls and then just put the information in the CreateControl call. But they are always in the wrong spot and too small. Guess I could just do the math myself Smile
#2
A quick example to show how the new lines are about 2/3 the size as the Dialog Editor's controls, even though they are using the same x y cx cy values.

Function CC_Dialog
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

;BEGIN DIALOG
;0 "" 0x90C80A44 0x100 0 0 439 135 "Dialog"
;1 Button 0x54030001 0x4 374 0 48 14 "OK"
;2 Button 0x54030000 0x4 374 16 48 14 "Cancel"
;3 ComboBox 0x54230243 0x0 2 2 96 213 ""
;4 ComboBox 0x54230243 0x0 100 2 96 213 ""
;5 Edit 0x54030080 0x200 198 2 20 12 ""
;6 Edit 0x54030080 0x200 220 2 46 12 ""
;7 Edit 0x54030080 0x200 268 2 48 12 ""
;8 Button 0x54032000 0x0 320 2 46 12 "Add"
;END DIALOG
;DIALOG EDITOR: "" 0x2030001 "" "" ""

str controls = "3 4 5 6 7"
str cb3 cb4 e5 e6 e7
e5=1
if(!ShowDialog("CC_Dialog" &CC_Dialog &controls)) ret

ret
;messages
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 8
,CC_Add hDlg
,
,case IDOK
,case IDCANCEL
ret 1

Function CC_Add
Code:
Copy      Help
;/CC_Dialog
function hwnd

int index=id(5 win("Dialog" "#32770"))
str sIndex.getwintext(index)
int i=val(sIndex)
int i2=val(sIndex)
i2*25
i*100

int idctrl
int hctrl
;CreateControl([Exstyle][Class][Text][Style][x][y][cx][cy][Hwnd][Id])
for(idctrl i 1000000) if(!id(idctrl hwnd)) break
hctrl=CreateControl(WS_EX_CLIENTEDGE "ComboBox" 0 0x54230243 2 i2 96 213 hwnd idctrl)
for(idctrl i 1000000) if(!id(idctrl hwnd)) break
hctrl=CreateControl(WS_EX_CLIENTEDGE "ComboBox" 0 0x54230243 100 i2 96 213 hwnd idctrl)
for(idctrl i 1000000) if(!id(idctrl hwnd)) break
hctrl=CreateControl(WS_EX_CLIENTEDGE "Edit" 0 0x54030080 198 i2 20 12 hwnd idctrl)
for(idctrl i 1000000) if(!id(idctrl hwnd)) break
hctrl=CreateControl(WS_EX_CLIENTEDGE "Edit" 0 0x54030080 220 i2 46 12 hwnd idctrl)
for(idctrl i 1000000) if(!id(idctrl hwnd)) break
hctrl=CreateControl(WS_EX_CLIENTEDGE "Edit" 0 0x54030080 268 i2 48 12 hwnd idctrl)
;

i/100
i+1
sIndex=i
sIndex.setwintext(index)
#3
Hmm...it's actually 2/3 exactly! If I multiply all the numbers by 1.5 I get them to even out.
for(idctrl i 1000000) if(!id(idctrl hwnd)) break
hctrl=CreateControl(WS_EX_CLIENTEDGE "ComboBox" 0 0x54230243 3 i2 144 213 hwnd idctrl)
for(idctrl i 1000000) if(!id(idctrl hwnd)) break
hctrl=CreateControl(WS_EX_CLIENTEDGE "ComboBox" 0 0x54230243 150 i2 144 213 hwnd idctrl)
for(idctrl i 1000000) if(!id(idctrl hwnd)) break
hctrl=CreateControl(WS_EX_CLIENTEDGE "Edit" 0 0x54030080 297 i2 30 20 hwnd idctrl)
for(idctrl i 1000000) if(!id(idctrl hwnd)) break
hctrl=CreateControl(WS_EX_CLIENTEDGE "Edit" 0 0x54030080 330 i2 69 20 hwnd idctrl)
for(idctrl i 1000000) if(!id(idctrl hwnd)) break
hctrl=CreateControl(WS_EX_CLIENTEDGE "Edit" 0 0x54030080 402 i2 72 20 hwnd idctrl)

neat...but why?

Also, What would be the simplest way to write all the data in those boxes to an XML being that I wouldn't know exactly how many will exist at the time of update? I'm not really good with those codes yet. I plan to be...but right now, I'm not so hot.

Mmm...Friday night...gig...free booze. I love being a musician. Thanks for all the help,
Jimmy Vig.
#4
CreateControl uses pixels.
Dialog editor uses dialog box units. They depend on dialog font. They are about 2 or 4 pixels, and different horizontally and vertically.
Using pixels is simpler.

What happens if you change dialog font, for example in control panel -> display:
If using pixels, position and size of controls will be the same. But text in controls may be too big or small.
If using dialog box units, position and size of controls will be automatically changed to match the new font.
#5
Are you saying that control panel will change the display of CreateControl items and not items created with dialog editor?

Not much of a problem for me, but doesn't this cause a problem when writing programs that will be used on any computer with many different font settings?

Maybe I'm not getting it right now...I'll play around with the settings like you said and get a feel for it more in the morning.

Thanks again for being such a great resource!
Jimmy Vig
#6
Try to change DPI from 96 (default) to 120. Dialogs will become bigger. Controls created in dialog editor will become bigger and moved. Controls created by CreateControls will remain in the same place and size. Use the way of creating controls which is better for you. But if you use both ways in a single dialog, after changing DPI controls may overlap etc.
#7
Please instruct how to change DPI from 96 (default) to 120.

Thanks.
#8
In control panel. Somewhere near the place where you can change display resolution etc.
#9
Achh...that makes the computer look all icky. I just can't get down with that solution. Plus wouldn't I have to make that change on every computer for my dialogs with CreateControl's to look right? Or does this just effect the way the program is written?
#10
Convert x, y, width and height from/to dialog box units. But I don't remember how to do it. I just remember it was not easy. Learn about dialog box units in msdn library.

But i think most computers have default DPI. Use CreateControl with pixels. To make your dialogs more compatible with 120 dpi, just make your controls that contain text (eg buttons) a bit bigger.


Forum Jump:


Users browsing this thread: 1 Guest(s)