📄 llk.cpp
字号:
// Superllk.cpp : Defines the entry point for the application.
//
/////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "resource.h"
#include "LLK.h"
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_LLK, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// BOOL MessageBeep( MB_ICONQUESTION); // just for fun
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_LLK);
srand( (unsigned)time( NULL ) );
// 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.
//
//
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_LLK);
wcex.hCursor = LoadCursor(hInstance,MAKEINTRESOURCE(154) );
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = (LPCSTR)IDC_LLK;
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
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hwnd;
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);
win_hWnd=hwnd;
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;
PAINTSTRUCT ps;
HDC hdc;
static int cxClient, cyClient,cxSource,cySource;
LPCREATESTRUCT lpcs;
HDC hCompatibleDC;
static HBITMAP map;
static BITMAP bitmap;
RECT rect;
TCHAR szHello[MAX_LOADSTRING];
////////////////////////
int wm_paint_count =0;
////////////////////////
LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
// PlaySound("backgroundsound",hInst,SND_ASYNC|SND_LOOP);
switch (message)
{
case WM_CREATE:
lpcs = (LPCREATESTRUCT) lParam;
map=::LoadBitmap(lpcs->hInstance,MAKEINTRESOURCE(IDB_BITMAP1));
GetObject (map, sizeof (BITMAP), &bitmap) ;
return 0 ;
case WM_SIZE:
cxSource = bitmap.bmWidth ;
cySource = bitmap.bmHeight ;
cxClient = LOWORD (lParam) ;
cyClient = HIWORD (lParam) ;
return 0 ;
case WM_LBUTTONDOWN:
int x,y;
int i,j,n;
x = LOWORD (lParam);
y = HIWORD (lParam);
MouseToMat(x,y);
if(true==First)
{
x1=x;
y1=y;
}
if(false==First && true==INIT)
{
x2=x;
y2=y;
IfConnect(x1,y1,x2,y2);
if(IfConnect(x1,y1,x2,y2)==true)MessageBeep (0) ;
OnPaint();
}
First=!First;
n=0;
for(i=0;i<WIDTH;i++)
{
for(j=0;j<HEIGHT;j++)
{
if(MATRIX[i][j]==0)
n++;
}
}
if(n==HEIGHT*WIDTH)
::MessageBox(NULL, "Hello boys and girls", "Greeting", MB_OK);
return 0;
case WM_PAINT:
GetClientRect(hwnd, &rect);
hdc=GetDC(hwnd);
hCompatibleDC=::CreateCompatibleDC(hdc);
::SelectObject(hCompatibleDC,map);
::BitBlt(hdc,0,0,cxClient,cyClient,hCompatibleDC,0,0,SRCCOPY);
::DeleteDC(hCompatibleDC);
BeginPaint(hwnd,&ps);
EndPaint(hwnd,&ps);
if(INIT==true)
{
OnPaint();
}
return 0 ;
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 32772:
InitMat();
OnPaint();
INIT=true;
break;
case 32777:
RandMat();
OnPaint();
break;
case 32785:
InitMat();
OnPaint();
break;
/* case IDM_PAUSE:
hdc=BeginPaint(hwnd,&ps);
sprintf(buffer,"WM_PAINT called %d times. ", ++wm_paint_count);
TextOut(hdc, 0,0, buffer, strlen(buffer));
EndPaint(win_hWnd,&ps);
Game_Pause();*/
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
// Message 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;
}
///////////////////////////////////////////////////////////////////////////////////////////////
/*int Game_Pause()
{
TCHAR szPause [MAX_LOADSTRING];
PPAINTSTRUCT ps;
HDC hdc;
HWND hwnd ;
LoadString(hInst, IDS_PAUSE, szPause, MAX_LOADSTRING);
hdc = BeginPaint(hwnd, &ps);
// TODO: Add any drawing code here...
RECT rt;
GetClientRect(hwnd, &rt);
DrawText(hdc, szPause, strlen(szPause), &rt, DT_LEFT);
EndPaint(hwnd, &ps);
return(0);
}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -