Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / WinAPI Code. Rightclick menus(works :D )

Author
Message
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 15th Mar 2009 05:43 Edited at: 15th Mar 2009 05:49
Ok I Just pretty much understand winapi now (well the basics of it) and so i was looking around msdn and i found this. its really easy really it uses 3 dll calls. and returns the number of the menu.

heres some simple code that will make it and return the menu number and make a submenu


the only problem is you can't position it at mousex mousey because mousex and mousey are relative to the window position which i can't seem to get :/ and the positions you pass to windows arn't so you have to use MouseX()+WindowX,mouseY()+WindowY(if you know how to get window x and window y tell me that would be helpful)


This requires 5 of the windows constants i have a txt file with all the constants i uploaded it if you want it.

New Site! Check it out \/

Attachments

Login to view attachments
Quirkyjim
16
Years of Service
User Offline
Joined: 18th Oct 2008
Location: At my computer
Posted: 15th Mar 2009 18:49
It's acting kind of strangely for me:

When I right-click, the popup pops up left and up of my cursor, not at it.

~QJ
That's what they WANT you to think...
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 15th Mar 2009 20:11
this is probebly because of (like I said) the coordanets of mousex and mousey are relativeto the window position so you need to get the position of the window(
which I have been researching and I think you need to call getwindowrect and get the coordanets from that.

New Site! Check it out \/
Quirkyjim
16
Years of Service
User Offline
Joined: 18th Oct 2008
Location: At my computer
Posted: 15th Mar 2009 21:32
Ah! I see...

~QJ
That's what they WANT you to think...
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 15th Mar 2009 22:33 Edited at: 15th Mar 2009 22:34
yes oh and when you call dll 1,"GetwindowRect",window,pointer

two things pointer is the pointer to a memblock that recieves the info. it is stored at dwords and position 0 is x 4 is y 8 is X2 12 is y2 like the coordanets to a box that you draw


and it is 4 off on the x and 23 off on the y for the border and titlebar because that is the coordanet of the actual window not the border and everything(btw if you use set window layout 0,0,0 you won't have the 4 and 23 offset because theres not border or titlebar) but if you add the 4 and 23 to the x and y it shows up great (i tested it) oh and i found out that arrays don't work for the constants. well the mf_string and mf_popup were but the other three won't so i just changed it to no dims and just globals(if you use darkedit you can use globals)

New Site! Check it out \/
feiting shadow
18
Years of Service
User Offline
Joined: 12th Sep 2006
Location:
Posted: 23rd Mar 2009 07:47
Hmmm, unsure if this will help, but if you can find a mouseX and mouseY position thing inside of the windows functions, pass the handle to the desktop in it to find the actual mouse location.

I think it's either 0 or 1, but my memory is not recalling if it could even be some random 32 bit value (64 probably in vista and xp64). Retrieve that handle and you should fix your prob

Signed
------
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 23rd Mar 2009 22:16
ya well at this point I don't knowthe api call the get mousex and yl

New Site! Check it out \/
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 23rd Mar 2009 22:30
You'll want to use GetCursorPos in the user32.dll . That should return the screen coordinates of the mouse pointer. You'll need to create a memblock to holder a pointer for a POINT structure:



Enjoy your day.
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 24th Mar 2009 00:37
sweet! Thanks! That's very useful

New Site! Check it out \/
AndrewT
18
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 24th Mar 2009 00:42
Have you figured out how to process messages, or are you just going to do it manually, i.e. check where the mouse clicks and where the options are, and see which option the user selected. I implemented some menu bar functions with the WinAPI DLLs in DBP awhile back but I had no idea how to handle messages; I couldn't get PeekMessage() to do anything.

Thank you.
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 24th Mar 2009 05:18
i think i might have based this off of yours but this isn't regular menu bar. i'm using CreatePopupMenu() not CreateMenu() with create popup menu you can use TrackPopupMenu(Menu,Constants(use returnCMD and LeftButton see bellow),X,Y,0,Parentwindow,NULL) to show the menu


if you set TPM_RETURNCMD then the function returns the selected menu. so you don't need peekmessage or anything. once researched it's quite easy to do.

if it was your dbp code i based this off of then thanks cuz this was fun to research all of this hahaha. msdn is so helpful

New Site! Check it out \/

Login to post a reply

Server time is: 2025-05-16 20:35:56
Your offset time is: 2025-05-16 20:35:56