Posted to tcl by patthoyts at Fri Oct 10 14:16:03 GMT 2008view raw
- set compiler [tcc::new]
- $compiler compile {
- #include <tcl.h>
- #include <tk.h>
- #define _WIN32_WINNT 0x0502
- #include <windows.h>
- static HWND
- GetHWNDFromObj(Tcl_Interp *interp, Tcl_Obj *pathObj)
- {
- Tk_Window tkwin = (Tk_Window)NULL;
- Window window = None;
- HWND hwnd = (HWND)NULL;
- tkwin = Tk_NameToWindow(interp, Tcl_GetString(pathObj),
- Tk_MainWindow(interp));
- if (tkwin != NULL)
- window = Tk_WindowId(tkwin);
- if (window != None)
- hwnd = Tk_GetHWND(window);
- if (hwnd != NULL && Tk_IsTopLevel(tkwin))
- hwnd = GetParent(hwnd); /* toplevels have a wrapper window */
- return hwnd;
- }
- int PrintDlg(ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
- {
- PRINTDLG pd;
- int oldMode = 0;
- ZeroMemory(&pd, sizeof(PRINTDLG));
- pd.lStructSize = sizeof(PRINTDLG);
- pd.hwndOwner = GetHWNDFromObj(interp, parent);
- pd.Flags = PD_ALLPAGES | PD_NOSELECTION;
- oldMode = Tcl_SetServiceMode(TCL_SERVICE_ALL);
- if (PrintDlg(&pd)) {
- Tcl_Obj *resObj = NULL;
- LPDEVNAMES lpDev = NULL;
- lpDev = (LPDEVNAMES)GlobalLock(pd.hDevNames);
- if (lpDev != NULL) {
- LPCTSTR szName = ((LPCTSTR)lpDev) + lpDev->wDeviceOffset;
- if (szName && *szName) {
- resObj = Tcl_NewStringObj(szName, -1);
- }
- }
- if (resObj != NULL) {
- Tcl_SetObjResult(interp, resObj);
- }
- }
- Tcl_SetServiceMode(oldMode);
- return TCL_OK;
- }
- }
- $compiler command PrintDlg PrintDlg