請使用API函數編寫程序,要求如下:
1.工程文件的名字取” 學號_姓名_課內考查”,工程文件中所有文件名均為“學號_姓名_課內考查”(包括.cpp,.rc,.h等文件),否則按照“未完成任務”處理(10分)
2.顯示一個WINDOWS窗口,窗口的標題為“學號_姓名_課內考查”,例如“2018620101_張三_課內考查”,演示錄屏時該窗口不能遮擋VC6.0窗口的左上側的文件列表,否則按未完成任務處理。(20分)
3.將光標設定為自己名字中的姓氏的第一個字,要求藍色字體,紅色背景。(10分)。
4.將圖標設定為自己名字中的最后一個字,要求綠色字體白色背景(10分)
5.在窗口的左半側顯示一組圖形并填充網格,如下圖(10分)
6.在窗口右半側顯示紅色正方形如下圖(10分)
7.創建一個菜單,其中有一個菜單項“文件”,“文件” 菜單項包含“創建”、 “刪除”、“退出”等項。選擇“創建”選項時則動態創建一個菜單“編輯”,該“編輯”菜單項包含“繪圖”選項,同時“創建”選項變為不可用狀態。選擇“刪除”選項時,則刪除菜單項“編輯”,同時“刪除”選項變為不可用狀態。選擇 “退出”選項時,退出程序(20分)
選擇“繪圖”選項時,則在窗口中間顯示下方圖形(在下一頁),要求第5,第6題的顯示圖不能消失,否則該題不得分。(10分)
#include<windows.h>
#include<stdlib.h>
#include<string.h>
#include<stdlib.h>
#include"resource.h"
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
BOOL CALLBACK DlgProc(HWND,UINT,WPARAM,LPARAM);
HINSTANCE hInst;
HWND hdlg;
HMENU hmenu,haddmenu;
int HUITU_flag=0;
//主函數
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{HWND hwnd;MSG Msg;HACCEL hAccel;WNDCLASS wndclass;char lpszMenuName[]="Menu";char lpszClassName[]="課內考察"; char lpszTitle[]="課內考察";wndclass.style=0;wndclass.lpfnWndProc=WndProc;//定義窗口處理函數wndclass.cbClsExtra=0;//窗口類無擴展wndclass.cbWndExtra=0;//窗口實例無擴展wndclass.hInstance=hInstance;//當前實例句柄wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);//窗口的最小化圖標為缺省圖標wndclass.hCursor=(HCURSOR)LoadImage(NULL,"課內考察.cur",IMAGE_CURSOR,72,32,LR_LOADFROMFILE);//光標為姓氏周,藍字紅底wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);//窗口背景為白色wndclass.lpszMenuName=MAKEINTRESOURCE(Menu);wndclass.lpszClassName=lpszClassName;wndclass.hIcon=LoadIcon(hInstance,"WEI");//加載圖標,圖標設定為自己名字中的最后一個字,要求綠色字體白色背景if( !RegisterClass( &wndclass)){ MessageBeep(0);return FALSE; }hwnd = CreateWindow( lpszClassName, lpszTitle,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance, NULL);ShowWindow(hwnd,nCmdShow);UpdateWindow(hwnd);hInst=hInstance;hAccel=LoadAccelerators(hInst,lpszMenuName);if(!IsDialogMessage(hdlg,&Msg)){if(!TranslateAccelerator(hwnd,hAccel,&Msg)){TranslateMessage(&Msg);DispatchMessage(&Msg);}}while(GetMessage(&Msg,NULL,0,0)){ TranslateMessage(&Msg); DispatchMessage(&Msg);}return Msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,UINT wParam,LONG IParam)
{HDC hDC;HBRUSH hBrush;HPEN hPen;PAINTSTRUCT PtStr;POINT points[6]={{100,212},{70,227},{70,250},{130,250},{130,227},{100,212}};switch(iMessage){case WM_COMMAND: // 菜單欄switch(LOWORD(wParam)){case IDM_CREATE://添加彈出式菜單編輯hmenu = GetMenu(hWnd);//獲取主菜單句柄haddmenu = CreateMenu();//動態創建菜單//在創建菜單中增加菜單項AppendMenu(haddmenu , MF_ENABLED , IDM_HUITU , "繪圖");//將創建的彈出式菜單插入主菜單中InsertMenu(hmenu , 2 , MF_POPUP|MF_BYPOSITION , (UINT)haddmenu , "編輯");//相應改變菜單中有關繪圖菜單項的屬性EnableMenuItem(hmenu , IDM_CREATE , MF_GRAYED);//按下創建后創建變灰色不能按EnableMenuItem(hmenu , IDM_DELETE , MF_ENABLED);//刪除由灰色變能按的DrawMenuBar(hWnd);break;case IDM_DELETE://按下刪除后刪除了編輯菜單欄DeleteMenu(hmenu , 1 , MF_BYPOSITION);//刪除編輯欄//相應改變其余屬性EnableMenuItem(hmenu , IDM_CREATE , MF_ENABLED);//可重新創建EnableMenuItem(hmenu , IDM_DELETE , MF_GRAYED);//刪除鍵變灰色DrawMenuBar(hWnd);break;case IDM_HUITU:HUITU_flag=1;InvalidateRect(hWnd,NULL,1);break;case IDM_EXIT:SendMessage(hWnd,WM_DESTROY,0,0);break;}break;case WM_PAINT:hDC=BeginPaint(hWnd,&PtStr);hPen=(HPEN)GetStockObject(NULL_PEN);SelectObject(hDC,hPen);hBrush=CreateHatchBrush(HS_CROSS,RGB(255,0,0));SelectObject(hDC,hBrush);LineTo(hDC,50,50);DeleteObject(hPen);hPen=CreatePen(PS_SOLID,2,RGB(0, 180, 255));//顏色天藍色SelectObject(hDC,hPen);Pie(hDC,213,137,288,212,240,137,260,137);//三個圖案Rectangle(hDC,213,212,287,250);RoundRect(hDC,213,100,287,137,20,20);hPen=CreatePen(PS_SOLID,2,RGB(0, 0, 0));//筆色黑SelectObject(hDC,hPen);hBrush=CreateSolidBrush(RGB(255,0,0));SelectObject(hDC,hBrush);Rectangle(hDC,800,100,900,200);//黑筆紅刷正方形,在右側if(HUITU_flag == 1){hPen=CreatePen(PS_SOLID,2,RGB(0, 0, 0));//筆色黑SelectObject(hDC,hPen);hBrush=CreateSolidBrush(RGB(255,255,255));SelectObject(hDC,hBrush);RoundRect(hDC,500,200,700,400,20,20);hBrush=CreateSolidBrush(RGB(0,0,0));SelectObject(hDC,hBrush);Ellipse(hDC,500,250,700,350);}DeleteObject(hPen);DeleteObject(hBrush);EndPaint(hWnd,&PtStr);return 0;case WM_DESTROY:PostQuitMessage(0);return 0;default:return DefWindowProc(hWnd,iMessage,wParam,IParam);}return 0;
}BOOL CALLBACK DlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam)
{switch(message){case WM_INITDIALOG:return 1;case WM_COMMAND:switch(LOWORD(wParam)){case IDOK:DestroyWindow(hdlg);return 1;}break;case WM_CLOSE:DestroyWindow(hdlg);return 1;}return 0;
}
頭文件
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by 課內考察.rc
//#define Menu 103
#define IDM_CREATE 10
#define IDM_DELETE 11
#define IDM_EXIT 15
#define IDM_HUITU 16// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
WEI ICON 課內考察.icoMenu MENU DISCARDABLE
{POPUP"文件(&F)"
{ MENUITEM "創建(&C)\t Ctrl+C", IDM_CREATEMENUITEM SEPARATOR MENUITEM "刪除(&S)\t Ctrl+D", IDM_DELETEMENUITEM SEPARATOR MENUITEM "退出(&X)", IDM_EXIT
}}
Menu ACCELERATORS{"^C", IDM_CREATE"^D", IDM_DELETE }About DIALOG 50, 50, 100, 50STYLE WS_POPUP | WS_CAPTION | WS_SYSMENU|WS_VISIBLECAPTION "關于"FONT 12, "楷體" {CTEXT "Windows模態對話框",-1,13,10,80,10DEFPUSHBUTTON "確定",IDOK,35,30,30,12}
總結
以上是生活随笔為你收集整理的可视化期末考察的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。