闲来无事 练习基础知识

26 篇文章 0 订阅
14 篇文章 0 订阅


1、创建进程:

 

    STARTUPINFO si  ;
 	si.cb = sizeof(si);
 	memset(&si,0,sizeof(si));
    PROCESS_INFORMATION  pi;
	
    si.wShowWindow = TRUE;
    BOOL bRet = CreateProcess(NULL,"notepad.exe",NULL,NULL,FALSE,NULL,NULL,NULL,&si,&pi); 
    if (bRet)
    {
        CString str;
        str.Format("%d",pi.dwThreadId);
    }


2、列举进程

    PROCESSENTRY32  pe32;
    pe32.dwSize = sizeof(pe32);
    HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
    if (hProcessSnap == INVALID_HANDLE_VALUE)
    {
        sprintf("%s\n","创建快照失败!");
        return ;
    }
    BOOL bMore = ::Process32First(hProcessSnap,&pe32);   
    
    while(bMore)
    {
        bMore = Process32Next(hProcessSnap,&pe32);
        sprintf(" 进程名称:%s  进程ID:%d;",pe32.szExeFile,pe32.th32ProcessID);
         
    }
    ::CloseHandle(hProcessSnap);
    return ;

 

3、时间

    struct tm  *pstr;
    time_t t;
    t =  time(NULL);
    pstr = localtime(&t);
    int yyyy = (pstr->tm_year) + 1900; // 年份是从1900开始
    int mm   = (pstr->tm_mon) + 1;  // 月是从0-11,所以要加1
    int dd   = (pstr->tm_mday) ; // 日是从1 开始
    printf("%d年%d月%d日",yyyy,mm,dd);


 

4、显示关机对话框

typedef int (CALLBACK *SHUTDOWNDLG)(int); //显示关机对话框函数的指针
    HINSTANCE hInst = LoadLibrary("shell32.dll"); //装入shell32.dll
    SHUTDOWNDLG ShutDownDialog; //指向shell32.dll库中显示关机对话框函数的指针
    if(hInst != NULL)
    {
        //获得函数的地址并调用之
        ShutDownDialog = (SHUTDOWNDLG)GetProcAddress(hInst,(LPSTR)60);
        
        (*ShutDownDialog)(0);
    }


 

5、结构体指针数组

#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <memory.h>

// 定义结构体
typedef struct tag_STUDENT 
{
    char name[120];
    int  ID;
    int  age;
}STUDENT,*LPSTUDENT;

// 函数声明
void  outputfun(LPSTUDENT pStu[3]);
void  setdatafun() ;
 

// 自定义
void  setdatafun() 
{
    char *str = "*** 夜深人静,此情此刻我心依然 ! ***";
    int i = 2;
    LPSTUDENT stu[3];
    
    for (i=2; i>=0;i--)
    {
        stu[i] = (LPSTUDENT)malloc(sizeof(tag_STUDENT));
        memset(stu[i],0,sizeof(tag_STUDENT));
        
        stu[i]->age = 1008611 + i;
        stu[i]->ID  = 181 + i;
        memset(stu[i]->name,0,sizeof(stu[i]->name));
        strcpy(stu[i]->name,str);
    }
    
    //  把 i 个 指针数组 传进去outputfun函数 
    outputfun(stu);

    for (i=2; i>=0;i--)
    {
        free(stu[i]);
    }
} 

//
//  结构体指针数组,LPSTUDENT pStu[3] 表示pStu指向3个都为LPSTUDENT类型指针的数组。
void outputfun(LPSTUDENT pStu[3])
{
    LPSTUDENT lpstu[3]; 
    int i;

    for (i=0; i<3; i++)
    {
        lpstu[i] = (LPSTUDENT)malloc(sizeof(tag_STUDENT));// 申请空间
        memset(lpstu[i],0,sizeof(tag_STUDENT)); // 内存清零
        memcpy(lpstu[i],pStu[i],sizeof(tag_STUDENT));// 数组复制
        
        printf("%s\n","  ");
        printf("===============第 %d 个数组=========\n",i+1);
        printf("age = %d\n",lpstu[i]->age);
        printf("ID = %d\n",lpstu[i]->ID );
        printf("name = %s\n",lpstu[i]->name);
        // 释放内存空间
        free(lpstu[i]);
    }
    
}

int main(int argc, char* argv[])
{
    setdatafun() ;
	return 0;
}


 6、CCtrlBox 实现水平滚动

添加成员函数:

 

void MyCListBox::UpdateListBoxWidth(CListBox * listBox)
{
    CClientDC dc(this);
	CFont * font = listBox->GetFont();
	dc.SelectObject(font);

	int i = 0,iCount,width = 0;
	CString str;
	CSize sz;
	iCount = listBox->GetCount();
	// 逐个listBox条目扫描
	for (i=0; i<iCount; i++)
	{
		listBox->GetText(i, str);
		sz = dc.GetTextExtent(str);
		sz.cx += 3 * ::GetSystemMetrics(SM_CXBORDER);
		if(sz.cx > width)
			width = sz.cx;
	}  
	listBox->SetHorizontalExtent(width+5);
}


在需要的更新滚动的地方加上:  UpdateListBoxWidth( 你的 listbox 指针 ) ;

 

 

 

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值