Jiangsheng的CSDN Digest (Dec 2005)[6]

[入库:2006年2月23日] [更新:2007年3月24日]

本文简介:

procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
var
CurWebrowser: IWebBrowser;
TopWebBrowser: IWebBrowser;
Document: OleVariant;
WindowName: string;
begin
CurWebrowser := pDisp as IWebBrowser;
TopWebBrowser := (Sender as TWebBrowser).DefaultInterface;
if CurWebrowser = TopWebBrowser then
ShowMessage('Complete document was loaded')
else
begin
Document := CurWebrowser.Document;
WindowName := Document.ParentWindow.Name;
ShowMessage(Format('Frame "%s" was loaded', [WindowName]));
end;
end;


怎么获得当前登入到2000,xp帐户的类型??? (VC/MFC 基础类)


比如,判断当前是一个管理员帐户,或是一个受限帐户?


Use IsUserAnAdmin
However, if you need to check a limited user account, You need to either use CheckTokenMembership, or construct a security descriptor and perform an access check.

You may need to use GetTokenInformation if you also target NT4.0
// whoami.cpp
// cl whoami.cpp /c1 /c
// link whoami.obj /nodefaultlib msvcrt.lib advapi32.lib kernel32.lib /align:16
//
//
//

#pragma comment(lib,"Advapi32.lib")

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <Windows.h>

#define UULEN 256
int main(int argc,char *argv[])
{
//OpenProcess();
HANDLE hp , htoken;
char buff[2560];
unsigned long size = 2560;

TOKEN_USER *tuser;
PTOKEN_GROUPS tgroup;
PTOKEN_OWNER towner;
PTOKEN_SOURCE tsource;
PSID sid;
char user[UULEN], domain[UULEN];
SID_NAME_USE snu;

hp = htoken = INVALID_HANDLE_VALUE;
hp = GetCurrentProcess();

if(!OpenProcessToken(hp, TOKEN_QUERY | TOKEN_QUERY_SOURCE , &htoken))
{
printf("OpenProcessToken error : %u\r\n", GetLastError());
goto exit_main;
}
if(!GetTokenInformation(htoken, TokenUser, (void*)buff, size, &size))
{
printf("GetTokenInformation error : %u\r\n", GetLastError());
goto exit_main;
}
tuser = (TOKEN_USER*)buff;
sid = tuser->User.Sid;
size = UULEN;
if(!LookupAccountSid(NULL, sid, user, &size, domain, &size, &snu))
{
printf("LookupAccountSid error : %u\r\n", GetLastError());
goto exit_main;
}
// printf("you are '%s\\%s'\r\n", domain, user);
printf( "Domain : %s\nUser : %s\n", domain, user);

size = UULEN *10;
if(!GetTokenInformation(htoken, TokenGroups , (void*)buff, size, &size))
{
printf("GetTokenInformation error : %u\r\n", GetLastError());
goto exit_main;
}
tgroup = (PTOKEN_GROUPS)buff;
int len ;
len = tgroup->GroupCount;
printf( "Group :\n");
int i;
for( i = 0; i< len ; i++)
{
sid = tgroup->Groups[i].Sid ;
size = UULEN;
if(!LookupAccountSid(NULL, sid, user, &size, domain, &size, &snu))
{
//printf("LookupAccountSid error : %u\r\n", GetLastError());
break;
}
printf("\t[%d] %s\n",i+1, user );
}

size = 2560;

if(!GetTokenInformation(htoken,TokenOwner, (void*)buff, size, &size))
{
printf("GetTokenInformation error : %u\r\n", GetLastError());
goto exit_main;
}

towner = (PTOKEN_OWNER)buff;
sid = towner->Owner;
size = UULEN;

if(!LookupAccountSid(NULL, sid, user, &size, domain, &size, &snu))
{
printf("LookupAccountSid error : %u\r\n", GetLastError());
goto exit_main;
}

printf( "Owner : %s\n", user );

size = 2560;

if(!GetTokenInformation(htoken,TokenSource, (void*)buff, size, &size))
{
printf("GetTokenInformation error : %u\r\n", GetLastError());
goto exit_main;
}
tsource = (PTOKEN_SOURCE ) buff;
tuser = (TOKEN_USER*)buff;
sid = tuser->User.Sid;
size = UULEN;

printf( "Source : %.8s\n", tsource->SourceName );


exit_main:
if(htoken != INVALID_HANDLE_VALUE)CloseHandle(htoken);
if(hp != INVALID_HANDLE_VALUE)CloseHandle(hp);
return 0;
}


MFC基于Dialog如何得到屏幕右下角坐标(可用位置) (VC/MFC 界面 )


如何得到屏幕右下角坐标(可用位置)?
int cx = GetSystemMetrics( SM_CXSCREEN );
int cy = GetSystemMetrics( SM_CYSCREEN );

这样可以得到分辨率。但是我需要知道是不是下边有一个任务栏会占据一定高度。又或许任务栏在右边。总之,需要知道可用位置的最右下位置


SystemParametersInfo

This function, with the flag SPI_GETWORKAREA, retrieves the size of the work
area on the primary display monitor. The work area is the portion of the
screen not obscured by the system taskbar or by application desktop
toolbars.
The parameter rc is a RECT structure that receives the coordinates of the
work
area, expressed in virtual screen coordinates

本文关键:Jiangsheng的CSDN Digest (Dec 2005)
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top