📄 simplewin.cpp
字号:
// WindowExample.cpp : Defines the entry point for the application.
////////////////////////////////////////////////
#include "windows.h"
//#include <stdlib.h>
//#include <malloc.h>
//#include <memory.h>
#include "resource.h"
#include "winuser.h"
#include "string.h"
//#include "simplewin.h"
// Global Variables:
HWND hEditItem,hEditResult,hButtonAdd,hButtonReset,hButtonCancle,
hStatic1,hStatic2;
HINSTANCE hInst;
HWND hWndMain;
int nResult,nAddItem;
////
LRESULT _stdcall WndProc(HWND, UINT, WPARAM, LPARAM);
BOOL InitApplication(HINSTANCE);
BOOL InitInstance(HINSTANCE, int);
char* hello1="诺贝尔物理学奖获得者李政道先生说:创造性";
char* hello2="人才的培养是师傅与徒弟对一些专题共同研究、";
char* hello3="共同学习的结果,这个过程需要经过几年的熏陶。";
char* hello4="现代化的教学手段和班级授课制可以加快知识的传授";
char* hello5="却难以达到培养创造性人才的目的!牛津大学是培养创造性人才的典范!";
// Foward declarations of functions included in this code module:
LRESULT CALLBACK WeiDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
int _stdcall WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg;
HACCEL hAccel;
if (!InitApplication(hInstance))
{
return FALSE;
}
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccel = LoadAccelerators(hInstance, (LPCTSTR)IDR_ACCELERATOR1);
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if(!TranslateAccelerator(hWndMain,hAccel,&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.
//
BOOL InitApplication(HINSTANCE hInstance)
{
//WNDCLASS wcSimpwin;
//HANDLE hMod;
// FARPROC proc;
WNDCLASS wcSimpwin;
// hMod = GetModuleHandle ("USER32");
//if (hMod != NULL) {
//#if defined (UNICODE)
// proc = GetProcAddress (hMod, "RegisterClassExW");
//#else
// proc = GetProcAddress (hMod, "RegisterClassExA");
// #endif
wcSimpwin.style = NULL;
wcSimpwin.lpfnWndProc = (WNDPROC)WndProc;
wcSimpwin.cbClsExtra = 0;
wcSimpwin.cbWndExtra = 0;
wcSimpwin.hInstance = hInstance;
wcSimpwin.hIcon = LoadIcon(hInstance,(LPCSTR)IDI_ICON1);
wcSimpwin.hCursor = LoadCursor(hInstance, (LPCSTR)IDC_CUR);
wcSimpwin.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcSimpwin.lpszMenuName =(LPCSTR)ID_AppMenu;
wcSimpwin.lpszClassName = "SimpwinWClass";
return RegisterClass(&wcSimpwin);
//// }
//}
//return (RegisterClass(lpwc));
}
//
// FUNCTION: InitInstance(HANDLE, int)
//
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
// HMENU hMenu;
hInst = hInstance; // Store instance handle in our global variable
// hMenu=LoadMenu(hInstance,"ID_AppMenu");
hWnd = CreateWindow("SimpwinWClass", "我的窗口", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
// hMenu=LoadMenu(hInstance,"ID_AppMenu");
// SetMenu(hWnd,hMenu);
if (!hWnd)
{
return FALSE;
}
hWndMain=hWnd;
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
// WM_DESTROY - post a quit message and return
//
LRESULT _stdcall WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
// WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
HPEN hP;
switch (message)
{
case WM_CREATE:
break;
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case ID_SHOWDIALOG:
DialogBox(hInst, (LPCTSTR)IDD_DIALOG1, hWnd, (DLGPROC)WeiDialog);
break;
case ID_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
TextOut(hdc, 20,10,hello1,lstrlen(hello1));
TextOut(hdc, 20,30,hello2,lstrlen(hello2));
TextOut(hdc, 20,50,hello3,lstrlen(hello3));
TextOut(hdc, 20,70,hello4,lstrlen(hello4));
TextOut(hdc, 20,90,hello5,lstrlen(hello5));
hP=CreatePen(PS_DASHDOT,1,RGB(0,255,0));//PS_SOLID实线
SelectObject(hdc,hP);
Ellipse(hdc,410,110,190,300);
EndPaint(hWnd, &ps);
break;
case ID_AppMenu:
DialogBox(hInst, (LPCTSTR)IDD_DIALOG1, hWnd, (DLGPROC)WeiDialog);
break;
case WM_DESTROY:
PostQuitMessage(WM_QUIT);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
LRESULT CALLBACK WeiDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{//对话框的参数和窗口过程完全一致
switch (message)
{
case WM_INITDIALOG:
SetDlgItemInt(hDlg,IDC_EDIT1,0,TRUE);
// SetFocus(GetDlgItem(hDlg,IDC_EDIT1));
//
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam))
{case IDOK:
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
case IDC_BUTTON1:
BOOL bErr;
nAddItem=GetDlgItemInt(hDlg,IDC_EDIT1,&bErr,TRUE);
nResult+=nAddItem;
SetDlgItemInt(hDlg,IDC_EDIT2,nResult,TRUE);
break;
case IDC_BUTTON2:
SetDlgItemInt(hDlg,IDC_EDIT1,0,TRUE);
SetDlgItemInt(hDlg,IDC_EDIT2,0,TRUE);
nResult=0;
break;
}
break;
}
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -