Draw string from main prog to window created by dll

Windows specific questions.
Post Reply
rvm
Posts: 7
Joined: Oct 08, 2017 3:34

Draw string from main prog to window created by dll

Post by rvm »

I'm trying to draw string from the main program to a window that is created by a dll but nothing is displayed. Is there any way to access that window from the main program?
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Draw string from main prog to window created by dll

Post by D.J.Peters »

viewtopic.php?f=3&t=23398&p=206070&hili ... ll#p206070

The primary problem are screen stuff in the *.exe and in the *.dll are two different things and both exists parallel !

If you create the window inside your dll you can export wrappers for all FB graphics command you need to share with the .exe !

Joshy

pseudo code in your dll:

Code: Select all

declare sub drawstring(x as integer, y as integer, text as string, colour as ulong) export
  draw string (x,y),text,colour
end sub
rvm
Posts: 7
Joined: Oct 08, 2017 3:34

Re: Draw string from main prog to window created by dll

Post by rvm »

Thank you for your response. So there is no way to interact with the screen directly from the main program? My idea was to create a DLL that would provide functions that create form controls like buttons, input boxes, radio buttons, drop down lists, etc. so the main program would then interact with the application user directly. But if the main program cannot access the window created by the DLL then this idea can’t work. However, I can make the functions available in a .bi file to be included into the main program, but that means those functions would be compiled over and over again with the development of every application that uses them. That will work but the DLL would be more efficient. Any other ideas?
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Draw string from main prog to window created by dll

Post by jj2007 »

If it's under Windows, I wonder if the dll could subclass its window to a WndProc obtained from the main program. Sounds like fun...
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Draw string from main prog to window created by dll

Post by dodicat »

Simple stuff (windows/fonts).
windll.bas

Code: Select all

 

'windll.bas
'compile -dll
#Include Once "windows.bi"
 function fb_Set_Font (Font As String,Size As Integer,Bold As Integer,Italic As Integer,Underline As Integer,StrikeThru As Integer) As HFONT export
  Dim As HDC hDC=GetDC(HWND_DESKTOP)
  Dim As Integer 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

function createmain(x as long,y as long,w as long,h as long) as any ptr export
    static as any ptr win:win=CreateWindowEx( 0,"#32770", "Main Window", WS_OVERLAPPEDWINDOW Or WS_VISIBLE, x,y,w,h, 0, 0, 0, 0 )
    return win
end function

function createedit(x as long,y as long,w as long,h as long,main as any ptr,message as string) as any ptr export
static as any ptr editin
editin  = CreateWindowEx( 0, "EDIT", message, WS_VISIBLE Or WS_CHILD Or WS_BORDER or ES_MULTILINE or WS_VSCROLL or WS_HSCROLL, x, y,w,h,main, 0, 0, 0 )
return editin
end function
 
And use the dll

Code: Select all

#include "windows.bi"
#inclib "windll"
Declare Function fb_Set_Font (Font As String,Size As Integer,Bold As Integer=0,Italic As Integer=0,Underline As Integer=0,StrikeThru As Integer=0) As HFONT
Declare Function createmain(x As Long,y As Long,w As Long,h As Long) As Any Ptr
Declare Function createedit(x As Long,y As Long,w As Long,h As Long,main As Any Ptr,message as string) As Any Ptr


Dim shared As HFONT   MyChoice
Dim As MSG msg
Dim As String  fontname
Dim As Integer fontsize=20
fontname="Times new Roman"
MyChoice=fb_Set_Font(fontname,fontsize,,TRUE)

Dim As Any Ptr mainwin=createmain(10,10,1024,768)
Dim As Any Ptr edit=createedit(10,10,1000,720,mainwin,"Write or paste stuff here")
SendMessage(edit,WM_SETFONT,Cast(WPARAM,MyChoice),0)


While GetMessage( @msg, 0, 0, 0 )
    TranslateMessage( @msg )
    DispatchMessage( @msg )
    
    Select Case msg.hwnd
    Case mainwin
        Select Case msg.message
        Case 273
            End
        End Select
    End Select
Wend

sub finish destructor
DeleteObject(Cast(HGDIOBJ,MyChoice))
end sub  
rvm
Posts: 7
Joined: Oct 08, 2017 3:34

Re: Draw string from main prog to window created by dll

Post by rvm »

Problem solved. I decided to see if a static library would work instead of the dynamic library and it does. I guess since we now have only one executable instead of two all routines within it have access to the same screen.

Thanks to all for your input.
Post Reply