problem with pointers and Classname

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

problem with pointers and Classname

Post by aurelVZAB »

I just want resurect simple scintilla exaple posted long time here on forum
and i have strange problem with class name ...
D:\FreeBASIC-1.05.0-win32\Aurel_FB_Scintilla\FBSci.bas(75) warning 4(2): Suspicious pointer assignment
D:\FreeBASIC-1.05.0-win32\Aurel_FB_Scintilla\FBSci.bas(83) warning 3(2): Passing different pointer types, at parameter 2 of CREATEWINDOWEX()
here is part of code :

Code: Select all

 dim classname as zstring 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)
    
it compile and even execute BUT complain ..about ???
even in original code complain strptr() can be used and anyway again complain ???
so anyone can explain to me a proper way ?
thanks in advance
VANYA
Posts: 1834
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: problem with pointers and Classname

Post by VANYA »

Code: Select all

 dim classname as zstring 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)
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: problem with pointers and Classname

Post by aurelVZAB »

WOW

thanks vanya

i come to this using any ptr..

Code: Select all

 dim classname as any ptr
    dim cname as string
    cname = "FBWin"
    classname = @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)
                          
so many different things drive me crazy and i must say that i become rusty with fbc
VANYA
Posts: 1834
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: problem with pointers and Classname

Post by VANYA »

aurelVZAB wrote:i come to this using any ptr..
The headers indicate the types:
for the ASCII version LPCSTR ( LPCSTR = CONST ZSTRING PTR)
for UNICODE version LPCWSTR (LPCWSTR = CONST WSTRING PTR)
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: problem with pointers and Classname

Post by aurelVZAB »

ahh ok ...so must be zstring ..fine
tnx
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: problem with pointers and Classname

Post by aurelVZAB »

so far i get this without warnnings and suspects

Code: Select all

#include once "windows.bi"
#include once "win/richedit.bi"
#define PLAT_WIN 1
#include "scintilla.bi"
#include "scilexer.bi"
DyLibLoad("SciLexer.dll")


Declare Function WinMain( byval hInstance as HINSTANCE, byval hPrevInstance as HINSTANCE, byval szCmdLine as string, byval iCmdShow as integer ) as integer

end WinMain( GetModuleHandle( null ), null, Command( ), SW_NORMAL )

Dim Shared As HWND hSci
Dim Shared tx As zstring ptr


function WndProc ( byval hWnd as HWND, byval wMsg as UINT, byval wParam as WPARAM, byval lParam as LPARAM ) as LRESULT
   
    function = 0
   
    select case( wMsg )
   
     case WM_CREATE
      
      Dim text as string  
      text = "Scintilla Test..OK!" 
      tx = strptr(text)
 
      Dim As Integer i,rx,ry,rw,rh,ext,sci_style,sciID
      rx=180: ry=84 : rw=598 : rh=390 : ext= &h200 : sciID = 400     
     hSci = CreateWindowEx(ext,"Scintilla","", WS_CHILD Or WS_VISIBLE Or WS_TABSTOP Or WS_CLIPCHILDREN,rx,ry,rw,rh,hWnd,NULL, 0,0)
           
            'SendMessage(hSci, SCI_SETSELBACK, 1, Cast(LPARAM,&HFFEFD0))  
            SendMessage(hSci,SCI_SETLEXER,40,0) 
         
            'SendMessage(hSci,SCI_SETKEYWORDS,NULL,Cast(LPARAM,@"html head body title"))
            SendMessage(hSci,SCI_STYLECLEARALL, 0, 1)
           
            SendMessage(hSci,SCI_SETTEXT,0, cast(LPARAM,tx) )
            
       
      case WM_KEYDOWN
         if( lobyte( wParam ) = 27 ) then
            PostMessage( hWnd, WM_CLOSE, 0, 0 )
         end if

       case WM_DESTROY
            PostQuitMessage( 0 )
            exit function
    end select
   
    function = DefWindowProc( hWnd, wMsg, wParam, lParam )   
   
end function

'':::::
function WinMain ( byval hInstance as HINSTANCE, _
                   byval hPrevInstance as HINSTANCE, _
                   byval szCmdLine as string, _
                   byval iCmdShow as integer ) as integer   
     
    dim wMsg as MSG
    dim wcls as WNDCLASS     
    dim hWnd as HWND
    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)
                          
                         

    ShowWindow( hWnd, iCmdShow )
    UpdateWindow( hWnd )
     
    while( GetMessage( @wMsg, NULL, 0, 0 ) <> FALSE )   
        TranslateMessage( @wMsg )
        DispatchMessage( @wMsg )
    wend
   
    function = wMsg.wParam

end function]
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: problem with pointers and Classname

Post by aurelVZAB »

