小弟在做一程序,非木马。。想实现程序对U盘的检测和连接上网的检测,U盘有标准消息,可连接上网是否必须要自定义消息实现本程序和WINDOWS上网程序间的进程间通信呢?据我了解,自定义消息实现进程间通信必须发送放和接收方同时在代码里注册。。可我怎么能对WINDOWS上网程序的代码操作呢?请大牛赐教。。非常感谢。。
#include "stdafx.h"
#include <windows.h>
#include <wininet.h>
#pragma comment (lib,"wininet.lib")
#include <Shlwapi.h>
#include <fstream.h>
#include <TlHelp32.h>
#include <Dbt.h>#pragma comment(lib,"shlwapi.lib")#define TIMER 1//计时器//function
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);//窗口过程
//获取盘符
TCHAR FirstDriveFromMask (ULONG unitmask);//global variable
TCHAR szExePath[MAX_PATH];//the virus's path
TCHAR U[2];//保存U盘的盘符
TCHAR szSysPath[MAX_PATH];//system path
BOOL islink=TRUE;int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{ static TCHAR szAppName[]=TEXT ("UUUUUU");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.style =0;
wndclass.lpfnWndProc =WndProc;
wndclass.cbClsExtra =0;
wndclass.cbWndExtra =0;
wndclass.hInstance =hInstance;
wndclass.hIcon =0;
wndclass.hCursor =0;
wndclass.hbrBackground =0;
wndclass.lpszMenuName =NULL;
wndclass.lpszClassName =szAppName;
if (!RegisterClass (&wndclass))
{
//MessageBox (NULL,TEXT("Program requires Windows NT!"),
//szAppName, MB_ICONERROR);
return 0;
}
hwnd = CreateWindow (szAppName, NULL,
WS_DISABLED,
0, 0,
0, 0,
NULL, NULL, hInstance, NULL);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam;
//return 0;
}
LRESULT OnDeviceChange(HWND hwnd,WPARAM wParam, LPARAM lParam)
{
PDEV_BROADCAST_HDR lpdb = (PDEV_BROADCAST_HDR)lParam;
switch(wParam)
{
case DBT_DEVICEARRIVAL: //插入
if (lpdb -> dbch_devicetype == DBT_DEVTYP_VOLUME)
{
PDEV_BROADCAST_VOLUME lpdbv = (PDEV_BROADCAST_VOLUME)lpdb;
U[0]=FirstDriveFromMask(lpdbv ->dbcv_unitmask);//得到u盘盘符
MessageBox(0,U,"Notice!",MB_OK);
}
break;
case DBT_DEVICEREMOVECOMPLETE: //设备删除
break;
}
return LRESULT();
}LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam,LPARAM
lParam)
{ switch(message)
{
case WM_CREATE: //处理一些要下面要用到的全局变量
U[1]=':';
SetTimer(hwnd,TIMER,5000,0);//启动计时器
return 0;
case WM_TIMER: //timer message
SendMessage(hwnd,WM_DEVICECHANGE,0,0);//检测有没有插入设备消息
return 0;
case WM_DEVICECHANGE:
OnDeviceChange(hwnd,wParam,lParam);
return 0;
case WM_DESTROY:
KillTimer(hwnd,TIMER);
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}TCHAR FirstDriveFromMask(ULONG unitmask)
{
char i;
for (i = 0; i < 26; ++i)
{
if (unitmask & 0x1)//看该驱动器的状态是否发生了变化
break;
unitmask = unitmask >> 1;
}
return (i + 'A');
}/*
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
BOOL islink=InternetGetConnectedState(NULL,0);
if (islink==TRUE)
MessageBoxA(0,"已经连接","提示",64);
//else
//MessageBoxA(0,"没有连接","提示",32);
return 0;
}
*/
#include "stdafx.h"
#include <windows.h>
#include <wininet.h>
#pragma comment (lib,"wininet.lib")
#include <Shlwapi.h>
#include <fstream.h>
#include <TlHelp32.h>
#include <Dbt.h>#pragma comment(lib,"shlwapi.lib")#define TIMER 1//计时器//function
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);//窗口过程
//获取盘符
TCHAR FirstDriveFromMask (ULONG unitmask);//global variable
TCHAR szExePath[MAX_PATH];//the virus's path
TCHAR U[2];//保存U盘的盘符
TCHAR szSysPath[MAX_PATH];//system path
BOOL islink=TRUE;int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{ static TCHAR szAppName[]=TEXT ("UUUUUU");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.style =0;
wndclass.lpfnWndProc =WndProc;
wndclass.cbClsExtra =0;
wndclass.cbWndExtra =0;
wndclass.hInstance =hInstance;
wndclass.hIcon =0;
wndclass.hCursor =0;
wndclass.hbrBackground =0;
wndclass.lpszMenuName =NULL;
wndclass.lpszClassName =szAppName;
if (!RegisterClass (&wndclass))
{
//MessageBox (NULL,TEXT("Program requires Windows NT!"),
//szAppName, MB_ICONERROR);
return 0;
}
hwnd = CreateWindow (szAppName, NULL,
WS_DISABLED,
0, 0,
0, 0,
NULL, NULL, hInstance, NULL);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam;
//return 0;
}
LRESULT OnDeviceChange(HWND hwnd,WPARAM wParam, LPARAM lParam)
{
PDEV_BROADCAST_HDR lpdb = (PDEV_BROADCAST_HDR)lParam;
switch(wParam)
{
case DBT_DEVICEARRIVAL: //插入
if (lpdb -> dbch_devicetype == DBT_DEVTYP_VOLUME)
{
PDEV_BROADCAST_VOLUME lpdbv = (PDEV_BROADCAST_VOLUME)lpdb;
U[0]=FirstDriveFromMask(lpdbv ->dbcv_unitmask);//得到u盘盘符
MessageBox(0,U,"Notice!",MB_OK);
}
break;
case DBT_DEVICEREMOVECOMPLETE: //设备删除
break;
}
return LRESULT();
}LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam,LPARAM
lParam)
{ switch(message)
{
case WM_CREATE: //处理一些要下面要用到的全局变量
U[1]=':';
SetTimer(hwnd,TIMER,5000,0);//启动计时器
return 0;
case WM_TIMER: //timer message
SendMessage(hwnd,WM_DEVICECHANGE,0,0);//检测有没有插入设备消息
return 0;
case WM_DEVICECHANGE:
OnDeviceChange(hwnd,wParam,lParam);
return 0;
case WM_DESTROY:
KillTimer(hwnd,TIMER);
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}TCHAR FirstDriveFromMask(ULONG unitmask)
{
char i;
for (i = 0; i < 26; ++i)
{
if (unitmask & 0x1)//看该驱动器的状态是否发生了变化
break;
unitmask = unitmask >> 1;
}
return (i + 'A');
}/*
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
BOOL islink=InternetGetConnectedState(NULL,0);
if (islink==TRUE)
MessageBoxA(0,"已经连接","提示",64);
//else
//MessageBoxA(0,"没有连接","提示",32);
return 0;
}
*/
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货