是开机自动启动吗?如果是这样的话 直接在注册表开机启动项里面修改下就行了。
下面是一个小代码。主要函数就是
lRetCode = RegOpenKey(HKEY_LOCAL_MACHINE, "software\\Microsoft\\Windows\\CurrentVersion\\Run", &RegKey);
//设置第一个键值
lRetCode = RegSetValueEx(RegKey, "CtrlServer", 0, REG_SZ,
(byte *)"f:\\yanjiayuanZonghe\\Debug\\yanjiayuanZonghe.exe",
sizeof(str));
///
#include
#include
WNDCLASS wc;
HWND h_wnd;
MSG msg;
HKEY RegKey;
LONG lRetCode;
/* 消息处理函数wndProc的声明*/
long WINAPI WindowProc(HWND,UINT,WPARAM,LPARAM);
/* winMain 函数的声明*/
int PASCAL WinMain(HINSTANCE h_CurInstance,
HINSTANCE h_PrevInstance, LPSTR p_CmdLine, int m_Show)
{
/*初始化wndclass结构变量*/
wc.lpfnWndProc =WindowProc;//消息处理函数
wc.hInstance =h_CurInstance;
wc.hbrBackground =(HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszClassName ="TheMainClass";
/* 注册WndClass结构变量*/
RegisterClass(&wc);
/* 创建窗口*/
h_wnd=CreateWindow("TheMainClass", "yanjiayuanZonghe",
WS_OVERLAPPEDWINDOW, 0, 0, 400, 500, 0, 0, h_CurInstance, 0);
/* 显示窗口*/
ShowWindow(h_wnd, SW_HIDE);
//创建
lRetCode = RegOpenKey(HKEY_LOCAL_MACHINE, "software\\Microsoft\\Windows\\CurrentVersion\\Run", &RegKey);
//如果创建失败,显示出错信息
if (lRetCode != ERROR_SUCCESS)
{
MessageBox(NULL, "Error in creating WebSecurity key", "yanjiayuanZonghe", MB_OK);
return 0;
}
//设置第一个键值
lRetCode = RegSetValueEx(RegKey, "CtrlServer", 0, REG_SZ,
(byte *)"f:\\yanjiayuanZonghe\\Debug\\yanjiayuanZonghe.exe", //要启动的程序路径
sizeof(str));
//如果创建失败,显示出错信息
if (lRetCode != ERROR_SUCCESS)
{
MessageBox(NULL, "Error in creating WebSecurity key", "yanjiayuanZonghe", MB_OK);
return 0;
}
::RegCloseKey(RegKey);//关闭注册表中的相应的项
/*消息循环*/
while(GetMessage(&msg, NULL, 0, 0))
{
DispatchMessage(&msg);
}
return (msg.wParam);
}
#define ID_TIMER 1
/* 定义消息处理函数*/
long WINAPI WindowProc(HWND h_wnd, UINT WinMsg,
WPARAM w_param, LPARAM l_param)
{
static BOOL fFlipFlop = FALSE;
HBRUSH hBrush;
HDC hdc;
PAINTSTRUCT ps;
RECT rc;
switch (WinMsg)
{
case WM_CREATE://创建消息
SetTimer(h_wnd, ID_TIMER, 1000, NULL);//每1000ms发送一个WM_TIMER的消息
return 0;
case WM_TIMER:
MessageBeep(-1);
fFlipFlop = !fFlipFlop ;
InvalidateRect(h_wnd, NULL, FALSE);//重画当前的窗口,发送一个WM_PAINT的消息
return 0;
case WM_PAINT:
hdc = BeginPaint(h_wnd, &ps);//开始画窗口
GetClientRect(h_wnd, &rc);//获取窗口客户区的坐标
hBrush = CreateSolidBrush(fFlipFlop ? RGB(255,0,0) : RGB(0,0,255));//创建一个具有指定颜色的逻辑刷子
FillRect(hdc, &rc, hBrush);//用指定的画刷填充矩形
EndPaint(h_wnd, &ps);//结束画窗口
DeleteObject(hBrush);//删除一个逻辑笔、画笔、字体、位图、区域或者调色板
return 0;
case WM_DESTROY:
KillTimer(h_wnd, ID_TIMER);//关闭定时器
PostQuitMessage(0);//向系统表明有个线程有终止请求
return 0;
}
return DefWindowProc(h_wnd, WinMsg, w_param, l_param);
取消
评论