Control ID..which type?

Windows specific questions.
Post Reply
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Control ID..which type?

Post by aurelVZAB »

hi
which type of varible must be used as control id ?
parameter after parent (hwnd)
i tried integer, integer ptr ,long ,long ptr ..all of them cose error or warnnings ?

static1 = CreateWindowEx( 0, "static", "" , WS_Border or WS_VISIBLE Or WS_CHILD , 10 , 10 , 100 , 100 , hWnd, st1_id, 0, 0)
Xusinboy Bekchanov
Posts: 789
Joined: Jul 26, 2018 18:28

Re: Control ID..which type?

Post by Xusinboy Bekchanov »

aurelVZAB wrote:hi
which type of varible must be used as control id ?
parameter after parent (hwnd)
i tried integer, integer ptr ,long ,long ptr ..all of them cose error or warnnings ?

static1 = CreateWindowEx( 0, "static", "" , WS_Border or WS_VISIBLE Or WS_CHILD , 10 , 10 , 100 , 100 , hWnd, st1_id, 0, 0)
Here:
https://docs.microsoft.com/en-us/window ... ewindowexa
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: Control ID..which type?

Post by aurelVZAB »

Come on Xusinboy...is that help ???
from someone like you who build IDE
i am not interested what MS offer than experience from FreeBasic user...is that right?
so ..in o2 i used for control id a Long or Int (Integer) and i cannot figure why FB use Null
what is NULL in fb case ?
and how NULL if is pointer or INT can be used for control ID ?
please anyone with experience in winapi programming ...
PaulSquires
Posts: 1002
Joined: Jul 14, 2005 23:41

Re: Control ID..which type?

Post by PaulSquires »

Try the following:

CAST(HMENU, st1_id)
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: Control ID..which type?

Post by aurelVZAB »

Thanks Paul

but that is not a problem compiler not complain about argument in function
but main complain is about variable type
like in declaration:
dim static1_id as integer ptr
static1_id = 500
no mether which type i use ..i get

suspicious pointer assignment ?
is this some kind of bug or what
i used latest fb 1.0.9
but same in older release too
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: Control ID..which type?

Post by aurelVZAB »

here is error message i am using poseidonFB

\FreeBASIC-1.09.0-win32\Aurel_FB_Scintilla\FBSci.bas(135) warning 4(2): Suspicious pointer assignment
Compile Success! But got warning...
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: Control ID..which type?

Post by Josep Roca »

Why do you declare it as a pointer if it is not a pointer?

dim static1_id as integer
static1_id = 500

and when you pass it to CreateWIndowEx, do te casting

static1 = CreateWindowEx( 0, "static", "" , WS_Border or WS_VISIBLE Or WS_CHILD , 10 , 10 , 100 , 100 , hWnd, CAST(HMENU, static1_id), 0, 0)
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: Control ID..which type?

Post by aurelVZAB »

Yes Jose
That is why i asking all the time I DON'T know which type i must use
and i agree with you ,and i already tried this using Integer
look code :

Code: Select all

 dim static1_id as integer 
    static1_id = 500

    dim classname as any ptr
    dim cname as string
    cname = "FBWin"
    classname = strptr(cname)
 
     
    function = 0
    
    with wcls
       .style         = CS_HREDRAW or CS_VREDRAW
       .lpfnWndProc   = @WndProc
       .cbClsExtra    = 0
       .cbWndExtra    = 0
       .hInstance     = hInstance
       .hIcon         = LoadIcon( NULL, IDI_APPLICATION )
       .hCursor       = LoadCursor( NULL, IDC_ARROW )
       .hbrBackground = GetStockObject( WHITE_BRUSH )
       .lpszMenuName  = NULL
       .lpszClassName = classname
    end with
         
    if( RegisterClass( @wcls ) = FALSE ) then
       MessageBox( null, "Failed to register wcls", "Error", MB_ICONERROR )
       exit function
    end if
   
    hWnd = CreateWindowEx( 0, classname, "Aurel_FB_SCi", WS_OVERLAPPEDWINDOW, 100, 100, 800, 600,NULL,NULL,hInstance,NULL)

   static1 = CreateWindowEx( 0, "static", "" , WS_Border or WS_VISIBLE Or WS_CHILD , 10 , 10 , 100 , 100 , hWnd,cast(HMENU,static1_id), 0, 0)
                          
then after that i get message :

D:\FreeBASIC-1.09.0-win32\Aurel_FB_Scintilla\FBSci.bas(135) error 14: Expected identifier
D:\FreeBASIC-1.09.0-win32\Aurel_FB_Scintilla\FBSci.bas(136) error 146: Only valid in -lang deprecated or fblite or qb

can you explain this ?
i am confused totally ....

to remind myself:

Declare Function CreateWindowEx Lib "user32.dll" Alias "CreateWindowExA"(ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, ByRef lpParam As Long) As Long

i use this in o2 and work allways of course ... it is type Long
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: Control ID..which type?

Post by Josep Roca »

This is not O2, it is FreeBasic.

declare function CreateWindowExA(byval dwExStyle as DWORD, byval lpClassName as LPCSTR, byval lpWindowName as LPCSTR, byval dwStyle as DWORD, byval X as long, byval Y as long, byval nWidth as long, byval nHeight as long, byval hWndParent as HWND, byval hMenu as HMENU, byval hInstance as HINSTANCE, byval lpParam as LPVOID) as HWND

What are you doing with?

dim classname as any ptr
dim cname as string
cname = "FBWin"
classname = strptr(cname)

You can simply do

dim classname as zstring * 6 = "FBWin"

and change

.lpszClassName = classname

to

.lpszClassName = @classname

BTW you're posting incomplete code, so nobody can test it.
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: Control ID..which type?

Post by aurelVZAB »

Ok
it seems that returned hendler of CreateWindowEx in FB must be HWND ..why is that i am not sure?
ok this work
thanks for replays..

Code: Select all

dim static1 as HWND
    dim static1_id As Long 
    static1_id = 500
    
 static1 = CreateWindowEx ( 0, "static", "" , WS_Border or WS_VISIBLE Or WS_CHILD , 10 , 10 , 100 , 100 , hWnd,cast(HMENU,static1_id), 0,byval NULL)   
    
    
so i will use same method for scintilla id..because it looks that is the only way
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: Control ID..which type?

Post by aurelVZAB »

BUT
i just found here on forum one old topic about Richedit control where is handler a Integer
this is the way i am more familiar..

Code: Select all

DIM hRich1 AS INTEGER
     hLib = LoadLibrary("RICHED32.DLL")
     
     hRich1 = CreateWindowEx(WS_EX_CLIENTEDGE, "RichEdit", "", WS_CHILD OR WS_VISIBLE OR _ 
     WS_CHILD OR WS_VISIBLE OR WS_TABSTOP OR WS_VSCROLL OR ES_WANTRETURN OR ES_AUTOVSCROLL OR _ 
     ES_MULTILINE OR ES_NOHIDESEL OR ES_SAVESEL OR ES_DISABLENOSCROLL, _   
     10,  148,  475,  361, hDlg,  101, 0, BYVAL NULL)
     
     SendMessage hRich1, EM_SETSEL, 1, 1       ' to reset pos/selection in text
     SendMessage hRich1, EM_SCROLLCARET, 0, 0  ' Make caret  scroll into view..
     SendMessage hRich1, EM_SETOPTIONS, ECOOP_OR, ECO_SELECTIONBAR
     SendMessage hRich1, EM_SETMARGINS, EC_LEFTMARGIN, 0     'Set Left Margin
 
Post Reply