RGB function it seems that not work in GUI mode so i made my own

Code: Select all

Function RGBX(byval red as INTEGER,byval green as INTEGER,byval blue as INTEGER) as integer
  dim rgb_color as integer
  rgb_color = red
  rgb_color = rgb_color + green*256
  rgb_color = rgb_color + blue*65536
  function = rgb_color
End Function 
i am not sure why font not respond
but i will try few tricks...

Code: Select all

'set font
			For i = 0 to 12
				SendMessage hsci,SCI_STYLESETFONT, i,cast(LPARAM, strptr("Courier New"))
				SendMessage(hsci,SCI_STYLESETSIZE, i, 9)
			Next 
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: problem with pointers and Classname

Post by aurelVZAB »

Strange things i get from VirusTotal
may i ask ..Is that false positive ?
Detection ratio: 5/72
Security vendor Result Update
SymantecMobileInsight failure 20211119

Malwarebytes malicious 20220102
Avira malicious 20220102
AhnLab-V3 malicious 20220102
VBA32 malicious 20211231
MaxSecure malicious 20211231
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: problem with pointers and Classname

Post by aurelVZAB »

i am not sure why svintilla not respond on font
so do i need to use api to set font ?

CreateFont(0-(Size*CyPixels)/72,0,0,0,Bold,Italic,Underline,StrikeThru,ANSI_CH
dodicat
Posts: 7967
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: problem with pointers and Classname

Post by dodicat »

aurelVZAB wrote:RGB function it seems that not work in GUI mode so i made my own

Code: Select all

Function RGBX(byval red as INTEGER,byval green as INTEGER,byval blue as INTEGER) as integer
  dim rgb_color as integer
  rgb_color = red
  rgb_color = rgb_color + green*256
  rgb_color = rgb_color + blue*65536
  function = rgb_color
End Function 
i am not sure why font not respond
but i will try few tricks...

Code: Select all

'set font
			For i = 0 to 12
				SendMessage hsci,SCI_STYLESETFONT, i,cast(LPARAM, strptr("Courier New"))
				SendMessage(hsci,SCI_STYLESETSIZE, i, 9)
			Next 
Here is an easy way to set fonts:

Code: Select all


#include "windows.bi"

Function Set_Font (Font As String,Size As long,Bold As long,Italic As long,Underline As long,StrikeThru As long) As HFONT
    Dim As HDC hDC=GetDC(HWND_DESKTOP)
    Dim As long CyPixels=GetDeviceCaps(hDC,LOGPIXELSY)
    ReleaseDC(HWND_DESKTOP,hDC)
    Return CreateFont(0-(Size*CyPixels)/72,0,0,0,Bold,Italic,Underline,StrikeThru,ANSI_CHARSET _
    ,OUT_TT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_DONTCARE,Font)
End Function

Dim  As HFONT  myFont=Set_Font("Courier New",30,1,1,0,0)

var mainwindow=CreateWindowEx(0,"#32770","Main.",WS_OVERLAPPEDWINDOW or WS_VISIBLE or WM_HSCROLL,200,200,800,600,0,0,0,0)
var edit=createwindowex(0,"edit","TEXT -"  , WS_CHILD or WS_VISIBLE or WS_BORDER Or WS_CHILD Or WS_HSCROLL Or WS_VSCROLL Or ES_AUTOHSCROLL Or ES_AUTOVSCROLL Or ES_MULTILINE ,25,25,750,525,MainWindow,0,0,0)

SendMessage(edit,WM_SETFONT,Cast(WPARAM,myFont),0)

dim as  MSG emsg

While GetMessage( @emsg, 0, 0, 0 )
    
    TranslateMessage( @emsg )
    DispatchMessage( @emsg )
    
    Select Case emsg.hwnd
    Case mainwindow
        Select Case emsg.message
        Case 273 : PostQuitMessage(0)
        End Select
    End Select
    wend 
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: problem with pointers and Classname

Post by aurelVZAB »

thanks dodicat
i have used above mothod in few languages including C and that
method work ..i mean that something is wrong with string pointer casting
maybe is better in last version so i i will try again
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: problem with pointers and Classname

Post by aurelVZAB »

Yes that function would be good solution for function like
ControlFont()
but here is a easy way ..just use pointer ..heh
i must say that i am very confused with pointer usage in fB they are little bit different than in o2 i used
but fine work well !!!!

Code: Select all

dim fontName as string
            dim sfont as any ptr
            fontname = "Consolas"
            sfont = strptr(fontname)

			For i = 0 to 12
				SendMessage hsci,SCI_STYLESETFONT, i,cast(LPARAM, sFont)
				SendMessage(hsci,SCI_STYLESETSIZE, i, 10)
			Next 
Post Reply