July 07, 2024, 12:34:30 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


MDI / CONTEXT MENU /ACCELERATORS

Started by LarryMc, January 02, 2012, 10:40:12 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

LarryMc

Ran into a stumbling block with the IDE

I'm hoping one of you have done this in C++ before and can provide me with a clue to what I'm doing wrong or not doing at all.

My main program has a messageloop which contains the following piece of code per the windows SDK:
if (!TranslateMDISysAccel(hwndMDIClient, &msg) &&
                !TranslateAccelerator(hwndFrame, hAccel, &msg))
            TranslateMessage(&msg)
            DispatchMessage(&msg)
endif

and I'm providing the proper handles.

When I create a mdi child window I properly create my accelerators with the ADDACCELERATOR command.
In my handler I create a context menu (right click popup menu)
when I open the menu and select any of the options I get the results I expect via the
case @idmenupick
select @menunum

structure I have set up.
However, when I use the accelerator keys defined for that MDI window nothing happens.

The accelerator keys defined for the mdi frame window work fine.

If someone can help me I'll have to come up with some sort of work around to get the results I want.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

aurelCB

January 03, 2012, 03:04:45 AM #1 Last Edit: January 03, 2012, 03:15:18 AM by aurelCB
Hi..
I never before work with this things and just catch some time to see
what is all about.
I use example MDI and here is my code:
'an example of how MDI windows can be used with EBASIC
'define the frame window and a maximum of 20 child windows
'requires Emergence BASIC 1.0 or greater
'Compile as a WINDOWS target

DEF frame,neww[ 20 ]:WINDOW
DEF run,wndcnt,x:INT
DEF left,top,width,height,panes[4]:INT
DEF stattext:STRING

'open the frame
OPENWINDOW frame,0,0,640,480,@MDIFRAME|@MINBOX|@MAXBOX|@SIZE|@MAXIMIZED,0,"MDI Demo",&wndproc
'Use INSERTMENU with @MDIFRAME windows so we dont erase the standard menu
BEGININSERTMENU frame,0
MENUTITLE "&File"
MENUITEM "&New",0,1
MENUITEM "&Quit",0,2

ENDMENU

'add a status bar
CONTROL frame,@STATUS,"Status",0,0,0,0,0,2
'get the windows client size and set up 4 panes for the status window
GETCLIENTSIZE frame,left,top,width,height
panes = width - 120,width - 80,width - 40,-1
CONTROLCMD frame,2,@SWSETPANES,4,panes
'set the initial pane text
'stattext = USING("& #### ####","Client size",width,height)
CONTROLCMD frame,2,@SWSETPANETEXT,0,stattext
CONTROLCMD frame,2,@SWSETPANETEXT,1,"Pane 2"
CONTROLCMD frame,2,@SWSETPANETEXT,2,"Pane 3"
CONTROLCMD frame,2,@SWSETPANETEXT,3,"Pane 4"
AddAccelerator frame,@FCONTROL|@FVIRTKEY,ASC("N"),1


REM load a toolbar from a bitmap file
DEF hbitmap:UINT
DEF tbArray[10]:INT
tbArray = 2,3,4,0,5,6,7,0,8,9
hbitmap = LOADIMAGE(GETSTARTPATH + "toolbar.bmp",@IMGBITMAP | @IMGMAPCOLORS)
IF LOADTOOLBAR(frame,hbitmap,98,tbArray,10,@TBTOP | @TBFROMHANDLE)
CONTROLCMD frame,98,@TBSETLABELS,"New|Open|Save|Cut|Copy|Paste|Print|Help||"
CONTROLCMD frame,98,@TBRESIZE
ENDIF


run = 1
wndcnt = 0
'process messages until someone closes us
WAITUNTIL run = 0
CLOSEWINDOW frame
DELETEIMAGE hbitmap,@IMGBITMAP
END

