其次SetTimer和KillTimer的第二個參數nIDEvent也應該一致的。一般來說,SetTimer中nIDEvent需要設爲非0,除非第一個參數hwnd的值爲NULL。
1 SetTimer第一個參數不置NULL,則SetTimer中nIDEvent需要設爲非0值A。如果成功,返回一個非零值,但這並不是這個Timer的id。要確認TimerProc中操作的是否同一個計時器,則需要在TimerProc的參數nIDEvent和A相比較是否相等。這種情況下Timer的操作應該是:
SetTimer(g_wnd, timerid0, 2000, &TimerProc);
///...
void __stdcall TimerProc( HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime)
{
if (idEvent == timerid0)
{
KillTimer(g_wnd, timerid0);
///...
}
}
2 SetTimer的hwnd設爲NULL,nIDEvent將會被忽略。如果成功,返回一個非零值A,這個A就是TimerProc的nIDEvent。這時應該這樣操作:
/// ...
void __stdcall TimerProc( HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime)
{
if (idEvent == timerid0)
{
KillTimer(NULL, timerid0);
///...
}
}
MCI_DGV_OPEN_PARMS mciOpen;
mciOpen.dwCallback = 0L;
mciOpen.wDeviceID = 0;
mciOpen.lpstrDeviceType = "avivideo";
mciOpen.lpstrElementName = m_lpszFileName;
mciOpen.lpstrAlias = NULL;
mciOpen.dwStyle = WS_CHILD;
mciOpen.hWndParent = hWnd;
mciSendCommand(0,
MCI_OPEN,
MCI_OPEN_TYPE ¦ // specify this command play file by specified device type
MCI_OPEN_ELEMENT ¦ // specify this command play
MCI_DGV_PLAY_REPEAT ¦ // repeatedly play
MCI_DGV_OPEN_PARENT, // couple to WS_CHILD parameter.
(DWORD)(LPMCI_DGV_OPEN_PARMS)&mciOpen);
MCI_DGV_STATUS_PARMS mciStatus;
mciStatus.dwItem = MCI_DGV_STATUS_HWND;
mciSendCommand(mciOpen.wDeviceID,
MCI_STATUS, MCI_STATUS_ITEM,
(DWORD)(LPMCI_STATUS_PARMS)&mciStatus);
mciPlay.dwCallback = (DWORD)hWnd;
mciPlay.dwFrom = 0;
mciPlay.dwTo = 0;
::ShowWindow(*phWnd,SW_MAXIMIZE);
m_wMCIDeviceID = mciOpen.wDeviceID;
mciSendCommand(m_wMCIDeviceID,
MCI_PLAY,
MCI_NOTIFY ¦MCI_DGV_PLAY_REPEAT ¦MCI_FROM,
(DWORD)(LPMCI_DGV_PLAY_PARMS)&mciPlay);
void CMainFrame::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
{
CMDIFrameWnd::OnNcCalcSize(bCalcValidRects, lpncsp);
if (bCalcValidRects)
lpncsp->rgrc[0].bottom -= 32; //下邊框
}
還不夠,還要把這塊位置用顏色添上:
void CMainFrame::OnNcPaint()
{
Default();
//...Draw your stuff here
}
COMPONENTSOPT opt;
CLSID_ActiveDesktop,
NULL,
CLSCTX_INPROC_SERVER,
IID_IActiveDesktop,
(void**)&pAD);
opt.fActiveDesktop =
opt.fEnableComponents = TRUE;
hr = pAD->SetDesktopItemOptions(&opt,0);
CString FindFileName(LPSTR path)
{
CString filename(path);
int nIndex = filename.ReverseFind('//');
filename = filename.Mid(nIndex + 1);
return filename;
}
BOOL IsAppAutoRunEnabled()
{
HKEY hKey;
if(RegCreateKey(HKEY_CURRENT_USER, TEXT("Software//Microsoft//"
"Windows//CurrentVersion//Run"), &hKey) == ERROR_SUCCESS)
{
BOOL bEnabled;
lpCurrentPath = new CHAR [MAX_PATH];
GetModuleFileName(NULL,lpCurrentPath,MAX_PATH);
CString filename = FindFileName(lpCurrentPath);
filename.GetBuffer(0), 0, NULL, NULL, NULL));
delete [] lpCurrentPath;
return bEnabled;
}
}
BOOL EnableAppAutoRun()
{
HKEY hKey;
"Windows//CurrentVersion//Run"), &hKey) == ERROR_SUCCESS)
{
LPTSTR lpCurrentPath = NULL;
lpCurrentPath = new CHAR [MAX_PATH];
GetModuleFileName(NULL,lpCurrentPath,MAX_PATH);
RegSetValueEx(hKey, filename.GetBuffer(0), 0, REG_SZ,
(BYTE *)lpCurrentPath, strlen(lpCurrentPath));
return TRUE;
}
}