How can i use variables declared in WinMain function in WndProc function ?

New to FreeBASIC? Post your questions here.
kcvinu
Posts: 232
Joined: Oct 07, 2015 16:44
Location: Keralam, India

How can i use variables declared in WinMain function in WndProc function ?

Post by kcvinu »

Hi,
I am playing with some win api code. But i can't access variables in WinMain function from WndProc function. How can i use variables declared in WinMain function in WndProc function ? Thanks in advance.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: How can i use variables declared in WinMain function in WndProc function ?

Post by MrSwiss »

Short answer: you can't (they are local to the procedure, only!)

There are cases (few, with WIN-API), where you have to resort to:
"shared" aka: GLOBAL, at module-level declared variables, to get things working.

Code: Select all

...
Dim shared as HWND WHandle
...
jcfuller
Posts: 325
Joined: Sep 03, 2007 18:40

Re: How can i use variables declared in WinMain function in WndProc function ?

Post by jcfuller »

Yes it is possible.
James

Code: Select all


#include once "windows.bi"

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 )

'':::::
function WndProc ( byval hWnd as HWND, _
                   byval wMsg as UINT, _
                   byval wParam as WPARAM, _
                   byval lParam as LPARAM ) as LRESULT
    
    Static s1 AS ZString Ptr  
     
    select case( wMsg )
        case WM_CREATE    
            DIM As CREATESTRUCT Ptr cstruct  
            cstruct = CAST(CREATESTRUCT Ptr,lParam)
            s1 = cstruct->lpCreateParams      
            exit function
            
        case WM_PAINT
            dim rct as RECT
            dim pnt as PAINTSTRUCT
            dim hDC as HDC
            hDC = BeginPaint( hWnd, @pnt )
            GetClientRect( hWnd, @rct )
            
            DrawText( hDC, _
                      s1, _
                      -1, _
                      @rct, _
                      DT_SINGLELINE or DT_CENTER or DT_VCENTER )
            
            EndPaint( hWnd, @pnt )
            
            exit function            
        
        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 lng As Long 
    dim s1 As ZString * 30 => "Hello, world From WinMain"

    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 = @"HelloWin"
    end with
          
    if( RegisterClass( @wcls ) = FALSE ) then
       MessageBox( null, "Failed to register wcls", "Error", MB_ICONERROR )
       exit function
    end if
    
    hWnd = CreateWindowEx( 0, _
                            @"HelloWin", _
                           "The Hello Program", _
                           WS_OVERLAPPEDWINDOW, _
                           CW_USEDEFAULT, _
                           CW_USEDEFAULT, _
                           CW_USEDEFAULT, _
                           CW_USEDEFAULT, _
                           NULL, _
                           NULL, _
                           hInstance, _
                           @s1 )
                          

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

end function

MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: How can i use variables declared in WinMain function in WndProc function ?

Post by MrSwiss »

@jcfuller,

all your code is proofing is, that we can (locally) reuse the same 'name', without conflict.
I'm quite sure that you are referring to: s1 ...
But, they aren't even of the same type, in the two procedures:
  • while the one, in WinMain, is a ZString (dynamic)
    is the other, in WndProc, a ZString Ptr (static)
Better read up on: Variable Scope in Programmer's Guide.
jcfuller
Posts: 325
Joined: Sep 03, 2007 18:40

Re: How can i use variables declared in WinMain function in WndProc function ?

Post by jcfuller »

Maybe a poor choice of data type in this example. Could produce buffer overun if assigned new value somewhere else. Has nothing to do with names and scope.
I've been using this concept for 20+yrs (various languages) normally with types(structs) or classes dimmed in WinMain filled out with data I need in assorted functions called from the callabck.
It gives me a warm fuzzy for not using globals.
I use it primarily with Dialogs which is even easier than sdk windows.

James
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: How can i use variables declared in WinMain function in WndProc function ?

Post by MrSwiss »

All very interesting, but still beside the OP's question (accessing local variables, by other procedure)!

Your method is a complex workaround, to avoid GLOBALS (here, we are in Beginners).

What I mean to say is:
Sometimes, in order to make a point, one has to sacrifice some measure of: "technical correctness".
This, to be clearly understud, without "muddying the Waters" further (with: advanced methods).
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: How can i use variables declared in WinMain function in WndProc function ?

