📄 3_6-week9labweek8samplecode1.txt
字号:
// MGProg_Lab4_1.cpp : Introduction to Graphical Interface
#include "stdafx.h"
#include <stdio.h>
HWND hWnd;
HINSTANCE hInst;
HBITMAP hbmp;
HDC mdc;
HDC hdc;
// Function Declaration
ATOM MyRegisterClass(HINSTANCE hInstance); // Declaration and register the Windows Object
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
// Main Program to Start
//////////////////////////////////////////////////////////////////////////
int APIENTRY WinMain(HINSTANCE hInstance, //
HINSTANCE hPrevInstance, //
LPSTR lpCmdLine, //
int nCmdShow) //
{ //
// TODO: Place code here. //
MSG msg; //
//
MyRegisterClass(hInstance); // Set Windows properties //
//
// Execute the initialize function //
if (!InitInstance(hInstance, nCmdShow)) // Create and Dispaly //
{ // the window //
return FALSE; //
} //
//
// Message Loop //
while (GetMessage(&msg, NULL, 0, 0)) //
{ //
TranslateMessage(&msg); //
DispatchMessage(&msg); //
} //
//
return msg.wParam; //
} //
//////////////////////////////////////////////////////////////////////////
// Declaration and register the Windows Object
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; // The most import part
wcex.hIcon = NULL;
wcex.hCursor = NULL;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = "canvas"; //It is not drawing
wcex.hIconSm = NULL;
return RegisterClassEx(&wcex);
}
// ********** Initialize Function *********************
// 1. To Save the instance handle into Global variable
// 2. Build up and display the windows
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance;
hWnd = CreateWindow("canvas", "The Paint Windows", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
MoveWindow(hWnd, 10, 10, 600, 450, true);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
// The Function to Handle different Events
// Message Call Back Handler
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -