Thread: 'ctrl + a' & font dialog

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    380

    'ctrl + a' & font dialog

    In my progam I would like to beable to select all text using ctrl+a. How do you do that using a resource script?

    Also, I have my problem display a font chooser dialog. When the dialog is shown the Font and Font Style fields are blank and the Size field has a random number. The Effects section of the dialog are checked by default. When I tried the example that is in the Winprog tutorial all fields are filled and the Effect section unchecked. What could be causing this?
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  2. #2
    Registered User sean345's Avatar
    Join Date
    Mar 2002
    Posts
    346
    For the font dialog, are you initializing all the variables in the struct you pass to the function. If not things will be set to wierd random values.

    What you want for the "ctrl + a" is a keyboard accelerator. Check some documentation for this to find out how to do it with your compiler and resource editor.

    - Sean
    If cities were built like software is built, the first woodpecker to come along would level civilization.
    Black Frog Studios

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    Do I have to load the keyboard accelators myself using LoadAccelators?

    I don't see anything wrong with the code, but here's the code anyways:
    Code:
    void doSelectFont(HWND hwnd)
    {
    	CHOOSEFONT cf = {sizeof(CHOOSEFONT)};
    	LOGFONT lf;
    
    	GetObject(g_hfFont, sizeof(LOGFONT), &lf);
    
    	cf.Flags = CF_EFFECTS | CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS;
    	cf.hwndOwner = hwnd;
    	cf.lpLogFont = &lf;
    	cf.rgbColors = g_rgbText;
    
    	if(ChooseFont(&cf))
    	{
    		HFONT hf = CreateFontIndirect(&lf);
    		if(hf)
    		{
    			g_hfFont = hf;
    		}
    		else
    		{
    			MessageBox(hwnd, "Font creation failed!", "Error", MB_OK | MB_ICONEXCLAMATION);
    		}
    
    		g_rgbText = cf.rgbColors;
    	}
    }
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Accelerator keys is a matter of implementation via resource editor. One solution is to add a key down message in whatever window you want to catch the keys.

    As for a font dialog, consider LOGFONT.

    Kuphryn

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    I believe I have solved my font problem by adding
    g_hfFont = GetStockObject(DEFAULT_GUI_FONT);
    to the WM_CREATE section of my program.

    I still haven't learnt how to use accelators with my resource editor. Prehaps you could help me? I'm using the free Borland 5.5 command line tools along with the Borland Resource Workshop 4.5.

    Thank you
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  6. #6
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    for the accelerator business, why not just do it at runtime? thats the way i always do it. then you really know what's going on in your code. here's an example:

    Code:
    ACCEL acc;
    HACCEL accTable;
    
    acc.cmd=ID_ACCEL; //whatever ID you want, #define it in header
    acc.fVirt=FCONTROL | FVIRTKEY; //FVIRTKEY must be included
    acc.key=65; //ASCII code for 'A'
    
    accTable=CreateAcceleratorTable((LPACCEL)&acc,1);
    
    while(GetMessage(&Msg, NULL, 0, 0) > 0)
        {
    		if(!TranslateAccelerator(hwndMain, accTable, &Msg))
    		{
    			TranslateMessage(&Msg);
    			DispatchMessage(&Msg);
    		}
    	}
    in my opinion its a better way to do it, and then you can also add more accelerators at runtime. keep in mind that the message is sent to whatever window has focus at the time, so you'll have to subclass any window that you want to be able to receive the message. a good idea is to forward all messages from child windows to the parent window, so that you only have to make the code once.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem with my font manager
    By hannibar in forum C Programming
    Replies: 1
    Last Post: 03-07-2006, 08:03 AM
  2. make Child Dialog not Popup?
    By Zeusbwr in forum Windows Programming
    Replies: 5
    Last Post: 04-08-2005, 02:42 PM
  3. char copy
    By variable in forum C Programming
    Replies: 8
    Last Post: 02-06-2005, 10:18 PM
  4. The relation between Font Size & Dialog Units
    By Templario in forum Windows Programming
    Replies: 4
    Last Post: 02-27-2003, 05:32 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM