1,创建进程 #include < windows.h > #include < stdio.h > int main(VOID) {STARTUPINFOsi;PROCESS_INFORMATIONpi;ZeroMemory(&si,sizeof(si));si.cb=sizeof(si);ZeroMemory(&pi,sizeof(pi));//Startthechildprocess.if(!CreateProcess(NULL,//Nomodulename(usecommandline)."C://WINDOWS//system32//mspaint.exe",//Commandline.NULL,//Processhandlenotinheritable.NULL,//Threadhandlenotinheritable.FALSE,//SethandleinheritancetoFALSE.0,//Nocreationflags.NULL,//Useparent'senvironmentblock.NULL,//Useparent'sstartingdirectory.&si,//PointertoSTARTUPINFOstructure.&pi)//PointertoPROCESS_INFORMATIONstructure.){printf("CreateProcessfailed(%d)./n",GetLastError());return-1;}//Waituntilchildprocessexits.WaitForSingleObject(pi.hProcess,INFINITE);//Closeprocessandthreadhandles.CloseHandle(pi.hProcess);CloseHandle(pi.hThread);} <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> 2,创建线程 #include < stdio.h > #include < iostream > #include < windows.h > using namespace std;DWORDSum; /**/ /*dataissharedbythethread(s)*/ /**/ /*thethreadrunsinthisseparatefunction*/ DWORDWINAPISummation(PVOIDParam) {DWORDUpper=*(DWORD*)Param;for(DWORDi=0;i<=Upper;i++)Sum+=i;return0;} int main( int argc, char * argv[]) {DWORDThreadId;HANDLEThreadHandle;intParam=100;if(Param<0){fprintf(stderr,"aninteger>=0isrequired/n");return-1;}//createthethreadThreadHandle=CreateThread(NULL,0,Summation,&Param,0,&ThreadId);if(ThreadHandle!=NULL){WaitForSingleObject(ThreadHandle,INFINITE);CloseHandle(ThreadHandle);printf("sum=%d/n",Sum);}} 3,加载BMP文件 #include < windows.h > #include < fstream > using namespace std; char szAppName[] = " BMPLoad " ;LRESULTCALLBACKWindowProc(HWND,UINT,WPARAM,LPARAM); // ********** // classCRaster // -GenericclassforBMPrasterimages. class CRaster {public:intWidth,Height;//DimensionsintBPP;//BitsPerPixel.char*Raster;//BitsoftheImage.RGBQUAD*Palette;//RGBPalettefortheimage.intBytesPerRow;//RowWidth(inbytes).BITMAPINFO*pbmi;//BITMAPINFOstructure//Memberfunctions(definedlater):intLoadBMP(char*szFile);intGDIPaint(HDChdc,intx,inty);} ; // ********** // WindowsMainFunction. // -Herestartsourdemoprogram int WINAPIWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance,LPSTRlpCmdLine, int nCmdShow) {HWNDhwnd;MSGmsg;WNDCLASSwc;wc.style=CS_HREDRAW|CS_VREDRAW;wc.lpfnWndProc=WindowProc;wc.cbClsExtra=0;wc.cbWndExtra=0;wc.hInstance=hInstance;wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);wc.hCursor=LoadCursor(NULL,IDC_ARROW);wc.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);wc.lpszMenuName=NULL;wc.lpszClassName=szAppName;RegisterClass(&wc);hwnd=CreateWindow(szAppName,"BMPLoad",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,0,0,hInstance,0);ShowWindow(hwnd,nCmdShow);UpdateWindow(hwnd);while(GetMessage(&msg,0,0,0)){TranslateMessage(&msg);DispatchMessage(&msg);}returnmsg.wParam;} // ********** // MainWindowProcedure. // -ProcessesWindowMessages LRESULTCALLBACKWindowProc(HWNDhwnd,UINTmessage,WPARAMwParam,LPARAMlParam) {staticCRasterbmp;HDChdc;PAINTSTRUCTps;switch(message){caseWM_CREATE:bmp.LoadBMP("example.bmp");return0;caseWM_PAINT:hdc=BeginPaint(hwnd,&ps);bmp.GDIPaint(hdc,10,10);EndPaint(hwnd,&ps);return0;caseWM_DESTROY:PostQuitMessage(0);return0;}returnDefWindowProc(hwnd,message,wParam,lParam);} // ********** // CRaster::LoadBMPFile(FileName); // -loadsaBMPfileintoaCRasterobject // *supportsnon-RLE-compressedfilesof1,2,4,8&24bits-per-pixel int CRaster::LoadBMP( char * szFile) {BITMAPFILEHEADERbmfh;BITMAPINFOHEADERbmih;//Openfile.ifstreambmpfile(szFile,ios::in|ios::binary);if(!bmpfile.is_open())return1;//Erroropeningfile//Loadbitmapfileheader&infoheaderbmpfile.read((char*)&bmfh,sizeof(BITMAPFILEHEADER));bmpfile.read((char*)&bmih,sizeof(BITMAPINFOHEADER));//Checkfiletypesignatureif(bmfh.bfType!='MB')return2;//FileisnotBMP//Assignsomeshortvariables:BPP=bmih.biBitCount;Width=bmih.biWidth;Height=(bmih.biHeight>0)?bmih.biHeight:-bmih.biHeight;//absoultevalueBytesPerRow=Width*BPP/8;BytesPerRow+=(4-BytesPerRow%4)%4;//intalignment//IfBPParen't24,loadPalette:if(BPP==24)pbmi=(BITMAPINFO*)newchar[sizeof(BITMAPINFO)];else{pbmi=(BITMAPINFO*)newchar[sizeof(BITMAPINFOHEADER)+(1<<BPP)*sizeof(RGBQUAD)];Palette=(RGBQUAD*)((char*)pbmi+sizeof(BITMAPINFOHEADER));bmpfile.read((char*)Palette,sizeof(RGBQUAD)*(1<<BPP));}pbmi->bmiHeader=bmih;//LoadRasterbmpfile.seekg(bmfh.bfOffBits,ios::beg);Raster=newchar[BytesPerRow*Height];//(ifheightispositivethebmpisbottom-up,readitreversed)if(bmih.biHeight>0)for(intn=Height-1;n>=0;n--)bmpfile.read(Raster+BytesPerRow*n,BytesPerRow);elsebmpfile.read(Raster,BytesPerRow*Height);//so,wealwayshaveaup-bottomraster(thatisnegativeheightforwindows):pbmi->bmiHeader.biHeight=-Height;bmpfile.close();return0;} // ********** // CRaster::GDIPaint(hdc,x,y); // *PaintsRastertoaWindowsDC. int CRaster::GDIPaint(HDChdc, int x = 0 , int y = 0 ) {//Painttheimagetothedevice.returnSetDIBitsToDevice(hdc,x,y,Width,Height,0,0,0,Height,(LPVOID)Raster,pbmi,0);}