Q:为什么不能够Kill计时器
A:
KillTimer和SetTimer的第一个句柄参数hwnd应该一致,这个句柄应该是同一线程的某个窗口句柄。
其次SetTimer和KillTimer的第二个参数nIDEvent也应该一致的。一般来说,SetTimer中nIDEvent需要设为非0,除非第一个参数hwnd的值为NULL。
1 SetTimer第一个参数不置NULL,则SetTimer中nIDEvent需要设为非0值A。如果成功,返回一个非零值,但这并不是这个Timer的id。要确认TimerProc中操作的是否同一个计时器,则需要在TimerProc的参数nIDEvent和A相比较是否相等。这种情况下Timer的操作应该是:
void __stdcall TimerProc( HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime)
{
if (idEvent == timerid0)
{
KillTimer(g_wnd, timerid0);
///...
}
}
其次SetTimer和KillTimer的第二个参数nIDEvent也应该一致的。一般来说,SetTimer中nIDEvent需要设为非0,除非第一个参数hwnd的值为NULL。
1 SetTimer第一个参数不置NULL,则SetTimer中nIDEvent需要设为非0值A。如果成功,返回一个非零值,但这并不是这个Timer的id。要确认TimerProc中操作的是否同一个计时器,则需要在TimerProc的参数nIDEvent和A相比较是否相等。这种情况下Timer的操作应该是:
timerid0 = 5500; // for example
SetTimer(g_wnd, timerid0, 2000, &TimerProc);
///...
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。这时应该这样操作:
timerid0 = SetTimer(NULL, 0, 2000, &TimerProc);
/// ...
/// ...
void __stdcall TimerProc( HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime)
{
if (idEvent == timerid0)
{
KillTimer(NULL, timerid0);
///...
}
}
Q:播放一段AVI,要循环全屏播放
MCI_DGV_PLAY_PARMS mciPlay;
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);
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);
手动添加消息WM_NCCALCSIZE的响应函数:
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
}
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
}
Q:硬盘中文件是怎样组织的祥细说明
A:
IActiveDesktop* pAD;
COMPONENTSOPT opt;
COMPONENTSOPT opt;
HRESULT hr = ::CoCreateInstance(
CLSID_ActiveDesktop,
NULL,
CLSCTX_INPROC_SERVER,
IID_IActiveDesktop,
(void**)&pAD);
CLSID_ActiveDesktop,
NULL,
CLSCTX_INPROC_SERVER,
IID_IActiveDesktop,
(void**)&pAD);
opt.dwSize = sizeof(opt);
opt.fActiveDesktop =
opt.fEnableComponents = TRUE;
hr = pAD->SetDesktopItemOptions(&opt,0);
opt.fActiveDesktop =
opt.fEnableComponents = TRUE;
hr = pAD->SetDesktopItemOptions(&opt,0);
hr = pAD->ApplyChanges(AD_APPLY_REFRESH);
Q:通过修改注册表让Windows启动的时候启动程序自身
A:
// find out the file name from given path
CString FindFileName(LPSTR path)
{
CString filename(path);
int nIndex = filename.ReverseFind('//');
filename = filename.Mid(nIndex + 1);
return filename;
}
CString FindFileName(LPSTR path)
{
CString filename(path);
int nIndex = filename.ReverseFind('//');
filename = filename.Mid(nIndex + 1);
return filename;
}
// Query if the application will automatically start up when starting windows
BOOL IsAppAutoRunEnabled()
{
HKEY hKey;
if(RegCreateKey(HKEY_CURRENT_USER, TEXT("Software//Microsoft//"
"Windows//CurrentVersion//Run"), &hKey) == ERROR_SUCCESS)
{
BOOL bEnabled;
BOOL IsAppAutoRunEnabled()
{
HKEY hKey;
if(RegCreateKey(HKEY_CURRENT_USER, TEXT("Software//Microsoft//"
"Windows//CurrentVersion//Run"), &hKey) == ERROR_SUCCESS)
{
BOOL bEnabled;
LPTSTR lpCurrentPath = NULL;
lpCurrentPath = new CHAR [MAX_PATH];
GetModuleFileName(NULL,lpCurrentPath,MAX_PATH);
CString filename = FindFileName(lpCurrentPath);
lpCurrentPath = new CHAR [MAX_PATH];
GetModuleFileName(NULL,lpCurrentPath,MAX_PATH);
CString filename = FindFileName(lpCurrentPath);
bEnabled = (ERROR_SUCCESS == RegQueryValueEx(hKey,
filename.GetBuffer(0), 0, NULL, NULL, NULL));
filename.GetBuffer(0), 0, NULL, NULL, NULL));
RegCloseKey(hKey);
delete [] lpCurrentPath;
return bEnabled;
}
delete [] lpCurrentPath;
return bEnabled;
}
return FALSE;
}
}
// Modify the registry to let the application run at window starting up.
BOOL EnableAppAutoRun()
{
HKEY hKey;
BOOL EnableAppAutoRun()
{
HKEY hKey;
if(RegCreateKey(HKEY_CURRENT_USER, TEXT("Software//Microsoft//"
"Windows//CurrentVersion//Run"), &hKey) == ERROR_SUCCESS)
{
LPTSTR lpCurrentPath = NULL;
lpCurrentPath = new CHAR [MAX_PATH];
GetModuleFileName(NULL,lpCurrentPath,MAX_PATH);
"Windows//CurrentVersion//Run"), &hKey) == ERROR_SUCCESS)
{
LPTSTR lpCurrentPath = NULL;
lpCurrentPath = new CHAR [MAX_PATH];
GetModuleFileName(NULL,lpCurrentPath,MAX_PATH);
CString filename = FindFileName(lpCurrentPath);
RegSetValueEx(hKey, filename.GetBuffer(0), 0, REG_SZ,
(BYTE *)lpCurrentPath, strlen(lpCurrentPath));
RegSetValueEx(hKey, filename.GetBuffer(0), 0, REG_SZ,
(BYTE *)lpCurrentPath, strlen(lpCurrentPath));
RegCloseKey(hKey);
return TRUE;
}
return TRUE;
}
return FALSE;
}
}