zoukankan      html  css  js  c++  java
  • VC点滴1

    过完年了,上了3天的班,感觉还是上班比较充实些,放假回家都不知道干什么了. 这段时间一直沉浸于vc中,感觉到vc真的很麻烦,写个UI太费劲了.不过目前的这个DCOM终于大部分的功能都完成了.  整理下其中使用的一些小的部分,记录以后可能也会用到.
    1.获取登陆OS的用户名和域名.
    因为这次开发用户都是是用AD进行管理的,所以要获取登陆OS的用户名,然后到DB中捞资料然后登陆分机.
    获取方法如下:
    #define MAX_SID_SIZE   1024
    #define MAX_NAME_STRING   1024
    //Get OSUser  Name 
    void XXXXXX()
    {
    TCHAR  errorMessage[
    1024];
     TCHAR  userName[MAX_NAME_STRING], domainName[MAX_NAME_STRING];
     TCHAR  subKeyName[MAX_PATH];
     DWORD  subKeyNameSize, index;
     DWORD  userNameSize, domainNameSize;
     FILETIME lastWriteTime;
     HKEY  usersKey;
     PSID  sid;
     SID_NAME_USE sidType;
     SID_IDENTIFIER_AUTHORITY authority;
     BYTE  subAuthorityCount;
     DWORD  authorityVal, revision;
     DWORD  subAuthorityVal[
    8= 00000000 };
     
    //
     
    // Use RegConnectRegistry so that we work with remote computers
     
    //

     
    if( RegOpenKey( HKEY_USERS, NULL, &usersKey ) != ERROR_SUCCESS ) {

      wprintf( errorMessage, L
    "Error opening HKEY_USERS" );
      GetError();
      
    //  PrintWin32Error( errorMessage, GetLastError() );
      
    //  return FALSE;
     }


     
    //
     
    // Enumerate keys under HKEY_USERS
     
    //
     index = 0;
     subKeyNameSize 
    = sizeof( subKeyName );
     
    while( RegEnumKeyEx( usersKey, index, subKeyName, &subKeyNameSize,
      NULL, NULL, NULL, 
    &lastWriteTime ) == ERROR_SUCCESS ) {

       
    //
       
    // Ignore the default subkey and win2K user class subkeys
       
    //
       if( wcsicmp( subKeyName, L".default" ) &&
        
    !wcsstr( subKeyName, L"Classes")) {

         
    //
         
    // Convert the textual SID into a binary SID
         
    //
         subAuthorityCount= swscanf( subKeyName, L"S-%d-%x-%lu-%lu-%lu-%lu-%lu-%lu-%lu-%lu",
          
    &revision, &authorityVal,
          
    &subAuthorityVal[0],
          
    &subAuthorityVal[1],
          
    &subAuthorityVal[2],
          
    &subAuthorityVal[3],
          
    &subAuthorityVal[4],
          
    &subAuthorityVal[5],
          
    &subAuthorityVal[6],
          
    &subAuthorityVal[7] );

         
    if( subAuthorityCount >= 3 ) {

          subAuthorityCount 
    -= 2;

          
    //
          
    // Note: we can only deal with authority values
          
    // of 4 bytes in length
          
    //
          authority.Value[5= *(PBYTE) &authorityVal;
          authority.Value[
    4= *((PBYTE) &authorityVal+1);
          authority.Value[
    3= *((PBYTE) &authorityVal+2);
          authority.Value[
    2= *((PBYTE) &authorityVal+3);
          authority.Value[
    1= 0;
          authority.Value[
    0= 0;

          
    //
          
    // Initialize variables for subsequent operations
          
    //
          sid = NULL;
          userNameSize   
    = MAX_NAME_STRING;
          domainNameSize 
    = MAX_NAME_STRING;

          
    if( AllocateAndInitializeSid( &authority,
           subAuthorityCount,
           subAuthorityVal[
    0],
           subAuthorityVal[
    1],
           subAuthorityVal[
    2],
           subAuthorityVal[
    3],
           subAuthorityVal[
    4],
           subAuthorityVal[
    5],
           subAuthorityVal[
    6],
           subAuthorityVal[
    7],
           
    &sid )) {

            
    //
            
    // We can finally lookup the account name
            
    //
            if( LookupAccountSid( NULL,
             sid, 
             userName,
             
    &userNameSize,
             domainName,
             
    &domainNameSize,
             
    &sidType )) {

              
    //
              
    // We've successfully looked up the user name
              
    //
              if(wcsicmp( domainName, L"NT AUTHORITY"))
              
    {
               m_User 
    = userName;
               m_Domain 
    = domainName;
               UpdateData(FALSE);
               wprintf( L
    "%s\\%s\n", domainName, userName );   
              }

            }

          }
                   
          
    if( sid ) FreeSid( sid );
         }

       }

       subKeyNameSize 
    = sizeof( subKeyName );
       index
    ++;
     }

     RegCloseKey( usersKey ); 
    }


    2.改变窗口背景色.

    HBRUSH CDialFrm::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
    {
     HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

     switch (nCtlColor) {
      case CTLCOLOR_STATIC:
      case CTLCOLOR_DLG:
      {
       pDC->SetBkMode(TRANSPARENT);
       HBRUSH b = CreateSolidBrush(RGB(0,0,0));
       return (HBRUSH) b;
      }
     }
     return hbr;
    }


    目前还差一个,就是跑马灯的实现,现在写了一个跑马灯的类,但是只能支持左到右的跑,按规格上看,也要支持上下才行。如果有人知道这样的类,告诉俺下,谢谢咯。

  • 相关阅读:
    Python基础语法 第2节课(数据类型转换、运算符、字符串)
    python基础语法 第5节课 ( if 、 for )
    python基础语法 第4节课 (字典 元组 集合)
    Python基础语法 第3节课 (列表)
    A. Peter and Snow Blower 解析(思維、幾何)
    C. Dima and Salad 解析(思維、DP)
    D. Serval and Rooted Tree (樹狀DP)
    C2. Balanced Removals (Harder) (幾何、思維)
    B. Two Fairs 解析(思維、DFS、組合)
    D. Bash and a Tough Math Puzzle 解析(線段樹、數論)
  • 原文地址:https://www.cnblogs.com/zhucl1006/p/1070012.html
Copyright © 2011-2022 走看看