Post by dodicat »

I like jcfuller's method.

What are FREEbasic's built in global variables?

I can think of one (err), it can be a getter or setter.
Using it as a setter, I can copy the value of a button into it.
It then pops up in the WinProc with this button value.

Code: Select all


#include once "windows.bi"

declare function        WinMain     ( byval hInstance as HINSTANCE, _
                                      byval hPrevInstance as HINSTANCE, _
                                      byval szCmdLine as zstring ptr, _
                                      byval iCmdShow as integer ) as integer
                                  
                                  
	end WinMain( GetModuleHandle( null ), null, Command( ), SW_NORMAL )

'':::::
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 )
    
    '========== GET THE BUTTON ==============
    case hwnd
        Case WM_COMMAND
            Select Case lParam  
            Case err  '=button
                beep
        messagebeep(64)
    end select
    '=========================
    
    case WM_CREATE  
      
            exit function

        case WM_PAINT
    		dim rct as RECT
    		dim pnt as PAINTSTRUCT
    		dim hDC as HDC
          
            hDC = BeginPaint( hWnd, @pnt )
            GetClientRect( hWnd, @rct )
            
            DrawText( hDC, _
            		  "Passed value of button = " +str(err), _
            		  -1, _
                      @rct, _
                      DT_SINGLELINE or DT_CENTER or DT_VCENTER )
            
            EndPaint( hWnd, @pnt )
            
            exit function            
       

    	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 zstring ptr, _
                   byval iCmdShow as integer ) as integer    
     
    dim wMsg as MSG
    dim wcls as WNDCLASS     
    dim hWnd as HWND
    
    dim as hwnd button

    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 = @"HelloWin"
    end with
          
    if( RegisterClass( @wcls ) = FALSE ) then
       MessageBox( null, "Failed to register wcls", "Error", MB_ICONERROR )
       exit function
    end if
    
    hWnd = CreateWindowEx( 0, _
    			 		   @"HelloWin", _
                           "The Hello Program", _
                           WS_OVERLAPPEDWINDOW, _
                           CW_USEDEFAULT, _
                           CW_USEDEFAULT, _
                           CW_USEDEFAULT, _
                           CW_USEDEFAULT, _
                           NULL, _
                           NULL, _
                           hInstance, _
                           NULL )
     Button = CreateWindowEx(NULL, "Button", "Click for Beep - Beep", WS_VISIBLE Or WS_CHILD, 10, 70, 200, 24, HWND, NULL, NULL, NULL)
      err=cast(integer,button)                    

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

end function
  
pretty crude eh!
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: How can i use variables declared in WinMain function in WndProc function ?

Post by MrSwiss »

dodicat wrote:What are FREEbasic's built in global variables?
Are you seriously asking???

Dim Shared As (whatever)

__ = GLOBAL
deltarho[1859]
Posts: 4305
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: How can i use variables declared in WinMain function in WndProc function ?

Post by deltarho[1859] »

Another way is to post a message from WinMain to WndProc.

I have used dodicat's code as a template to pass x = 5.

The sky is the limit if x is an address to a User Defined Type. <smile>

Code: Select all

#Include Once "windows.bi"

Declare Function  WinMain(Byval hInstance As HINSTANCE, _
                          Byval hPrevInstance As HINSTANCE, _
                          Byval szCmdLine As Zstring Ptr, _
                          Byval iCmdShow As Integer ) As Integer
End WinMain( GetModuleHandle( null ), null, Command( ), SW_NORMAL )

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_User + 999
      Dim As Ulong x
      x = wParam
      Print "In WndProc: ";"x = ";x
    ' #########################

    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 Zstring Ptr, _
                   Byval iCmdShow As Integer ) As Integer    
     
    Dim wMsg As MSG
    Dim wcls As WNDCLASS     
    Dim hWnd As HWND
    
    Dim As hwnd button

    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 = @"HelloWin"
  End With
        
  If( RegisterClass( @wcls ) = False ) Then
     MessageBox( null, "Failed To register wcls", "Error", MB_ICONERROR )
     Exit Function
  End If

  hWnd = CreateWindowEx( 0, _
                     @"HelloWin", _
                     "The Hello Program", _
                      WS_OVERLAPPEDWINDOW, _
                      500, _
                      500, _
                      200, _
                      200, _
                      NULL, _
                      NULL, _
                      hInstance, _
                      NULL )

  ' ###################################
  Dim As Ulong x = 666
  Print "In WinMain: ";"x = ";x
  PostMessage Hwnd, WM_USER + 999, x, 0
  ' ###################################

  ShowWindow( hWnd, iCmdShow )
  UpdateWindow( hWnd )

  While( GetMessage( @wMsg, NULL, 0, 0 ) <> False )  
    TranslateMessage( @wMsg )
    DispatchMessage( @wMsg )
  Wend

  Function = wMsg.wParam

