April 29, 2024, 04:55:44 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


ONMESSAGE - Access Violation

Started by Allan, June 05, 2009, 03:50:48 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Allan

June 05, 2009, 03:50:48 PM Last Edit: June 05, 2009, 03:53:18 PM by Allan
I was getting an ACCESS VIOLATION when I closed my Window using the ONMESSAGE events.

The problem was using the same SUB as the  ONMESSAGE Main,@IDCLOSEWINDOW,&EndProgram
for the Menu Item QUIT and also for a Button CLOSE.
ONMENUPICK Main,200,&EndProgram
ONCONTROL Main, BTN_EXIT, 0, &EndProgram

I changed to a different SUB  for the Menu and Button
ONMENUPICK Main,200,&ExitProgram
ONCONTROL Main, BTN_EXIT, 0, &ExitProgram

Still had the Access Violation Messages in the Debug panel.

Worked it out that the message que was where the answer was and used a POSTMESSAGE to make it work without an Access Violation appearing in the Debug Panel.

' window using the ONMESSAGE

' ONMESSAGE Main,@IDCLOSEWINDOW,&EndProgram
' ONMENUPICK Main,200,&EndProgram
' ONMENUPICK Main,100,&Show
' ONCONTROL Main, BTN_EXIT, 0, &EndProgram

' compile in Debug Mode
' click Exit button or Quit Menu option to close window
' notice in Debug Tab the Access Violation

$MAIN

AUTODEFINE "OFF"

DECLARE IMPORT, PostMessage Alias PostMessageA(hwnd:INT, wMsg:INT, wParam:INT, lParam:INT),INT

CONST BTN_EXIT = 300
CONST WM_CLOSE = 0x10

Window Main

OPENWINDOW Main,0,0,420,275,@SIZE|@MINBOX|@MAXBOX,0,"Window OnMessage",NULL
CONTROL Main,@BUTTON,"Exit",160,20,100,24,0x50000000,BTN_EXIT

BEGINMENU Main
    MENUTITLE "&File"
    MENUITEM "&Show",0,100
    MENUITEM "&Quit",0,200
ENDMENU

CENTERWINDOW Main

' Event messages
ONMESSAGE Main,@IDCLOSEWINDOW,&EndProgram
ONMENUPICK Main,200,&ExitProgram                ' changed to ExitProgram from EndProgram
ONMENUPICK Main,100,&Show
ONCONTROL Main, BTN_EXIT, 0, &ExitProgram       ' changed to ExitProgram from EndProgram

WAITUNTIL Main = 0
END


SUB EndProgram(),INT
CLOSEWINDOW Main
RETURN 0
ENDSUB

SUB Show()
string str1

str1 = "Close Window in Debug mode"
MESSAGEBOX Main, str1, "NOTICE"
' SENDMESSAGE Main, WM_CLOSE, 0, 0          ' Sends message now
PostMessage(Main.hwnd,WM_CLOSE,0,0)       ' puts message on end of Message Que
RETURN 0
ENDSUB

SUB ExitProgram()
PostMessage(Main.hwnd,WM_CLOSE,0,0)       ' puts message on end of Message Que
RETURN 0
ENDSUB


Ionic Wind Support Team

Allan,
That is what the return value is for when processing messages.  Return TRUE if you close the window in response to a menu pick command, windows sends a myriad of messages when you're clicking on a menu, returning TRUE indicates you don't want the default Windows handler to process the message.

SUB ExitProgram()
   Closewindow main
   RETURN TRUE
ENDSUB

Paul.



Ionic Wind Support Team

Allan

Return TRUE

That is much easier to use.

Thanks