Jiangsheng的CSDN Digest (Dec 2005)[11]

[入库:2006年2月23日] [更新:2007年3月24日]

本文简介:


1、在com中增加一个属性OnStateChange,其类型为IDispatch *并为其添加put方法。

2、在put方法的实现中将传进的DISPATCH型指针赋给自己的成员变量IDispatch *m_pDispatch。

STDMETHODIMP CDvdPlayCtl::put_OnStateChange(IDispatch *newVal)
{
// TODO: Add your implementation code here
m_pDispatch = newVal;
return S_OK;
}

3、定义成员函数void Send_Event(int state, TCHAR * info);在发送事件的函数中添加以下代码:
if (m_pDispatch != NULL)
{
CComVariant* pvars = new CComVariant[2];

pvars[1] = state;//回调函数的第一个参数
pvars[0] = info;//回调函数的第二个参数

DISPPARAMS disp = { pvars, NULL, 2, 0 };
HRESULT hr = m_pDispatch->Invoke(0, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, NULL, NULL, NULL);
delete[] pvars;
}
注意:
1、pvars的填充与函数参数顺序是相反的
4、在htm中如下调用
<script language="JavaScript">

var DvdPlayCtl = new ActiveXObject("DvdPlayCtl.DvdPlayCtl");

DvdPlayCtl.OnStateChange = OnStateChange;
DvdPlayCtl.OnError = OnError;

function OnStateChange(state,info)
{
alert("state change to "+state+" ,"+info);
}
</script>


類似VC的界面中,左邊的樹形控件不是添加一個控件,而是在MainFrm中定義的一個變量,如何做它的雙擊響應事件(VC/MFC 界面)


控件的通知消息是发给父窗口的,但是MFC也支持消息反射,所以你可以在控件的父窗口主框架中处理消息,或者从CTreeCtrl派生一个类来处理反射的消息。参考微软技术文章TN062 消息反射。


如何检测显示器是否处于休眠状态 (Delphi Windows SDK/API )


休眠状态是指用SendMessage(Handle, WM_SYSCOMMAND, SC_MONITORPOWER, -1)关闭的


The GetDevicePowerState function is supposed to retrieve the current power state of the specified device. However, Apps may fail to use GetDevicePowerState on the display, as they can't get a handle on "\\.\Display#", while the # index is 1-based, or "\\.\LCD", for security reasons.

If you are trying to do this on Windows XP, then you can use SetupDiGetDeviceRegistryProperty and Property: SPDRP_DEVICE_POWER_DATA to get the power management information. This is documented in the Windows XP DDK.

The WMI Class Win32_DesktopMonitor does not report the power state. use SPI_GETPOWEROFFACTIVE or DeviceIOControl with IOCTL_VIDEO_GET_POWER_MANAGEMENT will simply reports power management is enabled or not. SPI_GETPOWEROFFACTIVE just determines whether the power-off phase of screen saving is enabled or not.

BTW, you can always use the SetThreadExecutionState or other APIs (you have used) to switch ON the monitor no matter the monitor is in the ON or OFF state.

References

http://msdn.microsoft.com/library/en-us/Display_r/hh/Display_r/VideoMiniport_Functions_b47b2224-5e0b-44af-9d04-107ff1299381.xml.asp

http://msdn.microsoft.com/library/en-us/wmisdk/wmi/win32_desktopmonitor.asp


使用CWebBrowser2的打印功能时,可不可以去掉文件路径的打印(VC/MFC 网络编程 )


如我们打印www.csdn.net主页
在打印出的页面左下脚会有

http://www.csdn.net/

如何去掉,请朋友们帮忙解决

附:打印代码
void CMyDlg::OnBtPrint()
{
// Verify the Web Browser control is valid.
LPDISPATCH lpDispApp = m_wndBrowser.GetApplication();
if(lpDispApp)
{
// Get the HTMLDocument interface.
LPDISPATCH lpDispDoc = m_wndBrowser.GetDocument();
if (lpDispDoc != NULL)
{
// Get the IOleCommandTarget interface so that we can dispatch the command.
LPOLECOMMANDTARGET lpTarget = NULL;
if (SUCCEEDED(lpDispDoc->QueryInterface(IID_IOleCommandTarget,(LPVOID*) &lpTarget)))
{
// Execute the print preview command. The control will handle the print preview GUI.
// OLECMDID_PRINTPREVIEW is defined in "docobj.h".
lpTarget->Exec(NULL, OLECMDID_PRINTPREVIEW, 0, NULL, NULL);
lpTarget->Release();
}
lpDispDoc->Release();
}
lpDispApp->Release();
}
}
 


其实IE是可以设置打印出来的Header和Footer的.

1. 构造一个其实是SafeArray的VARIANT,这个SafeArray包含Header和Footer两个元素,
然后在在Exec的倒数第二个VARIANT参数那里传进去,这样真实打印出来的时候就是
你想要的设置了. 具体设置方法非常复杂,MSDN里面搜索一下
Printing with the Internet Explorer WebBrowser Control,有非常详细论述.Microsoft都说只能Workaround.
2. 当倒数第二个VARIANT参数是NULL的时候,IE会用你在IE里的页面设置.

3. PRINTPREVIEW的时候,无论你在倒数第二个参数设了多么多东西,IE也只会用回IE自己的页面设置. 所以无论你怎么设,通过IE的打印预览,你无法看到你编程设置的Header和Footer, 你设的Header和Footer只有OLECMDID_PRINT才能奏效. 这时可以用虚拟打印机来调试程序的.

4. 也可以Hack一下,打印或者打印预览前保存注册表里面的设置,然后设为你想要的,打印后再恢复回去.页面设置在注册表里的位置MSDN好像有讲,自己也可以搜注册表搜到.

上面讨论以IE6 SP1为准.其他版本的有一定程度上不同

http://support.microsoft.com/support/kb/articles/Q267/2/40.ASP
http://msdn.microsoft.com/workshop/browser/mshtml/reference/constants/idm_print.asp
http://msdn.microsoft.com/workshop/browser/hosting/printpreview/reference/behaviors/headerfooter.asp


请问在ActiveX控件里面怎么做出CScrollView那种可以滚动的效果(VC/MFC ATL/ActiveX/COM )


直接对滚动条进行设置的话就得处理好多消息,还得在画的时候算坐标

本文关键:Jiangsheng的CSDN Digest (Dec 2005)
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top