End Function
deltarho[1859]
Posts: 4305
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: How can i use variables declared in WinMain function in WndProc function ?

Post by deltarho[1859] »

dodicat wrote "built in".
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: How can i use variables declared in WinMain function in WndProc function ?

Post by MrSwiss »

They are called "Intrinsic Defines":

__FUNCTION__ a.s.o. (global, since its value changes, depending on procedure) ...

and, of course "built in"!
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: How can i use variables declared in WinMain function in WndProc function ?

Post by MrSwiss »

OK, to let "the cat out of the bag" ... it's of course a MACRO (and not a variable)!

Just wondered, how long it takes, for the smarter ones, to figure it out. ;-D

Afaik, there are no "built in" global variables ...
jcfuller
Posts: 325
Joined: Sep 03, 2007 18:40

Re: How can i use variables declared in WinMain function in WndProc function ?

Post by jcfuller »

This is more precisely how I use this method of encapsulation.
James

Code: Select all

'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
'                    This source created by dlg2src
'                    Target: FreeBASIC 1.50
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
#Include Once "Windows.bi"
#include once "win/commctrl.bi"
DECLARE FUNCTION WinMain (BYVAL hInstance AS HINSTANCE, _
                          BYVAL hPrevInstance AS HINSTANCE, _
                          BYVAL szCmdLine AS ZSTRING PTR, _
                          BYVAL nCmdShow AS LONG) AS LONG
    END WinMain(GetModuleHandle(NULL), NULL, COMMAND(), SW_NORMAL)

DECLARE FUNCTION WndProc (BYVAL hwnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT
'==============================================================================
FUNCTION FbCreateFont(BYREF szFaceName AS STRING, BYVAL lPointSize AS LONG, _
    BYVAL lWeight AS LONG = 0, BYVAL bItalic AS UBYTE = FALSE, BYVAL bUnderline AS UBYTE = FALSE, _
    BYVAL bStrikeOut AS UBYTE = FALSE, BYVAL bCharSet AS UBYTE = DEFAULT_CHARSET) AS HFONT

    DIM tlf AS LOGFONT
    DIM hDC AS HDC = GetDC(HWND_DESKTOP)

    GetDeviceCaps(hDC, LOGPIXELSX)
    tlf.lfHeight = -MulDiv(lPointSize,.GetDeviceCaps(hDC, LOGPIXELSY), 72)
    tlf.lfWidth  =  0
    tlf.lfEscapement = 0 
    tlf.lfOrientation = 0
    tlf.lfWeight = lWeight
    tlf.lfItalic = bItalic
    tlf.lfUnderline = bUnderline
    tlf.lfStrikeOut = bStrikeOut
    tlf.lfCharSet = bCharset
    tlf.lfOutPrecision = OUT_TT_PRECIS
    tlf.lfClipPrecision = CLIP_DEFAULT_PRECIS
    tlf.lfQuality = DEFAULT_QUALITY
    tlf.lfPitchAndFamily = FF_DONTCARE
    tlf.lfFaceName = szFaceName

    ReleaseDC(HWND_DESKTOP, hDC)
    FUNCTION = CreateFontIndirect(@tlf)
END FUNCTION
'==============================================================================
Sub FbCenterWin(Byval hWnd As HWND)
    Dim As RECT WndRect
    Dim As Long x,y
    GetWindowRect(hWnd, @WndRect)
    x = (GETSYSTEMMETRICS(SM_CXSCREEN) - (WndRect.RIGHT-WndRect.LEFT))/2
    y = (GETSYSTEMMETRICS(SM_CYSCREEN) - (WndRect.Bottom-WndRect.Top+GETSYSTEMMETRICS(SM_CYCAPTION)))/2
    SetWindowPos (hWnd, NULL, x, y, 0, 0, SWP_NOSIZE OR SWP_NOZORDER)
End Sub
'==============================================================================
'------------------------------------------------------------------------------
'From José Roca's CWindow framework renamed to avoid conflicts
'------------------------------------------------------------------------------
SUB FbSetWindowClientSize (BYVAL hwnd AS HWND, BYVAL nWidth AS LONG, BYVAL nHeight AS LONG, BYVAL rxRatio AS SINGLE = 1, BYVAL ryRatio AS SINGLE = 1)

    DIM rc AS RECT, rcTemp  AS RECT
    SetRect(@rc, 0, 0, nWidth * rxRatio, nHeight * ryRatio)
    DIM hMenu AS HANDLE = GetMenu(hwnd)
    DIM dwStyle AS DWORD = GetWindowLongPtrW(hwnd, GWL_STYLE)
    AdjustWindowRectEx(@rc, dwStyle, (hMenu <> NULL), GetWindowLongPtrW(hwnd, GWL_EXSTYLE))
    IF hMenu <> NULL THEN
        rcTemp = rc
        rcTemp.Bottom = &H7FFF
        SendMessage(hwnd, WM_NCCALCSIZE, 0, CAST(LPARAM, @rcTemp))
        rc.Bottom = rc.Bottom + rcTemp.Top
    END IF
    IF (dwStyle AND WS_HSCROLL) = WS_HSCROLL THEN
        rc.Bottom = rc.Bottom + GetSystemMetrics(SM_CYHSCROLL)
    END IF
    IF (dwStyle AND WS_VSCROLL) = WS_VSCROLL THEN
        rc.Right = rc.Right + GetSystemMetrics(SM_CXVSCROLL)
    END IF
    DIM cx AS LONG = rc.Right - rc.Left
    DIM cy AS LONG = rc.Bottom - rc.Top
    SetWindowPos(hwnd, NULL, 0, 0, cx, cy, SWP_NOZORDER OR SWP_NOMOVE OR SWP_NOACTIVATE)
END SUB
'==============================================================================
CONST IDD_DLG1 = 1000
CONST IDC_BTN1 = 1001
CONST IDC_BTN2 = 1002
'==============================================================================
Type DataInfoType
    Dim As zstring * 32 szData
    Dim As Long lDataOne
    Dim As Long lDataTwo
End Type
'==============================================================================
Function WinMain(Byval hInstance as HINSTANCE, _
                 Byval hPrevInstance As HINSTANCE, _
                 Byval szCmdLine As ZSTRING PTR, _
                 Byval nCmdShow As LONG ) as LONG
    Dim wMsg As MSG
    Dim wcls As WNDCLASS
    Dim hWin as HWND
    Dim hCtl as HWND
    Dim hFont As HFONT
    Dim As DataInfoType DataInfo 
    DataInfo.szData = "WinMain"
    DataInfo.lDataOne = 1
    DataInfo.lDataTwo = 2
    With wcls
       .style         = CS_HREDRAW OR CS_VREDRAW
       .lpfnWndProc   = @WndProc
       .cbClsExtra    = 0
       .cbWndExtra    = 0
       .hInstance     = hInstance
       .hbrBackground =  CAST(HBRUSH,(COLOR_BTNFACE+1))
       .hIcon         = LoadIcon( NULL, IDI_APPLICATION )
       .hCursor       = LoadCursor( NULL, IDC_ARROW )
       .lpszMenuName  = NULL
       .lpszClassName = @"FbSDKWindow"
    End With
    If( RegisterClass( @wcls ) = FALSE ) Then
        MessageBox( NULL, "Failed to register wcls", "Error", MB_ICONERROR )
        Exit Function
    End If

    hFont = FbCreateFont("Tahoma",9)
    hWin = CreateWindowEx(0,"FbSDKWindow","IDD_DLG",&H10CC0800,0,0,314,146,0,0,hInstance,@DataInfo)
    FbSetWindowClientSize(hWin,550,256)
    hCtl = CreateWindowEx(0,"Button","Button one",&H50010000,91,168,119,39,hWin,CAST(HMENU,IDC_BTN1),hInstance,NULL)
    SendMessage(hCtl,WM_SETFONT,CAST(WPARAM,hFont),CAST(LPARAM,0))
    hCtl = CreateWindowEx(0,"Button","Button two",&H50010000,347,168,112,39,hWin,CAST(HMENU,IDC_BTN2),hInstance,NULL)
    SendMessage(hCtl,WM_SETFONT,CAST(WPARAM,hFont),CAST(LPARAM,0))
    FbCenterWin(hWin)
    ShowWindow(hWin,nCmdShow)
    
    While(GetMessage(@wMsg,NULL,0,0) <> 0)
        If IsDialogMessage (hWin,@wMsg) = 0 Then
            TranslateMessage(@wMsg)
            DispatchMessage(@wMsg)
        End If
    Wend
    DeleteObject(CAST(HFONT,hFont))
    Function = wMsg.wParam
End Function
'==============================================================================
Function ButtonOneClick(Byval hWnd As HWND) As long
    Dim As DataInfoType Ptr DataInfo
    Dim AS string sOut
    DataInfo = GetProp(hWnd,"DATAINFO")
    sOut = DataInfo->szData + CHR$(10) + Str$(DataInfo->lDataOne) + CHR$(10) + Str$(DataInfo->lDataTwo)
    MessageBox(hWnd,strptr(sOut),"DataInfo",MB_OK)
    DataInfo->szData = "Button One"
    DataInfo->lDataOne = 100
    DataInfo->lDataTwo = 200
    Function = 1
End Function
'==============================================================================
Function ButtonTwoClick(Byval hWnd As HWND) As long
    Dim As DataInfoType Ptr DataInfo
    Dim As string sOut
    DataInfo = GetProp(hWnd,"DATAINFO")
    sOut = DataInfo->szData + CHR$(10) + Str$(DataInfo->lDataOne) + CHR$(10) + Str$(DataInfo->lDataTwo)
    MessageBox(hWnd,strptr(sOut),"DataInfo",MB_OK)
    DataInfo->szData = "Button Two"
    DataInfo->lDataOne = 200
    DataInfo->lDataTwo = 400
    Function = 2
End Function
'==============================================================================
Function WndProc(Byval hWnd As HWND, _
                 Byval wMsg As UINT, _
                 Byval wParam As WPARAM, _
                 Byval lParam As LPARAM ) As LRESULT
    Select Case wMsg
        Case WM_CREATE
            DIM As CREATESTRUCT Ptr cstruct  
            cstruct = CAST(CREATESTRUCT Ptr,lParam)
             SetProp(hWnd,"DATAINFO",cstruct->lpCreateParams)
        Case WM_COMMAND
            Select Case LOWORD(wParam)
                Case IDCANCEL 
                    IF HIWORD(wParam) = BN_CLICKED THEN
                        SendMessage hwnd, WM_CLOSE, 0, 0
                        Exit Function
                    END IF
                Case IDC_BTN1
                    ButtonOneClick(hWnd)
                Case IDC_BTN2
                    ButtonTwoClick(hWnd)        
             End Select
        Case WM_DESTROY
            RemoveProp(hWnd,"DATAINFO")
            PostQuitMessage(0)
            Exit Function
    End Select
    FUNCTION = DefWindowProc(hWnd, wMsg, wParam, lParam)
End Function

dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: How can i use variables declared in WinMain function in WndProc function ?

Post by dodicat »

Nice neat method DeltaRho[]
I have tested with string messages also, they are easily passed to the wndproc.
also jcfuller, neat.

I like the idea of packing the (any pointer) hwnd with extra information, and posting it off.
Mr Swiss
I mean built-in variables which can be used without declaring new shared variables.
Err is an example.
So is __FB_ARGV__ , but only in the main module.
Example for __FB_ARGV__ :

Code: Select all


screen 19
dim as any ptr n=imagecreate(100,100)

circle n,(50,50),40,3,,,,f


__FB_ARGV__[0]=n

dim as any ptr m=imagecreate(100,100)

circle m,(50,50),40,4,,,,f
__FB_ARGV__[1]=m

put(200,200),__FB_ARGV__[0],pset
put(300,300),__FB_ARGV__[1],pset

sleep
imagedestroy n
imagedestroy m

  
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: How can i use variables declared in WinMain function in WndProc function ?

Post by MrSwiss »

dodicat,

Err = Function, see: KeyPgErr
__FB_ARGV__ = Macro, see: KeyPgDdfbargv

None of them, are global variables.
Post Reply