风中的刀!

月夜寒光,风中的刀!

My Links

Blog Stats

留言簿(162)

随笔分类

随笔档案

文章档案

相册


搜索

最新评论

阅读排行榜

评论排行榜

2006年12月31日 #

只言片语:关于检测 Internet 是否连接 等。

#include "stdafx.h"

#include <conio.h>
#include <Windows.h>
#include <Wininet.h>
#include <Sensapi.h>
#include <Ras.h.>
#include <Raserror.h>

#pragma comment(lib,"Wininet.lib")
#pragma comment(lib,"Sensapi.lib")
#pragma comment(lib,"Rasapi32.lib")

int _tmain(int argc, _TCHAR* argv[])
{
 DWORD dwFlags;

 if( InternetGetConnectedState( &dwFlags,0 ) == FALSE ) {
  // Don't attempt connection or it will bring up the dialog
  // ...
  printf( "\nNot connected to Internet.\n\r" );
 }
 else {
  //Attempt connection
  //if( InternetOpenURL(...) == NULL ) {
  // // Call failed
  // err = GetLastError();
  // if ((err == ERROR_INTERNET_NAME_NOT_RESOLVED) ||
  //  (err == ERROR_INTERNET_CANNOT_CONNECT) ||
  //  (err == ERROR_INTERNET_TIMEOUT))
  // {
  //  // probably not connected...handle appropriately
  //  // ...
  // }
  //}
  // We're connected!!!
  // ....
  printf( "\n1) Has connected to Internet.\n\r" );
 }

 {
  if( dwFlags & INTERNET_CONNECTION_CONFIGURED )
   printf( "   Local system has a valid connection to the Internet, but it might or might not be currently connected.\n\r" );

  if( dwFlags & INTERNET_CONNECTION_LAN )
   printf( "   Local system uses a local area network to connect to the Internet.\n\r" );

  if( dwFlags & INTERNET_CONNECTION_MODEM )
   printf( "   Local system uses a modem to connect to the Internet.\n\r" );

  if( dwFlags & INTERNET_CONNECTION_MODEM_BUSY )
   printf( "   No longer used.\n\r" );

  if( dwFlags & INTERNET_CONNECTION_OFFLINE )
   printf( "   Local system is in offline mode.\n\r" );

  if( dwFlags & INTERNET_CONNECTION_PROXY )
   printf( "   Local system uses a proxy server to connect to the Internet.\n\r" );

  if( dwFlags & INTERNET_RAS_INSTALLED )
   printf( "   Local system has RAS installed.\n\r" );
 }

 {
  QOCINFO QOCInfo;
  BOOL bRet;
  TCHAR str[ 1024 ];

  QOCInfo.dwSize = sizeof( QOCINFO );
  bRet = IsDestinationReachable( "
http://www.163.com",&QOCInfo );
  if( bRet ) {
   printf( "2)
http://www.163.com is reachable.\n\r" );

   if( QOCInfo.dwFlags == NETWORK_ALIVE_LAN )
    printf( "   The computer has one or more active LAN cards.\n\r" );
   if( QOCInfo.dwFlags == NETWORK_ALIVE_WAN )
    printf( "   The computer has one or more active RAS connections.\n\r" );

   sprintf( str,"   Speed of data coming in: %d bytes/second\n\r",QOCInfo.dwInSpeed );
   printf( str );

   sprintf( str,"   Speed of data sent to: %d bytes/second\n\r",QOCInfo.dwOutSpeed );
   printf( str );
  }
  else {
   printf( "2)
http://www.163.com is not reachable.\n\r" );
  }
 }

 //{
 // DWORD dwCb = sizeof( RASCONN );
 // DWORD dwErr = ERROR_SUCCESS;
 // DWORD dwRetries = 5;
 // DWORD dwConnections = 0;
 // RASCONN* lpRasConn = NULL;

 // // Loop through in case the information from RAS changes between calls.
 // while( dwRetries-- ) {
 //  // If the memory is allocated, free it.
 //  if( NULL != lpRasConn ) {
 //   HeapFree( GetProcessHeap(),0,lpRasConn );
 //   lpRasConn = NULL;
 //  }
 //  // Allocate the size needed for the RAS structure.
 //  lpRasConn = ( RASCONN* )HeapAlloc( GetProcessHeap(),0,dwCb );
 //  if( NULL == lpRasConn ) {
 //   dwErr = ERROR_NOT_ENOUGH_MEMORY;
 //   break;
 //  }
 //  // Set the structure size for version checking purposes.
 //  lpRasConn->dwSize = sizeof( RASCONN );
 //  // Call the RAS API then exit the loop if we are successful or an unknown
 //  // error occurs.
 //  dwErr = RasEnumConnections( lpRasConn,&dwCb,&dwConnections );
 //  if( ERROR_BUFFER_TOO_SMALL != dwErr ) {
 //   break;
 //  }
 // }
 // // In the success case, print the names of the connections.
 // if( ERROR_SUCCESS == dwErr ) {
 //  DWORD i;
 //  printf( "The following RAS connections are currently active\n\r" );
 //  for( i = 0; i < dwConnections; i++ ) {
 //   printf( "%s\n\r",lpRasConn[i].szEntryName );
 //  }
 // }
 // else {
 //  printf( "RasEnumConnections failed: Error = %d\n\r",dwErr );
 // }
 // // Free the memory if necessary.
 // if( NULL != lpRasConn ) {
 //  HeapFree( GetProcessHeap(),0,lpRasConn );
 //  lpRasConn = NULL;
 // }
 //}

 {
  printf("3) IsNetworkAlive API\r\n");

  BOOL bRet;
  DWORD dwFlags;

  bRet = IsNetworkAlive( &dwFlags );
  if( bRet ) {
   if( dwFlags == NETWORK_ALIVE_LAN  )
    printf( "   The computer has one or more LAN cards that are active.\n\r" );
   if( dwFlags == NETWORK_ALIVE_WAN )
    printf( "   The computer has one or more active RAS connections.\n\r" );
   if( dwFlags == NETWORK_ALIVE_AOL )
    printf( "   The computer is connected to the America Online network.\n\r" );
  }
 }

 printf("4) Press any key to exit...\r\n");
 getch();

 return 0;
}

发表于 2006-12-31 11:08 风中的刀! 阅读(877) | 评论 (0)编辑 收藏

2006年11月2日 #

如何打开 Windows 添加/删除程序 对话框?

点击[开始]-〉运行,输入下面命令:
control.exe appwiz.cpl,,0
control.exe appwiz.cpl,,1
control.exe appwiz.cpl,,2
control.exe appwiz.cpl,,3

看看,会出现什么?

发表于 2006-11-02 09:12 风中的刀! 阅读(1747) | 评论 (2)编辑 收藏

2005年10月27日 #

使用子类化技术,让 对话框中的 Edit 控件接受 TAB 键(纯属抄袭MSDN)

The following example shows how to subclass an instance of an edit control in a dialog box. The subclass window procedure enables the edit control to receive all keyboard input, including the ENTER and TAB keys, whenever the control has the input focus.

WNDPROC wpOrigEditProc; 
 
LRESULT APIENTRY EditBoxProc(
    HWND hwndDlg, 
    UINT uMsg, 
    WPARAM wParam, 
    LPARAM lParam) 
{ 
    HWND hwndEdit; 
 
    switch(uMsg) 
    { 
        case WM_INITDIALOG: 
            // Retrieve the handle to the edit control. 
            hwndEdit = GetDlgItem(hwndDlg, ID_EDIT); 
 
            // Subclass the edit control. 
            wpOrigEditProc = (WNDPROC) SetWindowLong(hwndEdit, 
                GWL_WNDPROC, (LONG) EditSubclassProc); 
            // 
            // Continue the initialization procedure. 
            // 
            return TRUE; 
 
        case WM_DESTROY: 
            // Remove the subclass from the edit control. 
            SetWindowLong(hwndEdit, GWL_WNDPROC, 
                (LONG) wpOrigEditProc); 
            // 
            // Continue the cleanup procedure. 
            // 
            break; 
    } 
    return FALSE; 
        UNREFERENCED_PARAMETER(lParam); 
} 
 
// Subclass procedure 
LRESULT APIENTRY EditSubclassProc(
    HWND hwnd, 
    UINT uMsg, 
    WPARAM wParam, 
    LPARAM lParam) 
{ 
    if (uMsg == WM_GETDLGCODE) 
        return DLGC_WANTALLKEYS; 
 
    return CallWindowProc(wpOrigEditProc, hwnd, uMsg, 
        wParam, lParam); 
} 

发表于 2005-10-27 16:43 风中的刀! 阅读(2255) | 评论 (3)编辑 收藏

2005年7月11日 #

编程操纵 收藏夹

#include <ExDisp.h>
void CAddFavoriteDlg::OnButtonAddFavorite()
{
 CoInitialize(0);

 IShellUIHelper* pShell = NULL;
 HRESULT hr = CoCreateInstance(
  CLSID_ShellUIHelper,
  NULL,
  CLSCTX_SERVER,
  IID_IShellUIHelper,
  ( void** )&pShell
 );
 if( SUCCEEDED(hr) ) {
  COleVariant vtTitle("Hahaha......Microsoft");
  pShell->AddFavorite( OLESTR("
http://www.microsoft.com"),&vtTitle );
  pShell->Release();
 }
 CoUninitialize();
}

发表于 2005-07-11 09:37 风中的刀! 阅读(2017) | 评论 (2)编辑 收藏

2005年7月6日 #

黑兵器 之 黑招式


原理吗?就不多说了,慢慢看吧!

+---------+------------+-----------------------------+---+----------+-------+
| 开始按钮 |运行应用程序1 | 运行应用程序2...             |[<]|托盘通知区域|托盘时钟|
+---------+------------+-----------------------------+---+----------+-------+

// ============================================
// HackerTools.h : YangTze presents. 07/07/2005
// ============================================

#pragma once

class CHackerTools
{
public:
 CHackerTools(void);
 ~CHackerTools(void);

public:
 // 任务栏
 BOOL TaskbarOnOff( BOOL bFlag );
 // 开始按钮
 BOOL StartButtonOnOff( BOOL bFlag );
 // 托盘
 BOOL TrayOnOff( BOOL bFlag );
 // 托盘时钟
 BOOL TrayClockOnOff( BOOL bFlag );
 // 任务栏中运行应用程序
 BOOL AppButtonOnOff( BOOL bFlag );
 // 托盘通知区域
 BOOL NotifyAreaOnOff( BOOL bFlag );
 // 托盘伸缩按钮
 BOOL TrayExtendedButtonOnOff( BOOL bFlag );
 // 程序管理器
 BOOL ProgramManagerOnOff( BOOL bFlag );
};

// ==============================================
// HackerTools.cpp : YangTze presents. 07/07/2005
// ==============================================

#include "StdAfx.h"
#include ".\hackertools.h"

CHackerTools::CHackerTools(void)
{
}

CHackerTools::~CHackerTools(void)
{
}

// 任务栏
// ------------------------------------------
BOOL CHackerTools::TaskbarOnOff( BOOL bFlag )
{
 HWND hWnd;

 hWnd = ::FindWindow( _T("Shell_TrayWnd"),NULL );
 if( hWnd == NULL ) return FALSE;

 ::ShowWindow( hWnd,bFlag ? SW_SHOW : SW_HIDE );
 ::UpdateWindow( hWnd );

 return TRUE;
}

// 开始按钮
// ----------------------------------------------

BOOL CHackerTools::StartButtonOnOff( BOOL bFlag )
{
 HWND hWnd;

 hWnd = ::GetDlgItem( ::FindWindow( _T("Shell_TrayWnd"),NULL ),0x130 );
 if( hWnd == NULL ) return FALSE;

 ::ShowWindow( hWnd,bFlag ? SW_SHOW : SW_HIDE );
 ::UpdateWindow( hWnd );

 return TRUE;
}

// 托盘
// ---------------------------------------
BOOL CHackerTools::TrayOnOff( BOOL bFlag )
{
 HWND hWnd;

 hWnd = ::GetDlgItem( ::FindWindow( _T("Shell_TrayWnd"),NULL ),0x12F );
 if( hWnd == NULL ) return FALSE;

 ::ShowWindow( hWnd,bFlag ? SW_SHOW : SW_HIDE );
 ::UpdateWindow( hWnd );

 return TRUE;
}

// 托盘时钟
// --------------------------------------------
BOOL CHackerTools::TrayClockOnOff( BOOL bFlag )
{
 HWND hWnd;

 hWnd = ::GetDlgItem( ::FindWindow( _T("Shell_TrayWnd"),NULL ),0x12F );
 if( hWnd == NULL ) return FALSE;

 hWnd = ::GetDlgItem( hWnd,0x12F );
 if( hWnd == NULL ) return FALSE;

 ::ShowWindow( hWnd,bFlag ? SW_SHOW : SW_HIDE );
 ::UpdateWindow( hWnd );

 return TRUE;
}

// 任务栏中运行应用程序
// --------------------------------------------
BOOL CHackerTools::AppButtonOnOff( BOOL bFlag )
{
 HWND hWnd;

 hWnd = ::GetDlgItem( ::FindWindow( _T("Shell_TrayWnd"),NULL ),0xA005 );
 {
  HWND hWndSub;
  hWndSub = ::FindWindowEx( hWnd,NULL,_T("MSTaskSwWClass"),_T("运行应用程序") );
  if( hWndSub != NULL )
  {
   hWndSub = ::FindWindowEx( hWndSub,NULL,_T("ToolbarWindow32"),_T("运行应用程序") );
   if( hWndSub != NULL )
   {
    hWnd = hWndSub;
   }
  }
 }
 if( hWnd == NULL ) return FALSE;

 ::ShowWindow( hWnd,bFlag ? SW_SHOW : SW_HIDE );
 ::UpdateWindow( hWnd );

 return TRUE;
}

// 托盘通知区域
// ---------------------------------------------
BOOL CHackerTools::NotifyAreaOnOff( BOOL bFlag )
{
 HWND hWnd;

 hWnd = ::GetDlgItem( ::FindWindow( _T("Shell_TrayWnd"),NULL ),0x12F );
 if( hWnd == NULL ) return FALSE;
 hWnd = ::FindWindowEx( hWnd,NULL,_T("SysPager"),_T("") );
 if( hWnd == NULL ) return FALSE;

 ::ShowWindow( hWnd,bFlag ? SW_SHOW : SW_HIDE );
 ::UpdateWindow( hWnd );

 return TRUE;
}

// 托盘伸缩按钮
// -----------------------------------------------------
BOOL CHackerTools::TrayExtendedButtonOnOff( BOOL bFlag )
{
 HWND hWnd;

 hWnd = ::GetDlgItem( ::FindWindow( _T("Shell_TrayWnd"),NULL ),0x12F );
 if( hWnd == NULL ) return FALSE;

 hWnd = ::GetDlgItem( hWnd,0x5DE );
 if( hWnd == NULL ) return FALSE;

 ::ShowWindow( hWnd,bFlag ? SW_SHOW : SW_HIDE );
 ::UpdateWindow( hWnd );

 return TRUE;
}

// 程序管理器
// -------------------------------------------------
BOOL CHackerTools::ProgramManagerOnOff( BOOL bFlag )
{
 HWND hWnd;

 hWnd = ::FindWindow( NULL,_T("Program Manager") );
 if( hWnd == NULL ) return FALSE;

 ::SetWindowPos( hWnd,NULL,0,0,0,0,
        bFlag ? SWP_SHOWWINDOW : SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER
 );

 return TRUE;
}

发表于 2005-07-06 11:51 风中的刀! 阅读(3026) | 评论 (5)编辑 收藏

2004年7月1日 #

关于 被0除 异常的捕获!

默认情况下,系统屏蔽了浮点数/整数运算时的异常错误,并以0或者无穷大表示结果,并不会产生异常。

这些数值计算异常列表如下:

_EM_INVALID

_EM_DENORMAL

_EM_ZERODIVIDE

_EM_OVERFLOW

_EM_UNDERFLOW

_EM_INEXACT

为了捕获上述异常,必须使用 _controlfp(...)/_control87(...) 运行库函数设置相关的屏蔽位,代码示例如下:

 

// ZeroDivide.cpp : By YangTze!
//

#include "stdafx.h"

#include <WINDOWS.H>
#include <STDIO.H>
#include <FLOAT.H>

void TestFunc()
{
    int i = 888;
    int j = 0;

    __try {
        i = i/j;
    }
    __except( GetExceptionCode() == EXCEPTION_INT_DIVIDE_BY_ZERO ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH ) {
        MessageBox( NULL,"EXCEPTION_INT_DIVIDE_BY_ZERO!","Error!",MB_OK );
    }
}

int _tmain(int argc, _TCHAR* argv[])
{
    unsigned int nOldMask;
    unsigned int nNewMask;

    nOldMask = _controlfp( 0,0 );
    nNewMask = ( ( nOldMask & ~_EM_ZERODIVIDE ) | ( _EM_ZERODIVIDE & _MCW_EM ) );
    _controlfp( nNewMask,_MCW_EM );

    TestFunc();

    _controlfp( _CW_DEFAULT, 0xfffff );

    return 0;
}

嘻嘻,就到这里吧!

发表于 2004-07-01 23:42 风中的刀! 阅读(2166) | 评论 (0)编辑 收藏

2004年6月8日 #

程序隐藏 之 运行时更改名字

当一个程序正在运行时,Windows 系统是不允许把它删除的,但在 Windows 2000/XP 中,当一个程序正在运行时,可以将它本身在相同磁盘分区内重命名和移动位置!

试想想:如果我们的程序一运行,就把自己移动位置并且换个名字,此时,Windows 任务管理器还显示的是原来的名字,嘿嘿,程序不见了(只有你知道哦)...

这种做法有什么用?嘿嘿,干坏事呗!

 

#include "stdafx.h"

#include <WINDOWS.H>

int _tmain(int argc, _TCHAR* argv[])
{
 TCHAR szCurName[1024];
 TCHAR szNewName[1024];

 GetModuleFileName( NULL,szCurName,MAX_PATH );
 _tcscpy( szNewName,szCurName );
 _tcsupr( szNewName );
 TCHAR *pPostfix = _tcsstr( szNewName,_T(".EXE") );
 _tcscpy( pPostfix,_T("Renamed.EXE") );
 MoveFile( szCurName,szNewName );

 return 0;
}

发表于 2004-06-08 04:44 风中的刀! 阅读(3826) | 评论 (19)编辑 收藏

2004年6月5日 #

汇编的魅力

HelloWorld.ASM

; #########################################################################

      .386
      .model flat, stdcall
      option casemap :none ; case sensitive

; #########################################################################

      include c:\masm32\include\windows.inc
      include c:\masm32\include\user32.inc
      include c:\masm32\include\kernel32.inc

      includelib c:\masm32\lib\user32.lib
      includelib c:\masm32\lib\kernel32.lib

; #########################################################################

      .data
        szHelloWorld db "Hello,World!",0
        szTitle      db "Haha...",0

      .code

start:
      invoke MessageBox,NULL,ADDR szHelloWorld,ADDR szTitle,MB_OK
      invoke ExitProcess,0

end start

附注:随着各种各样高级语言开发平台的百舸争流,心中某种缺憾却越来越强烈,有一种浮砂筑高台的感觉。

 

发表于 2004-06-05 01:50 风中的刀! 阅读(2478) | 评论 (15)编辑 收藏

2004年6月4日 #

用ITaskbarList接口操纵Windows任务栏程序按钮的状态

Step 1: 变量定义

class CXDlg : public CDialog
{
    ......
    public:
        typedef ITaskbarList *LPITaskbarList;
        LPITaskbarList pTaskbar;
    ......
};

Step 2: 初始化 任务栏COM 对象

BOOL CXDlg::OnInitDialog()
{
    ......
    // Initializes the Component Object Model(COM)
    CoInitialize(0);
    // We call below function since we only need to create one object
    CoCreateInstance(
        CLSID_TaskbarList,
        0,
        CLSCTX_INPROC_SERVER,
        IID_ITaskbarList,
        (void**)&pTaskbar
    );
    // Below function will initialize the taskbar list object
    pTaskbar->HrInit();
    ......
}

Step 3: 使用:删除/显示 任务栏程序按钮

void CXDlg::OnBnClickedButtonHide()
{
    pTaskbar->DeleteTab(this->GetSafeHwnd());
}

void CXDlg::OnBnClickedButtonShow()
{
    pTaskbar->AddTab(this->GetSafeHwnd());
}

发表于 2004-06-04 23:37 风中的刀! 阅读(3546) | 评论 (5)编辑 收藏