>>** This >>GlobalUnlock( pDevMode ) >> >>** Replace with this >>GlobalUnlock( hDevMode ) >>>
lh_Wnd = FindWindowEx( This.hPrintDlg, 0, '#32770', 'General' ) > lh_Wnd = FindWindowEx( lh_Wnd, 0, 'SHELLDLL_DefView', 0 ) > lh_Wnd = FindWindowEx( lh_Wnd, 0, 'SysListView32', 'FolderView' )>where W9x probably has a combo, not a listview/folderview.
If (nResult != 0) hDevMode = CToBin( substr( sPrintDlg, 9, 4 ), '4rs' ) hDevNames = CToBin( substr( sPrintDlg, 13, 4 ), '4rs' ) ** Make sure we don't get a NULL handle to DEVMODE, otherwise do not process If (hDevMode != 0) pDevMode = GlobalLock( hDevMode ) cPrinterName = sys( 2600, pDevMode, 32 ) GlobalUnlock( hDevMode ) nLen = at( chr(0), cPrinterName ) - 1 If (nLen > 0) cPrinterName = left( cPrinterName, nLen ) endif ? 'Selected Printer:', cPrinterName GlobalFree( hDevMode ) endif ** Same thing for DEVNAMES If (hDevNames != 0) GlobalFree( hDevNames ) endif else ** Check for the PrintDlg error by calling CommDlgExtendedError() endifNow, in the handle to DEVNAMES structure, there is one field (wDeviceOffset) that also pointed to the printer name. I haven't try this, but you may need to check from that offset, because the "printer name" return from the DEVMODE is limited to 32 chars. If the name is longer than 32 chars, it might be stored in the DEVNAMES. But, again, I haven't try this myself because I don't have any printer that has names longer than 32. So, please do some more checking.
** Skeleton code Do case Case ( WIN_9X_ME ) do this Case ( WIN_2K_XP ) do that Otherwise do other thing elseAbout that FindWindowEx() things, you don't have to worry. It works under W9x too. However, all the classname to be searched for is different. First I already make it to look for the right target. The code will first react on printer dialog activation.
If (tn_Msg == 0x06) && WM_ACTIVATE If (t_wParam == 0) lc_ClassName = space( 64 ) ln_Len = GetClassName( t_lParam, @lc_ClassName, 64 ) If (ln_Len > 0) and ('#32770' $ lc_ClassName) ** If you want to make it more safety, then do one more checking here If (GetParent( t_lParam ) == _VFP.hWnd) ** Here the handle to printer dialog belongs to our app (our child) This.hPrintDlg = t_lParam UnBindEvents( th_Wnd, 6 ) ** Set the timer to look for the ListView child handle SetTimer( _VFP.hWnd, 1, 50, 0 ) endif endif endif elseIf the timer doesn't find any of it then it will return 0. You can continue looking for several time (use counter) then kill the timer. Also you can remove the Window name if you want, it's also safer. You can also wrap it in IF..ENDIF if you want
lh_Wnd = FindWindowEx( This.hPrintDlg, 0, '#32770', 'General' ) If (lh_Wnd != 0) lh_Wnd = FindWindowEx( lh_Wnd, 0, 'SHELLDLL_DefView', 0 ) If (lh_Wnd != 0) lh_Wnd = FindWindowEx( lh_Wnd, 0, 'SysListView32', 0 ) endif endifFor W9X, Although it is still doable from VFP, I'm sorry to say you better skip it <*g*>. It's not that I don't want to tell you, but it needs to do a subclassed (also a hook for more robust solution). And simply can't be done from VFP. Searching the "Combo List Box" using timer is not reliable. Because the listbox is not a direct child of the Printer Dialog. Having said that, it's not that we can not subclassed right from VFP, but I really don't want start it because it's highly dangerous!