wndclass.cbsize = sizeof(wndclass);
wndclass.style = cs_hredraw | cs_vredraw;
wndclass.lpfnwndproc = wndproc;
wndclass.cbclsextra = 0;
wndclass.cbwndextra = 0;
wndclass.hinstance = hinstance;
wndclass.hicon = null;
wndclass.hcursor = loadcursor(null,idc_arrow);
wndclass.hbrbackground = (hbrush)getstockobject(ltgray_brush);
wndclass.lpszmenuname = null;
wndclass.lpszclassname = "printdemo";
wndclass.hiconsm = null;
registerclassex (&wndclass);
hwmain=createwindow (wndclass.lpszclassname,null,ws_overlappedwindow,
cw_usedefault,cw_usedefault,500,568,null,null,hinstance,null);
hmenu=createmenu();
hmenua=createmenu();
appendmenu(hmenua,mf_string,id_file_print,"print");
appendmenu(hmenu,mf_popup,(uint)hmenua,"file");
setmenu(hwmain,hmenu);
showwindow (hwmain,icmdshow);
updatewindow (hwmain);
while (getmessage (&msg,null,0,0))
{
translatemessage(&msg);
dispatchmessage(&msg);
}
return msg.wparam ;
}
/* this function is called by the windows function dispatchmessage() */
lresult callback wndproc (hwnd hwnd, uint imsg, wparam wparam, lparam lparam)
{
hdc hdc;
paintstruct ps;
static printdlg pd;
static docinfo dci;
static lptstr lpszdocname="print test";
switch (imsg)
{
case wm_create:
pd.lstructsize=sizeof(pd);
pd.hwndowner=hwnd;
pd.hdevmode=null;
pd.hdevnames=null;
pd.flags=pd_returndc|pd_hideprinttofile |pd_returndefault;
pd.nfrompage=1;
pd.ntopage=1;
pd.nminpage=1;
pd.nmaxpage=1;
pd.ncopies=1;
dci.cbsize=sizeof(dci);
dci.lpszdocname=lpszdocname;
dci.lpszoutput=null;
dci.lpszdatatype=null;
dci.fwtype=0;
return 0;
case wm_command:
switch (loword(wparam))
{
case id_file_print:
if (!printdlg(&pd))
return 0;
hdc=pd.hdc;
startdoc(hdc,&dci);
startpage(hdc);
draw(hdc);
endpage(hdc);
enddoc(hdc);
break;
}
return 0;
case wm_paint:
hdc=beginpaint(hwnd,&ps);
draw(hdc);
endpaint(hwnd,&ps);
return 0;
case wm_destroy :
postquitmessage(0);
return 0;
}
return defwindowproc (hwnd, imsg, wparam, lparam) ;