March 28, 2024, 11:58:35 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Why SetFont don't work with CreateWindowExA?

Started by aurelCB, February 14, 2009, 05:33:24 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

aurelCB

Hi people...

I have one small(or big?) problem.
Why SetFont don't work with CreateWindowExA?
I create button with CreateWindowExA API.
You may ask why?
Becose only in this way i can add xp theme style with manifest.
SETCONTROLTEXT command work with button but SETFONT crush Creative Basic?

here is example:
def win:window

def button1:uint

const button1_ID = 100
const ID_button1_CREATE = 2024 + button1_ID
DECLARE "user32",CreateWindowExA(ex:int,class:string,name:string,style:int,x:int,y:int,x1:int,y1:int,parent:window,id:int,hinstance:int,ed:int),int

DECLARE "kernel32", GetExeHandle alias GetModuleHandleA(name:int),INT

CONST WM_SETFONT = 0x30
CONST WM_FONTCHANGE = 0x1D

Window win,0,0,400,300,@minbox,0,"Main",main
Setwindowcolor win,rgb(210,210,230)


Button1 = CreateWindowExA(0, "Button","",1342242816, 95, 47, 89, 27,win,ID_button1_CREATE ,0 ,0)

SETCONTROLTEXT win, button1_ID , "XP button"
'>>>>>>setfont command crush creative basic
'SETFONT win,"MS Sans Serif",8, 400,0,100
'i try this but don't work
'SENDMESSAGE (win,WM_SETFONT, 0, "Courier New",100)


waituntil win=0
END

SUB main
select @class
case @IDclosewindow
closewindow win
case @idcreate
centerwindow win

case @idcontrol
IF @controlid = 100
IF @notifycode=0
'sendmessage (win,0x1D,0,0,button1_ID)
messagebox win,"I'm a XP button","Ready!"
ENDIF
ENDIF


endselect
RETURN



I try change font with Sendmessage but without success.
Does anyone of you has an idea how to do it?
thanks..
Zlatko

Ionic Wind Support Team

Because internally Creative BASIC adds a constant to your button ID.  So it isn't 100 when you create a button in Creative.  It is 2024+100

so change your constant:

const button1_ID = 2124
....
Button1 = CreateWindowExA(0, "Button","",1342242816, 95, 47, 89, 27,win,ID_button1_CREATE ,0 ,0)
SETFONT win,"MS Sans Serif",8, 400,0,100

Would work.

Of course there is an easier trick.  Just create a bitmap button, but don't give it an image.  And it will be themed.
Ionic Wind Support Team

aurelCB

Thanks Paul... :)

Oh my , i find harder way with SendMessage.
Here is code:
' xp style button with font -MS Sans Serif-8
'compile as windows app and add manifest
def win:window
def button1:uint
' this api you must use for change font
declare "gdi32",GetStockObject(nIndex AS INT),INT
'button ID
const button1_ID = 100
const ID_button1_CREATE = 2024 + button1_ID
' select font
const DEFAULT_GUI_FONT = 17
DECLARE "user32",CreateWindowExA(ex:int,class:string,name:string,style:int,x:int,y:int,x1:int,y1:int,parent:window,id:int,hinstance:int,ed:int),int

'DECLARE "kernel32", GetExeHandle alias GetModuleHandleA(name:int),INT

CONST WM_SETFONT = 0x30

Window win,0,0,400,300,@minbox,0,"XP Style button",main
Setwindowcolor win,rgb(210,210,230)


Button1 = CreateWindowExA(0, "Button","",1342242816, 95, 47, 89, 27,win,ID_button1_CREATE ,0 ,0)

SETCONTROLTEXT win, button1_ID , "XP button"
'>>>>>>setfont command crush creative basic
'SETFONT win,"MS Sans Serif",8, 400,0,100 
' // set font with sendmessage command
SENDMESSAGE (win,WM_SETFONT, GetStockObject(DEFAULT_GUI_FONT),0,100)


waituntil win=0
END

SUB main
select @class
case @IDclosewindow
closewindow win
case @idcreate
centerwindow win

