⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 minigui11.cpp

📁 mini gui的linux移植程序
💻 CPP
字号:
// MiniGUI11.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "resource.h"
#include "math.h"

#define MAX_LOADSTRING 100
#define IDC_EDIT 101
#define IDC_OK 102
#define IDC_EXIT 103



// Global Variables:
HINSTANCE hInst;								// current instance
TCHAR szTitle[MAX_LOADSTRING];								// The title bar text
TCHAR szWindowClass[MAX_LOADSTRING];								// The title bar text

// Foward declarations of functions included in this code module:
ATOM				MyRegisterClass(HINSTANCE hInstance);
BOOL				InitInstance(HINSTANCE, int);
LRESULT CALLBACK	WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK	About(HWND, UINT, WPARAM, LPARAM);

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
 	// TODO: Place code here.
	MSG msg;
	HACCEL hAccelTable;

	// Initialize global strings
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	LoadString(hInstance, IDC_MINIGUI11, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance);

	// Perform application initialization:
	if (!InitInstance (hInstance, nCmdShow)) 
	{
		return FALSE;
	}

	hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_MINIGUI11);

	// Main message loop:
	while (GetMessage(&msg, NULL, 0, 0)) 
	{
		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	return msg.wParam;
}



//
//  FUNCTION: MyRegisterClass()
//
//  PURPOSE: Registers the window class.
//
//  COMMENTS:
//
//    This function and its usage is only necessary if you want this code
//    to be compatible with Win32 systems prior to the 'RegisterClassEx'
//    function that was added to Windows 95. It is important to call this function
//    so that the application will get 'well formed' small icons associated
//    with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
	WNDCLASSEX wcex;

	wcex.cbSize = sizeof(WNDCLASSEX); 

	wcex.style			= CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc	= (WNDPROC)WndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= LoadIcon(hInstance, (LPCTSTR)IDI_MINIGUI11);
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW+1);
	wcex.lpszMenuName	= (LPCSTR)IDC_MINIGUI11;
	wcex.lpszClassName	= szWindowClass;
	wcex.hIconSm		= LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);

	return RegisterClassEx(&wcex);
}

//
//   FUNCTION: InitInstance(HANDLE, int)
//
//   PURPOSE: Saves instance handle and creates main window
//
//   COMMENTS:
//
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;
   HWND hEdit,hButtonOk,hButtonExit;

   hInst = hInstance; // Store instance handle in our global variable

   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
   hEdit=CreateWindow("EDIT",
						NULL,
						WS_CHILD | SS_SIMPLE | WS_VISIBLE | WS_BORDER,
						20,10,40,20,hWnd,NULL,
						hInst,NULL); 
   hButtonOk=CreateWindow("BUTTON",
						"OK",
						WS_CHILD | WS_VISIBLE | WS_BORDER,
						20,40,40,20,hWnd,NULL,
						hInst,NULL);
   hButtonExit=CreateWindow("BUTTON",
						"EXIT",
						WS_CHILD | WS_VISIBLE | WS_BORDER,
						20,70,40,20,hWnd,NULL,
						hInst,NULL);
   SetWindowLong(hEdit,GWL_ID,IDC_EDIT);
   SetWindowLong(hButtonOk,GWL_ID,IDC_OK);
   SetWindowLong(hButtonExit,GWL_ID,IDC_EXIT);

   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}

//
//  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND	- process the application menu
//  WM_PAINT	- Paint the main window
//  WM_DESTROY	- post a quit message and return
//
//

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	int i;
	PAINTSTRUCT ps;
	HDC hdc;
	HPEN hPen,hPenRed,hPenBlue;
	static int x=200,y=100;
	int x1,y1;
	static int nValue=0;

	switch (message) 
	{
		case WM_COMMAND:
			wmId    = LOWORD(wParam); 
			wmEvent = HIWORD(wParam); 
			// Parse the menu selections:
			switch (wmId)
			{
				case IDM_ABOUT:
					DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
					break;
				case IDM_EXIT:
					DestroyWindow(hWnd);
					break;
				case IDC_OK:		
					nValue= GetDlgItemInt(hWnd,IDC_EDIT,NULL,FALSE);
					if(nValue>60) 
					{
						MessageBox(hWnd,"The Number Should BeBetween 0 to 60",NULL,MB_OK);
						break;
					}
					x=200+100*sin(3.14/180* (float) nValue*6);
					y=200-100*cos(3.14/180* (float) nValue*6);
					InvalidateRect(hWnd,NULL,FALSE);
					break;
				case IDC_EXIT:
					PostQuitMessage(0);
					break;
				default:
					return DefWindowProc(hWnd, message, wParam, lParam);
			}
			break;
		case WM_PAINT:
			//hdc=GetDC(hWnd);
			hdc = BeginPaint(hWnd, &ps);
			// TODO: Add any drawing code here...
			hPen=CreatePen(PS_SOLID,2,RGB(0,0,0));
			hPenRed=CreatePen(PS_SOLID,3,RGB(255,0,0));
			SelectObject(hdc,hPenRed);
			Ellipse(hdc,90,90,310,310);
			hPenBlue=CreatePen(PS_SOLID,1,RGB(0,0,255));
			SelectObject(hdc,hPenBlue);
			Ellipse(hdc,100,100,300,300);
			Ellipse(hdc,197,197,203,203);
			for(i=0;i<12;i++)
			{
				x1=200+110*sin(3.14/180* (float) 30*i);
			    y1=200-110*cos(3.14/180* (float) 30*i);
				Ellipse(hdc,x1-3,y1-3,x1+3,y1+3);
			}
			MoveToEx(hdc,200,200,NULL);
			LineTo(hdc,x,y);
			SelectObject(hdc,hPen);
			EndPaint(hWnd, &ps);
			//ReleaseDC(hWnd,hdc);
			break;
		case WM_DESTROY:
			PostQuitMessage(0);
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
   }
	return 0;
}

// Mesage handler for about box.
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
		case WM_INITDIALOG:
				return TRUE;

		case WM_COMMAND:
			if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) 
			{
				EndDialog(hDlg, LOWORD(wParam));
				return TRUE;
			}
			break;
	}
    return FALSE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -