win32 gui

This is a discussion on win32 gui within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I have made a button, when pressed program should activate some shortcuts. I am using the GetAsyncKeyState function to ...

  1. #1
    Registered User
    Join Date
    Dec 2004
    Location
    The Netherlands
    Posts
    91

    win32 gui

    Hi,

    I have made a button, when pressed program should activate some shortcuts. I am using the GetAsyncKeyState function to find out what button is pressed. But where should I put this, currently I have put it this way, but when activated the GUI stops responding untill the shortcut button has pressed:

    Code:
    BOOL CALLBACK DialogProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {	
    	switch (message)
    	{    
    	case WM_COMMAND:
    		switch (LOWORD(wParam))
    		{
    		case IDC_ACTIVATE:
    			while(1) { while(!GetAsyncKeyState(vKey)) Sleep(50);
    				/* Do Stuff.. */
    				break;
    			}
    			break;
    		}
    	break;
    	return 0;
    }
    Any info about how I can fix this is welcome,
    apsync

    [edit]I am using Windows XP as OS and VC++6 as compiler[/edit]
    Last edited by apsync; 12-21-2006 at 12:54 PM.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,592
    You can't just halt the windows message loop by throwing in a while(1) and a sleep.

    Everything has to be, get in, do some small amount of work based on the current message and get out again.

    So for instance
    Code:
    BOOL CALLBACK DialogProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {	
    	static bActivated = FALSE;  // a bit of persistent memory for this function
    
    	switch (message)
    	{    
    	case WM_COMMAND:
    		switch (LOWORD(wParam))
    		{
    		case IDC_ACTIVATE:
    			bActivated = TRUE;
    			break;
    		}
    	break;
    	case WM_TIMER: // maybe WM_KEYDOWN, WM_CHAR, etc etc - RTM to find suitable ones
    		if ( bActivated && GetAsyncKeyState(vKey) ) {
    			/* Do Stuff.. */
    		}
    	break;
    	}
    	return 0;
    }
    Obviously, in response to some other message, you set the flag to FALSE again.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    If you want your application to respond to the key even if it's not the current app, perhaps RegisterHotKey() is what you're looking for.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  4. #4
    Registered User
    Join Date
    Dec 2004
    Location
    The Netherlands
    Posts
    91
    Thanks for the replies. I see what you mean Salem, I have a totally different view now, thanks.

    Also, Cactus_Hugger, I will check out what RegisterHotKey function does and if it is any good in my situation, but for now I will stick with Salem's solution.

  5. #5
    Registered User
    Join Date
    Dec 2004
    Location
    The Netherlands
    Posts
    91
    >>// maybe WM_KEYDOWN, WM_CHAR, etc etc - RTM to find suitable ones
    Can you provide a link, been searching on msdn but couldnt find it. Isn't 'message identifiers' the right keyword for it?

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,592
    Since you're using VC6, just point at a message identifier and press F1

    Or point at a message identifier, right click and press "goto definition".
    That will take you to the windows header file containing a whole bunch of them, where you can then F1 all the ones which might interest you.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User
    Join Date
    Dec 2004
    Location
    The Netherlands
    Posts
    91
    That helps, thank you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. win32 GUI components
    By abraham2119 in forum Windows Programming
    Replies: 5
    Last Post: 06-18-2009, 10:18 AM
  2. Win32 API GUI problems
    By Cha0sBG in forum Windows Programming
    Replies: 7
    Last Post: 06-05-2009, 04:35 PM
  3. Looking for free win32 gui (resource) editor
    By umen242 in forum Windows Programming
    Replies: 1
    Last Post: 05-22-2008, 03:49 AM
  4. How can I pass arguments through a GUI (win32)?
    By bikr692002 in forum C++ Programming
    Replies: 2
    Last Post: 04-08-2006, 05:17 PM
  5. Strings in Win32 GUI
    By maxorator in forum Windows Programming
    Replies: 2
    Last Post: 09-26-2005, 06:55 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21