Thread: Hacked OST2 methods (not hacking)--need advice

  1. #1
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    University of Waterloo

    Hacked OST2 methods (not hacking)--need advice

    These are some methods I'm using in my OpenScript2.0 programming language's IDE that are really bad hacks and I was wondering if there are better ways of doing them. Any advice would be great.

    Notice: Method #2 has been fixed, found out about keyboard accelerators

    Hack method #1
    When the user right clicks on either the workspace area or in the code, I force a left depression and release, then set a timer for 50 ms later to show the menu at the new position.....this seems like a really bad hack, as some computers might take longer than 50 ms to calculate the left click and increasing that time would cause an annoying delay.
    For visual people:
        			case NM_RCLICK:
        // This is a bad hack...try and fix it
     		 	 SetTimer(hWnd,0,50,0);		// Showing the menu 50 ms later
    That's where i process the right click
        // Bad method of doing this...but until I find a better method this will have to work
        //  What this is is when you right click it sets a timer to wait for a little bit,
        //  allowing the mouse position to update, and then it places the menu at that position
        	case WM_TIMER:
        		case 0:
        			POINT CursorPos;
     			HWND Child=(HWND)SendMessage(MDIClient,WM_MDIGETACTIVE,0,0);
     		KillTimer(hWnd,wParam);		// Kill the timer right away
    and that's the timer call

    The reason why I have to do this is because when you right click, say, in the workspace tree, and....damnit, lemme get a screeny cuz i can't explain it very well in text. Please note Figure 1 shown below.
    In the top box is just the normal view of the workspace tree.
    In the bottom box is when the user right clicks on somewhere else. Now, if I didn't have that left click thing in there, notice how "Workspace" still has the selection ants around it? If I didn't have that code in there, the menu would pop up, you'd think you were doing something to "movin.ost" but actually you're modifying the workspace one....this gets really annoying, thus the reason why i put the code in there.
    It basically just emulates the user clicking the item first and then right clicking...but this just seems so hackish to me...

    Hack method #2--FIXED
    This method is also another hack that I put together just for it to work, but because it's a hack has some drawbacks.
    Take in to account the following code:
        // Very bad method for having a ctrl-F5/F5 hotkey.  Look in to getting real hotkeys
        //  working.
        			UPDATESTATUSBAR("Saving all files",0);
       		 if(KEY_DOWN(VK_CONTROL))	CompileProject(MainWindow,1);
     		 else		 		 CompileProject(MainWindow,-1);
    This is inside my WinMain message loop....REALLY bad idea, heh. What that code does is it tests (asynchronously) whether the user pressed the f5 key, and also if they pressed the control key, so it can either compile or run and compile the project...

    What would be a much better alternative is to set up hotkeys in my IDE, but I have no idea (and no experience) with creating and using hotkeys inside of win32 applications. Anyone have any info on this or perhaps bookmarked a good msdn directory about them?

    Those are the 2 hacks I've found in my IDE so far as I'm going through the code (cleaning it up so it's a bit more memory efficient), I'll post more as they're found and if I can't figure 'em out.

    Thanks in advance
    Last edited by jverkoey; 07-23-2004 at 05:04 PM.

  2. #2
    Registered User
    Join Date
    Jul 2003
    Im not sure if i understand problem #1 correct. But couldnt you check the mouse pos in WM_CONTEXTMENU and if the mouse is over the workspace show the popupmenu, or else send it to DefaultWindowProc

  3. #3
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    University of Waterloo
    No, I dont' have any trouble figuring out where it's focused, i have trouble with when i want to get which item in the list is actually selected, it's not the one you right click on, because to change the selection, you have to left click.....if that makes any sense?

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Is this a tree view control? I would have thought a tree view control would change selection on right click, but that's probably just because I am used to that behaviour.

    Anyway, if you are using a tree view control and need to manually change the selection on right click you can use the following pseudo code:

    // Get the mouse position
    // Convert to tree view client coordinates
    ScreenToClient(hwndTreeView, &;
    // Get the tree view item underneath the mouse pointer
    TreeView_HitTest(hwndTreeView, &hti);
    // Select it
    TreeView_SelectItem(hwndTreeView, hti.hItem);
    // show your popup menu here
    If your not using a tree view control...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Lesson #5 - Methods
    By oval in forum C# Programming
    Replies: 1
    Last Post: 05-04-2006, 03:09 PM
  2. Need advice: catch exceptions or call methods to check bits?
    By registering in forum C++ Programming
    Replies: 1
    Last Post: 10-03-2003, 01:49 PM