Advertisement

Win32 Growing Pains

Started by December 21, 2000 03:53 PM
14 comments, last by Orpheum 24 years, 1 month ago
I don''t understand your explanation of what is wrong...

Here''s some sample code. It is extremely simple and just has a dialog with a single edit control. Comment out/uncomment the approriate lines to change the font to either 14-point Arial, 9-point symbol, or whatever the system default is. No error checking or resource cleanup is done for brevity sake. You''ll need to kill the app (with task manager or something) to get rid of it. You''ll need to create the dialog resource in VC or whatever of course.

-Mike

  #include <windows.h>#include "resource.h"int CALLBACK DialogProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){    if (WM_INITDIALOG == message)    {        HWND    edit = GetDlgItem(hWnd, IDC_EDIT1);        LOGFONT logfont;        HFONT   hFont;        HDC     hDC = GetDC(edit);        ZeroMemory(&logfont, sizeof(logfont));// 14 point arial//        logfont.lfHeight = -MulDiv(14, GetDeviceCaps(hDC, LOGPIXELSY), 72);//        strcpy(logfont.lfFaceName, "Arial");// 9 point symbol        logfont.lfHeight = -MulDiv(9, GetDeviceCaps(hDC, LOGPIXELSY), 72);        strcpy(logfont.lfFaceName, "Symbol");        ReleaseDC(edit, hDC);        hFont = CreateFontIndirect(&logfont);        SendMessage(edit, WM_SETFONT, (WPARAM) hFont, TRUE);        SetWindowText(edit, "The quick brown fox");        return TRUE;    }    return FALSE;}int WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int){    return DialogBox(instance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DialogProc);}  


Couple of things... The below code is identical to mine with the exception of the -MulDiv(...) part. That and I do all of this font crap just under CreateWindowEx() in WM_NCCREATE. Would the location of this code matter? I see you do yours in WM_INITDIALOG.... is an edit box a dialog?? My edit box lives on a tool band so I cant have a big box with an edit control on it. I appreciate your help so far Mike, no one else seems to be skilled in Win32. =P heheh
There is no spoon.
Advertisement
All this dialog stuff is there simply to provide a small example and is irrelvant to the problem of setting fonts (the edit control is a child of the dialog box, it isn''t a dialog box itself). INITDIALOG is just a convient place to do it - I know that the edit control has been fully created at this point. The MulDiv stuff is just to convert from points to "logical units" (which I''ve never figured out what are).

You need to place the code that sets the font after the point at which the edit box is created. It sounds like someplace you''ve got a call to CreateWindow that creates the edit box. Put the font stuff right after that call.

If this has something to do with your subclassed edit controls in the other thread, and you''re trying to set the font in the *edit box''s* WM_NCCREATE hander, then you may be doing it to early - the edit box code may be resetting the font on you. In this case I would try setting the font *after* you''ve passed the WM_CREATE (not NCCREATE) message to the original window proc. Or better yet, on the first WM_PAINT. The point is to make sure the edit box is fully initialized to it''s default state before you go mucking with it.

Good luck.

-Mike


Crap crap crap crap..... I had the font stuff in the WM_NCCREATE of the toolband but obviosly that didnt work. I then placed it in WM_CREATE of the toolband all by itself and still nothing. As a last resort I placed the code in WM_PAINT of the toolband and still nothing!! I posted on MSDN, but no one answered (gamedev forums kick ass!)... as this is my first edit control I have no experience to draw on, and my book is completly useless for this project. I dont want to give up, but Ive been mucking with just this font trouble and the damn enter and backspace problem from the other thread for 3 days now. Sometimes I really hate programming.
There is no spoon.
Orpheum I soooo hear ya on that hate programming stuff but if you willing to part with your source and e-mail me a copy I might be able to help you out by digging through the Windows API Bible. My e-mail is joshbussdieker@crosswinds.net

"Don''t make me come down there..." - GOD
"Don't make me come down there..." -GOD
i don''t have time to read the entire thread, but i think this will help:

SendDlgItemMessage(hWnd, IDC_EDIT, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), 0);

This topic is closed to new replies.

Advertisement