-
'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?
-
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
-
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;
}
}
-
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
-
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
-
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.