Hi Guys, Sorry another quick question..
Has anyone else experienced the same problem ...
using the code ...
function custom_Messagebox ()
y&=MessageBox_show (hwnd_, %true)
msgbox "I am Here"
function = %true
end function
If i call the function from a button click it all works fine .
The messagebox form closes its self (using both Dialog End and FF_closeform)
and the msgbox will appear.
my problem is I use the same function called from a thread somewhere, and the msgbox is never reached!!! in fact its as if the form will not close.
any one had somehting simular?
I have even stuck a message box on the form close call back so i know for sure its being closed. just the message box doesnt pop up.
I am having a hard time following exactly what your question is. Are you saying that when you try to close a Form and display your custom messagebox in that Form's WM_CLOSE message handler that the Form will not close?
If that is the question then you need to realize this: In the WM_CLOSE handler you would return %TRUE to prevent the Form from continuing to close. So, if your custom messagebox returns TRUE and you return that result from the WM_CLOSE handler then the Form will not close.
For example,
Function FORM1_WM_CLOSE ( _
hWndForm As Dword _ ' handle of Form
) As Long
Local nResult As Long
nResult = custom_Messagebox()
Function = nResult
' If nResult is TRUE then the Form will not close
End Function
Also, never use Dialog End to close FireFly forms. Always use FF_CloseForm.
Also, what do you mean by "called from a thread somewhere"?
Sorry I know im rubbish at explaining myself...
'------------------------------------------------------------------------------------------------------------------------
Function HostMessage (hwnd_ As Long, TitleMessage As String , Message As String , OkButton As String , CancelButton As String ) As Long
gTitleMessage = TitleMessage
gMessage = Message
gOkButton = OkButton
gCancelButton = CancelButton
y&=MessageBox_show (hwnd_, %true)
'never gets here.
MsgBox "here"
Function = gResult
End Function
'------------------------------------------------------------------------------------------------------------------------
Function MESSAGEBOX_OK_BN_CLICKED ( _
ControlIndex As Long, _ ' index in Control Array
hWndForm As Dword, _ ' handle of Form
hWndControl As Dword, _ ' handle of Control
idButtonControl As Long _ ' identifier of button
) As Long
gResult = %true
FF_CloseForm hwnd_messagebox, %true
End Function
Main Problem for some reason i dont get to "'never gets here." when HostMessage is called from within a thread.
if i call HostMessage from a callback such as a button on a form, then it all works fine.
hope this explains the problem better.
Still having big issues with this one :-(
any ideas?
I really don't know. If you feel comfortable sending me your project (or an example project showing the problem), I would be more than happen to take a look at it.
hehe I thought you said that...
Il rustle something up when i have time.
Thanks.
Paul.
Ok Created an example, and a little relieved that the bug appears here too
the example should explain whats going on.
Paul.
[attachment deleted by admin]
Hi Paul,
The problem is that you are trying to display GUI elements from within your thread. You should not do that. GUI elements like Forms, Controls, etc, should be displayed from the main thread of your application. Any threads that you start should only be "worker threads" that do some tasks and the "notify" the main thread if a message box of Form needs to be displayed. You do this notification by posting a message to the main thread.
In your FireFly project, create a unique user defined message that you will use to notify the main thread to do something:
%MSG_USER_MESSAGEBOX = %WM_USER + 100
From within your thread, whenever you need to display the messagebox Form then you would SendMessage or PostMessage your user defined message back to the main thread.
SendMessage HWND_FORM1, %MSG_USER_MESSAGEBOX, 0, 0
- or -
PostMessage HWND_FORM1, %MSG_USER_MESSAGEBOX, 0, 0
In the CUSTOM handler for your main Form you would handle the incoming user defined message liek this:
Function FORM1_CUSTOM ( _
hWndForm As Dword, _ ' handle of Form
wMsg As Long, _ ' type of message
wParam As Dword, _ ' first message parameter
lParam As Long _ ' second message parameter
) As Long
Select Case wMsg
Case %MSG_USER_MESSAGEBOX
HostMessage( hwnd_form1,"Message box" , "hello","Chicken", "Soup")'
MsgBox "Never gets here"
End Select
End Function
Hope that helps!
\
Brilliant.
although im starting to remember of having to do this before...
ohwell. thanks for looking into this
Paul.