'our window subroutine for the frame and child windows
SUB wndproc
SELECT @CLASS
CASE @IDCLOSEWINDOW
run = 0
CASE @IDCONTROL
SELECT @CONTROLID
CASE 2
OpenNewWindow()
ENDSELECT


CASE @IDMENUPICK
SELECT @MENUNUM
CASE 1
OpenNewWindow()
CASE 2
run = 0
ENDSELECT



case @IDSIZE
'resize the status window and update the panes
'check to make sure the status window exists
'it may not have been added to the window yet.
if CONTROLEXISTS(frame,2)
'Tell the status window we are sizing
CONTROLCMD frame,2,@SWRESIZE

'get the client size of the window and
'display it in the status bar
'calculate the right edges of the other panes.
GETCLIENTSIZE frame,left,top,width,height
panes = width - 120,width - 80,width - 40,-1
CONTROLCMD frame,2,@SWSETPANES,4,panes
'stattext = USING("& #### ####","Client size",width,height)
CONTROLCMD frame,2,@SWSETPANETEXT,0,stattext
endif
'resize the toolbar
IF CONTROLEXISTS(frame,98)
CONTROLCMD frame,98,@TBRESIZE
ENDIF

ENDSELECT
RETURN
ENDSUB

SUB OpenNewWindow
wndcnt = -1
FOR x=0 TO 19
IF neww[x] = 0
wndcnt = x
x=19
ENDIF
NEXT x
IF wndcnt > -1
name$ = "Untitled"+LTRIM$(STR$(wndcnt+1))
OPENWINDOW neww[wndcnt],@USEDEFAULT,0,0,0,@SIZE|@MINBOX|@MAXBOX,frame,name$,&childwndproc
'CONTEXTMENU neww[wndcnt],@MOUSEX,@MOUSEY
'MENUITEM "Set childW Yellow",0,99
'MENUITEM "Set childW White",0,100
'ENDMENU
ENDIF
RETURN
ENDSUB

SUB childwndproc
SELECT @CLASS
CASE @IDCLOSEWINDOW
CLOSEWINDOW #<WINDOW>@HITWINDOW

CASE @IDRBUTTONUP
    CONTEXTMENU neww[wndcnt],@MOUSEX,@MOUSEY
MENUITEM "Set childW Yellow",0,99
MENUITEM "Set childW White",0,100
ENDMENU
'with accelerator you can set child to yellow
    AddAccelerator neww[wndcnt],@FCONTROL|@FVIRTKEY,ASC("W"),99   

CASE @IDMENUPICK
SELECT @MENUNUM
CASE 99
SETWINDOWCOLOR #<WINDOW>@HITWINDOW,rgb(220,220,0)
CASE 100
SETWINDOWCOLOR #<WINDOW>@HITWINDOW,rgb(255,255,255)
ENDSELECT


ENDSELECT
ENDSUB


It looks that on this way accelerators work... ;)

PS. I think that we all are used to MDI frame of editor but when i start
create ABasic scintilla editor i decide to use single interface ,maybe im not
in right but work with MDI i find little bit complex then only with tabs.
Just my opinion, however great work on editor Larry... :)

LarryMc

I tried your modified example and it did indeed work the way you have it coded.
The big difference is that your window array is  global to the program and is there all the time.

In mine there is no array and each child window is a new instance of a class.

I'm in the middle of implementing a scheme that I'm pretty sure will work for me.

Thanks for looking at it for me.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

The scheme I've implemented works.
I assigned all the accelerators to the main window frame.
I already had all my main menu handlers set up as OnMenuPick subroutines.
I just added OnMenuPick routines for the accelerator declarations.

For all I know it might be the way I was suppose to do it to begin with.

Regardless, the bottom line is it works and I understand how it works.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

aurelCB

QuoteIn mine there is no array and each child window is a new instance of a class.
Aha i see...
Ok then you probably use pointers for this job.
As i say before i first time use this i will see how i will implement something similiar in ABasic to. ;)