您好,欢迎访问三七文档
#includewindows.h#includestdio.hLRESULTCALLBACKWndProc(HWNDhwnd,UINTuMsg,WPARAMwParam,LPARAMlParam);intWINAPIWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance,LPSTRlpCmdLine,intnCmdShow){//Éè¼ÆÒ»¸ö´°¿ÚÀàWNDCLASSwndcls;wndcls.style=CS_HREDRAW|CS_VREDRAW;wndcls.lpfnWndProc=WndProc;wndcls.cbClsExtra=0;wndcls.cbWndExtra=0;wndcls.hInstance=hInstance;wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);wndcls.lpszMenuName=NULL;wndcls.lpszClassName=111;RegisterClass(&wndcls);HWNDhwnd;hwnd=CreateWindow(111,hello,WS_OVERLAPPEDWINDOW,0,0,600,400,NULL,NULL,hInstance,NULL);ShowWindow(hwnd,SW_SHOWNORMAL);UpdateWindow(hwnd);MSGmsg;while(GetMessage(&msg,NULL,0,0)){TranslateMessage(&msg);DispatchMessage(&msg);}returnmsg.wParam;}LRESULTCALLBACKWndProc(HWNDhwnd,UINTuMsg,WPARAMwParam,LPARAMlParam){switch(uMsg){caseWM_CHAR:charszChar[20];sprintf(szChar,charcodeis%d,wParam);MessageBox(hwnd,szChar,char,0);break;caseWM_LBUTTONDOWN:MessageBox(hwnd,mouseclicked,message,0);HDChdc;hdc=GetDC(hwnd);TextOut(hdc,0,50,VC++³ÌÐòÉè¼Æ,strlen(VC++³ÌÐòÉè¼Æ));ReleaseDC(hwnd,hdc);break;caseWM_PAINT:HDChDC;PAINTSTRUCTps;hDC=BeginPaint(hwnd,&ps);TextOut(hDC,0,0,ÄãºÃ£¡,strlen(ÄãºÃ£¡));EndPaint(hwnd,&ps);break;caseWM_CLOSE:if(IDYES==MessageBox(hwnd,ÊÇ·ñÕæµÄ½áÊø£¿,message,MB_YESNO)){DestroyWindow(hwnd);}break;caseWM_DESTROY:PostQuitMessage(0);break;default:returnDefWindowProc(hwnd,uMsg,wParam,lParam);}return0;}
本文标题:C语言创建窗口代码
链接地址:https://www.777doc.com/doc-5160518 .html