case @idcontrol
IF @controlid = 100
' if you use manifest you must have @notifycode
IF @notifycode=0
messagebox win,"I'm a XP button","Ready!"
ENDIF
ENDIF


endselect
RETURN



I always make complicated. ::)
But on the other side I learn new API.
Your way is better and easier!
Thanks again...

Zlatko

aurelCB

Hi...
Here is example with 3 controls with xp theme.
Edit control is little bit problematic- work native only in dialog?

' xp style controls with font -MS Sans Serif-8
'compile as windows app and add manifest(yourexename.exe.manifest)
def win:window
def button1,edit1,combo1:uint
' this api you must use for change font
declare "gdi32",GetStockObject(nIndex AS INT),INT
'button ID
const button1_ID = 2124
const edit1_iD = 2125
const combo1_ID = 2126
'const ID_button1_CREATE = 2024 + button1_ID
' select font
const DEFAULT_GUI_FONT = 17
declare "user32",GetSysColor(nIndex AS INT),INT
DECLARE "user32",CreateWindowExA(ex:int,class:string,name:string,style:int,x:int,y:int,x1:int,y1:int,parent:window,id:int,hinstance:int,ed:int),int

'DECLARE "kernel32", GetExeHandle alias GetModuleHandleA(name:int),INT

CONST WM_SETFONT = 0x30
CONST WS_OVERLAPPED = 0x0
CONST WS_POPUP = 0x80000000
CONST WS_CHILD = 0x40000000
CONST WS_MINIMIZE = 0x20000000
CONST WS_VISIBLE = 0x10000000
CONST WS_DISABLED = 0x8000000
CONST WS_CLIPSIBLINGS = 0x4000000
CONST WS_CLIPCHILDREN = 0x2000000
CONST WS_MAXIMIZE = 0x1000000
CONST WS_CAPTION = 0xC00000                 
CONST WS_BORDER = 0x800000
CONST WS_DLGFRAME = 0x400000
CONST WS_VSCROLL = 0x200000
CONST WS_HSCROLL = 0x100000
CONST WS_SYSMENU = 0x80000
CONST WS_THICKFRAME = 0x40000
CONST WS_GROUP = 0x20000
CONST WS_TABSTOP = 0x10000
CONST CBS_DROPDOWN = 0x2
CONST CBS_DROPDOWNLIST = 0x3

Window win,0,0,400,300,@minbox,0,"XP Style button",main
Setwindowcolor win,GetSysColor(15)


Button1 = CreateWindowExA(0, "Button","",1342242816, 95, 47, 89, 27,win,button1_ID,0 ,0)
SETCONTROLTEXT win, 100 , "XP button"
SENDMESSAGE (win,WM_SETFONT, GetStockObject(DEFAULT_GUI_FONT),0,100)
' edit is weird work ,native only if is created on dialog
Edit1 = CreateWindowExA(0, "Edit","",WS_CHILD|WS_VISIBLE, 195, 48, 80, 16,win,edit1_ID,0 ,0)
SENDMESSAGE (win,WM_SETFONT, GetStockObject(DEFAULT_GUI_FONT),0,101)
' small trick
RECT win,194,47,82,18,rgb(100,100,120)
'work in two way
Combo1 = CreateWindowExA(0, "ComboBox","",WS_CHILD|WS_VISIBLE|CBS_DROPDOWN, 195, 88, 180, 120,win,combo1_ID,0 ,0)
'CONTROL win,"M,ComboBox1,69,80,150,180,0x50A00603,102"
SENDMESSAGE (win,WM_SETFONT, GetStockObject(DEFAULT_GUI_FONT),0,102)
ADDSTRING win, 102, "This is"
ADDSTRING win, 102, "XP theme"
ADDSTRING win, 102, "Combobox"






waituntil win=0
END

SUB main
select @class
case @IDclosewindow
closewindow win
case @idcreate
centerwindow win

case @idcontrol
IF @controlid = 100
' if you use manifest you must have @notifycode
IF @notifycode=0
messagebox win,"I'm a XP button","Ready!"
ENDIF
ENDIF


endselect
RETURN