March 28, 2024, 06:48:04 AM

News:

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


How change edit control backcolor

Started by aurelCB, March 29, 2009, 04:39:32 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

aurelCB

Hi...
This question maby look stupid.
So I have created edit control with APi
def ehdc:int
def fcolor,bcolor:INT
Edit1 = CreateWindowExA(0x200, "Edit","",WS_CHILD|WS_VISIBLE, 195, 47, 89, 27,win,edit1_ID+2024,0 ,0)
'// next few lines is from internet ...
'  case  WM_CTLCOLOREDIT:
'ehdc = GetHDC(win)       
'        hdc = (HDC) wParam;             // handle of dc
'         tmpHwnd = (HWND) lParam;  // handle of edit control
         
  ' fcolor=SetTextColor(ehdc, RGB(255, 0, 0))
'  ' bcolor=SetBkColor(ehdc, RGB(0, 200, 0))
'ReleaseHDC win,ehdc
'setcontrolcolor win,101,fcolor,bcolor


Setcontrolcolor don't work and simply crush Cbasic IDE.
Is there a another way to set backcolor or forecolore of control?

Zlatko

ZeroDog

is there any reason you are using API functions instead of using CBasic's control creation functions?

Ionic Wind Support Team

That's what I want to know too.

WM_CTLCOLOREDIT is the correct message, but you have to process it in your Windows handler.  Creative BASIC does a lot for you in the background, so you can't just use SetControlColor on a control that wasn't created by Creative BASIC commands.

Creative BASIC has special processing of the "control color" messages that reflect the message from the parent window, to the control it applies to.  Creative BASIC controls are subclassed to handle their own color message.  For all of this to work you can't mix an API created window/control with a Creative BASIC created window/control.  Not sure why you want to.

Again I have to stress, if you really want to learn the GDI, or create API windows and controls using CreateWindowEx then you shouldn't be using Creative BASIC to do it.  Use Emergence BASIC, its only $24 on sale, and you'll be much better off with lower level coding.  Then you can create WndProc functions, subclass controls, create callbacks and all of the other fun Windows API mess.

Paul.



Ionic Wind Support Team

aurelCB

Yes reason is simple.
I want add manifest to my app and want that Edit control look like in many other
aplication.Only way is with APi created edit control.

regards
Zlatko

Ionic Wind Support Team

Why not just include a manifest file with your executable?

Paul.
Ionic Wind Support Team

aurelCB

I include manifest and i add small example in attachment.
Screenshot present what I want that edit control look.
I want look like edit1.Nothing else.

' xp style button with font -MS Sans Serif-8
'compile as windows app and add manifest
def win:window
def button1,edit1:uint
' this api you must use for change font
declare "gdi32",GetStockObject(nIndex AS INT),INT
'button ID
def button1_ID,edit1_ID:INT
button1_ID = 100
edit1_iD = 101
'const ID_button1_CREATE = 2024 + button1_ID
' select font
def fsize:int
def cfont:int
def hbackbrush:int
const DEFAULT_GUI_FONT = 11
DECLARE "gdi32",SetTextColor(hdc AS INT,crColor AS INT),INT
DECLARE "gdi32",SetBkColor(hdc AS INT,crColor AS INT),INT
DECLARE "gdi32",CreateSolidBrush(crColor 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 "gdi32",CreateFontA(H:INT,W:INT,E:INT,O:INT,Weigth:INT,I AS INT,u AS INT,S AS INT,C AS INT,OP AS INT,CP AS INT,Q AS INT,PAF AS INT,F AS STRING),INT
'ib LoadFont(_fname.s,_fsize,_ff,_fi,_fu,_fs)
'  ProcedureReturn CreateFont(_fsize,0,0,0,_ff,_fi,_fu,_fs,1,0,0,0,2,_fname)
'EndProcedure
'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                  :'  WS_BORDER | WS_DLGFRAME
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 CTLCOLOR_EDIT = 10
CONST WM_CTLCOLOREDIT = 0x133
CONST EM_SETBKGNDCOLOR = 0x010203
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,button1_ID+2024,0 ,0)

