I'm a little confused. I found this: http://msdn.microsoft.com/library/default..../usingmenus.asp
And in the link it does this.
I was trying to do a similar thing in my own code.Code:HFONT GetAFont(int fnFont) { static LOGFONT lf; // structure for font information // Get a handle to the ANSI fixed-pitch font, and copy // information about the font to a LOGFONT structure. GetObject(GetStockObject(ANSI_FIXED_FONT), sizeof(LOGFONT), &lf); // Set the font attributes, as appropriate. if (fnFont == BOLD) lf.lfWeight = FW_BOLD; else lf.lfWeight = FW_NORMAL; lf.lfItalic = (fnFont == ITALIC); lf.lfItalic = (fnFont == ULINE); // Create the font, and then return its handle. return CreateFont(lf.lfHeight, lf.lfWidth, lf.lfEscapement, lf.lfOrientation, lf.lfWeight, lf.lfItalic, lf.lfUnderline, lf.lfStrikeOut, lf.lfCharSet, lf.lfOutPrecision, lf.lfClipPrecision, lf.lfQuality, lf.lfPitchAndFamily, lf.lfFaceName); }
Doesn't do anything. But that's because, hey, it crashes! Before it hits the break, it calls some procedure that um, does some wierd stuff, and then crashes I think with an unhandled exception (that may have been raised in this procedure). Disassembly ends up like this yo.Code:case WM_CREATE: { LOGFONT lFont; HFONT hFont; ::GetObject (::GetStockObject(ANSI_FIXED_FONT), sizeof LOGFONT, &lFont); _tcsncpy (lFont.lfFaceName, _T("Courier New"), sizeof lFont.lfFaceName); hFont = ::CreateFontIndirect(&lFont); break; }
That CALL Dialog_T.004013CC there at the end does it. Um. Yeah, that CALL is made unconditionally, and I can't understand it. But the wierd part is, after being all mystified by the fact that it was crashing, I made my LOGFONT structure static, like in MSDN's code, and it did not crash. In fact, the disassembly does not contain that last call.Code:0040118E . 6A 40 PUSH 40 00401190 . 8D4C24 38 LEA ECX,DWORD PTR SS:[ESP+38] 00401194 . 68 94814000 PUSH Dialog_T.00408194 00401199 . 51 PUSH ECX 0040119A . E8 3C020000 CALL Dialog_T.004013DB 0040119F . 83C4 0C ADD ESP,0C 004011A2 . 8D5424 18 LEA EDX,DWORD PTR SS:[ESP+18] 004011A6 . 52 PUSH EDX 004011A7 . FF15 04804000 CALL DWORD PTR DS:[<&GDI32.CreateFontInd> 004011AD . 5F POP EDI 004011AE . 33C0 XOR EAX,EAX 004011B0 . 5E POP ESI 004011B1 . 8B4C24 6C MOV ECX,DWORD PTR SS:[ESP+6C] 004011B5 . 33CC XOR ECX,ESP 004011B7 . E8 10020000 CALL Dialog_T.004013CC 004011BC . 83C4 70 ADD ESP,70 004011BF . C2 1000 RETN 10
See, not there. So, my question is:Code:00401166 . 6A 40 PUSH 40 00401168 . 68 94814000 PUSH Dialog_T.00408194 0040116D . 68 DCAC4000 PUSH Dialog_T.0040ACDC 00401172 . E8 04020000 CALL Dialog_T.0040137B 00401177 . 83C4 0C ADD ESP,0C 0040117A . 68 C0AC4000 PUSH Dialog_T.0040ACC0 0040117F . FF15 04804000 CALL DWORD PTR DS:[<&GDI32.CreateFontInd> 00401185 . 33C0 XOR EAX,EAX 00401187 . 83C4 10 ADD ESP,10 0040118A . C2 1000 RETN 10
Why does my LOGFONT structure have to be static, and if possible, why did it crash in the first place? Nothing in the CreateFontIndirect/LOGFONT documentation about such craziness. All replies appreciated.
http://msdn.microsoft.com/library/default....ontext_4rw4.asp
http://msdn.microsoft.com/library/default....ontext_1wmq.asp



LinkBack URL
About LinkBacks


