Win32 API FAQ
Страница 9.


However, I can't recommend this approach. I have found when using this code,
NT4 very occasionally seems to get confused and pass you back the normal
desktop handle, in which case you end up trying to close all the normal
application windows. Note, in MS' defence, that the code above for closing
32 bit savers is derived from a sample that is only marked as valid for
NT3.51 - there is no mention of NT4 in the sample. Unfortunately, there is
also nothing to indicate that it doesn't work properly.

I have subsequently performed some tests, and found that the stock screen
savers supplied with NT4 will in any case get a hit on the window class search
normally used for 16 bit savers ("WindowsScreenSaverClass"). I don't believe
for a moment that the OpenGL savers (for example) are 16 bit, so maybe MS are
supplying a saver window class that will give the necessary hit. So anyway, you
can use this route :

      HWND hSaver = FindWindow ("WindowsScreenSaverClass", NULL);
      if (hSaver)
         PostMessage (hSaver, WM_CLOSE, 0, 0);

Yet another alternative is now available, which depends upon new functionality
in SystemParametersInfo. This should be even more general :

      BOOL bSaver;
      if (::SystemParametersInfo (SPI_GETSCREENSAVEACTIVE,0,&bSaver,0))
      {
         if (bSaver)
         {
            ::PostMessage (::GetForegroundWindow(), WM_CLOSE, 0L, 0L);
         }
      }

So you can try that one as well. An embarassment of riches !

14)--------------------------------------------------------------------------

 

    Q> Как узнать ip адрес(а) машины (в текстовом виде)?

    A> Кусок исходника от плугина к BackOrifice:

//---------------------------------------------------
void MachineIP(char *result)
{
         WSADATA WSAData;

         WSAStartup(MAKEWORD(1,1), &WSAData);

    char dot[6];
    int iResult;
    int i = 0;
    u_long *ppIpNO;
    u_long *pIpNO;
    HOSTENT FAR *lphostent;
    u_long ipHO;
    unsigned char binIp[4];
    int iterations = 0;

    //Get local host name and crudely validate
    char szHostName[100];
    *result = 0;

    iResult = gethostname(szHostName, sizeof(szHostName));
// printf("%d %s",iResult,szHostName);
    if ((iResult != 0) || (lstrcmp(szHostName, "")==0))
     return;

    //Lok up this host info via supplied name
    lphostent = gethostbyname(szHostName);
    if (lphostent == NULL)
     return;
    //Retreive first entry (might have multiple connects)
    do
    {
     iterations++;
     ppIpNO = (u_long *)lphostent->h_addr_list;
     if (ppIpNO+i == NULL)
      return;
     pIpNO = ((u_long *)*(ppIpNO+i));
     if (pIpNO == NULL)
      return;

    //convert back to host order, since SOCKADDR_IN expects that
     //MessageBox(NULL,"z","x",MB_OK);
     ipHO = ntohl(*pIpNO);

     binIp[0] = (BYTE)((ipHO & 0xff000000) >> 24);
     itoa(binIp[0], dot, 10);
     strcat(result,dot);
     binIp[1] = (BYTE)((ipHO & 0x00ff0000) >> 16);
     itoa(binIp[1], dot, 10);
     strcat(result, "."); strcat(result, dot);
     binIp[2] = (BYTE)((ipHO & 0x0000ff00) >> 8);
     itoa(binIp[2], dot, 10);
     strcat(result, "."); strcat(result, dot);
     binIp[3] = (BYTE)(ipHO & 0x000000ff);
     itoa(binIp[3], dot, 10);
     strcat(result,"."); strcat(result, dot);
     strcat(result,"\r\n");
     i++;
    } while ((pIpNO != NULL) && (iterations < 6));
    WSACleanup();
         PostQuitMessage(0);
    return;
}

15)--------------------------------------------------------------------------

 

    Q> Как определить тип Windows на компьютере?

    A>

bool OsTypeNT(void)
{
           OSVERSIONINFO vi;

           vi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
           GetVersionEx(&vi);
           if (vi.dwPlatformId==VER_PLATFORM_WIN32_NT)
           return true;

           return false;
}

 
« Предыдущая статья   Следующая статья »