SETCONTROLTEXT win, 100 , "XP button"
'>>>>>>setfont command crush creative basic
'SETFONT win,"MS Sans Serif",8, 400,0,100 
' // set font with sendmessage command
'_ff     "Bold factor", a value from 0 to 900 in increments of 100
'             400 is standard, 700 bold
'    _fi     Italics. Set to 1 for italics, 0 for normal
'    _fu        Underlined. Set to 1 for underlines, 0 for normal
'    _fs        Strikeout. Set to 1 for strikeout, 0 for normal
'(H AS INT,W AS INT,E AS INT,O AS INT,W AS INT,I AS INT,u AS INT,S AS INT,C AS INT,OP AS INT,CP AS INT,Q AS INT,PAF AS INT,F AS STRING),INT
fsize=16
'CreateFont(_fsize,0,0,0,_ff,_fi,_fu,_fs,1,0,0,0,2,_fname)
'SetControlFont()
cfont=CreateFontA(fsize,0,0,0,700,1,0,0,1,0,0,0,2,"Times New Roman")
SENDMESSAGE (win,WM_SETFONT,cfont,0,100)
'-----------------------------------------------------------------

Edit1 = CreateWindowExA(0x200, "Edit","Edit1",WS_CHILD|WS_VISIBLE, 195, 47, 89, 27,win,edit1_ID+2024,0 ,0)
fsize=12
cfont=CreateFontA(fsize,0,0,0,400,0,0,0,1,0,0,0,2,"Verdana")
SENDMESSAGE (win,WM_SETFONT,cfont,0,101)
SETCONTROLTEXT win, 101 , "Edit1"

CONTROL win,"E,,38,143,162,28,0x200|WS_CHILD|WS_VISIBLE,102"
SETCONTROLTEXT win, 102 , "Edit2"

'-----------------------------------------------
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


Ionic Wind Support Team

Zlatko,

Just remove the extra border style (ws_ex_clientedge) from the edit control using SetWindowLong and GWL_STYLE.  Here is Grahams example which removes both borders:

http://www.ionicwind.com/forums/index.php/topic,2844.0.html

And for buttons, create a button with the @CTLBTNBITMAP  but don't give it an image to display, it will be a normal button that is themed, set the buttons text with SETCONTROLTEXT and change the font to whatever you want.

No need to create them with the API at all, you only needed to ask ;)

Paul.

NOTE:  Much simpler with Emergence BASIC.  Which has the built in @SYSBUTTON type, and a convenient ModifyExStyle command to remove/set extended styles of controls.  But you can still get the same results using Creative BASIC using the hacks above.



Ionic Wind Support Team

aurelCB

Hi...
Yes Graham-s example work perfectly,thanks...

def w1:window
def run,t:int
declare "user32",GetWindowLongA(hnd:int,ind:int),int
declare "user32",GetDlgItem(Hwnd:int,cntid:int),int
declare "user32",SetWindowLongA(hwnd:int,ind:int,nwv:int),int

const gwl_style = -16
const gwl_exstyle = -20
const WS_EX_CLIENTEDGE = 200

window w1,100,100,300,150,0,0,"Xp stlyle edit",hwndmain
setwindowcolor w1,rgb(200,200,210)
CONTROL w1,"E,,60,30,150,20,0x50000000,1"

'Parameters for RemoveBorder:-
'window,control,x,y,width,height
'should be same as given in control statement
def hwndN,hwndD,cnt:int
def x,y,wi,h:INT
cnt=1

  hwndN = GetDlgItem(w1,2024+cnt)
  hwndD = GetWindowLongA(hwndN,gwl_style)

  hwndD = hwndD & Not(@border)
  SetWindowLongA(hwndN,gwl_style,hwndD)
  hwndD = GetWindowLongA(hwndN,gwl_exstyle)

  hwndD = hwndD & Not(ws_ex_clientedge)
  SetWindowLongA(hwndN,gwl_exstyle,hwndD)
'has to a different size here, as otherwise control
'doesn't get redrawn without border(must be h+1=20+1)
  setsize w1,60,30,150,20+1,cnt


setcontroltext w1,1,"test"
setfont w1,"Courier New",10,400,0,cnt
setcontrolcolor w1,1,0,rgb(250,250,250)

run=1
waituntil run=0
closewindow w1
end

sub hwndmain
select @class
case @idclosewindow
run=0
case @idcreate
centerwindow w1
endselect
return



aurelCB

I find next trick for xpedit control.
Edit is not edit then is combo ::)

' main skeleton
def win:window
Window win,0,0,400,300,@minbox,0,"Edit",main
setwindowcolor win,rgb(230,230,235)

CONTROL win,"M,,59,28,111,22,0x50800000,1"
SETFONT win, "MS Sans Serif",8,400,0,1
Setcontroltext win,1,"Text1"

CONTROL win,"M,,58,81,112,24,0x50800000,2"
SETFONT win,"Courier New",10,400,0,2
Setcontroltext win,2,"Text2"
SETCONTROLCOLOR win, 2,rgb(250,250,0),rgb(100,100,160)

waituntil win=0
END

SUB main
select @class
case @IDclosewindow
closewindow win
endselect
RETURN