-
Help me out for this pals!!!
hi,whoevers is good in window programming.can u ppl help me out for this problem.thanks very much.that is where i can work on to? u can see my coding,
here is my problem,how to write an application to display"welcome" in a different stock fonts?
and one thing,what is stock fonts? plss.....i shall be here for urs answers.thanks
#include<windows.h>
#include"resource.h"
long FAR PASCAL WndProc(HWND ,UINT, WPARAM,LPARAM);
int PASCAL WinMain(HANDLE hInst,HANDLE hPrevInstance,LPSTR lpszCmdLine,int nCmdShow)
{
HWND hWnd;
MSG msg;
WNDCLASS wndclass;
hInstance=hInst;
if(!hPrevInstance)
{
wndclass.style=0;
wndclass.lpfnWndProc=(WNDPROC)WndProc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hInstance=hInst;
wndclass.hIcon=LoadIcon(hInst,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=GetStockObject(WHITE_BRUSH) ;
wndclass.lpszMenuName=MAKEINTRESOURCE(IDR_MENU1);
wndclass.lpszClassName="MyClass";
if(!RegisterClass(&wndclass))
return 0;
}
hWnd=CreateWindow("MyClass","Student Pre-App Form",WS_OVERLAPPEDWINDOW,10,10,300,300,NULL,NULL, hInst,NULL);
ShowWindow(hWnd,nCmdShow);
while(GetMessage(&msg,0,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return(msg.wParam);
}
long FAR PASCAL WndProc(HWND hWnd ,UNIT wMessage, wParam,LPARAM lParam)
{
-
Just one more wrong move.
well for one thing nobody uses long far PASCAl, etc anymore..whrere you getting this code? a Win3.1 book?
make the wndproc this:
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
and make the WinMain into this:
int WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPrevInstance,PSTR lpszCmdLine,int nCmdShow)
-
Stock fonts are some few fonts that can be loaded easily, you use the function
HGDIOBJ GetStockObject(
int fnObject // stock object type
);
where fnObject can be
ANSI_FIXED_FONT Windows fixed-pitch (monospace) system font.
ANSI_VAR_FONT Windows variable-pitch (proportional space) system font.
DEVICE_DEFAULT_FONT (only Windows NT/ 2000): Device-dependent font.
DEFAULT_GUI_FONT Default font for user interface objects such as menus and dialog boxes.
OEM_FIXED_FONT Original equipment manufacturer (OEM) dependent fixed-pitch (monospace) font.
SYSTEM_FONT System font. By default, the system uses the system font to draw menus, dialog box controls, and text.
SYSTEM_FIXED_FONT Fixed-pitch (monospace) system font. This stock object is provided only for compatibility with 16-bit Windows versions earlier than 3.0.
it returns an HGDIOBJ, which you can use to load into a DC using
HGDIOBJ SelectObject(
HDC hdc, // handle to DC
HGDIOBJ hgdiobj // handle to object
);
where you replace hgdiobj with the object you just got, but you can also load a normal font using CreateFont it's like this
HFONT CreateFont(
int nHeight, // height of font
int nWidth, // average character width
int nEscapement, // angle of escapement
int nOrientation, // base-line orientation angle
int fnWeight, // font weight
DWORD fdwItalic, // italic attribute option
DWORD fdwUnderline, // underline attribute option
DWORD fdwStrikeOut, // strikeout attribute option
DWORD fdwCharSet, // character set identifier
DWORD fdwOutputPrecision, // output precision
DWORD fdwClipPrecision, // clipping precision
DWORD fdwQuality, // output quality
DWORD fdwPitchAndFamily, // pitch and family
LPCTSTR lpszFace // typeface name
);
it's quite long to explain how this works, but go to the MSDN library at http://msdn.microsoft.com and search for CreateFont.
anyway, the HFONT object this function returns can be used in SelectObject as shown above
finally, to print the text to the DC, use
BOOL TextOut(
HDC hdc, // handle to DC to print to, using selected font
int nXStart, // x-coordinate of starting position
int nYStart, // y-coordinate of starting position
LPCTSTR lpString, // character string
int cbString // number of characters
);
i think this is self-explanatory
Good luck
Oskilian
-
u didn't really understand the problem,ken.
did u read my question?pls.....try to help me solve it.
thanks.....
-
PART II
to print to the window, you must get the DC (Device Context) associated with the window, using
GetDC(HWND hwnd);
set the hwnd parameter to the HWND that CreateWindow() returns, and you get a DC you can play with as shown above
Good luck
Oskilian
-
sorry,oskilian.i am still have doubt on it.
according to my coding,can u finish up the bottom there on how to implement different stock font? once u finished the program,
maybe i have some hint to know how it works? thanks... help pal!
i am not fully understand the thing u post on the board but i will refer again as i don't understand.Thanks,but pls first give me a example!! u can see my coding,which part is lack of when implement the stock font? thanks
the questions is...write an application to display"welcome" in different stock fonts? i will be glad if u can help me with this pro.
Popular pages
Recent additions