#include<stdio.h>
#include<windows.h>
#include "qrencode.h"
#include"stdafx.h"
#include<windows.h>
#define R 200
#define G 0
#define B 0
int a[25][25];
void GetArry();
LRESULT CALLBACK WndProc(HWND hwnd, UINT umsg, WPARAM wparam, LPARAM lparam)
{
HDC dc1;
RECT rec;
PAINTSTRUCT ps;
HBRUSH brush1;
HPEN pen1;
static int cxClient, cyClient;
switch (umsg)
{
case WM_SIZE:
cxClient = LOWORD(lparam);
cyClient = HIWORD(lparam);
break;
case WM_PAINT:
BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rec);
dc1 = GetDC(hwnd);
brush1 = CreateSolidBrush(RGB(R,G,B));
pen1 = CreatePen(PS_SOLID, 1, RGB(R, G, B));
SelectObject(dc1, brush1);
SelectObject(dc1, pen1);// 笔是用来填充边框的那一个像素
for (int i = 0; i<25; i++)
for (int j = 0; j < 25; j++)
{
if (a[i][j] == 1)
{
Rectangle(dc1, 10 * (i + 1), 10 * (j + 1), 10 * (i + 2), 10 * (j + 2));
}
}
EndPaint(hwnd, &ps);
ReleaseDC(hwnd,dc1);
break;
case WM_CLOSE:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, umsg, wparam, lparam); //默认的窗口处理函数
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevinstace, PSTR szCmdLine, int iCmdShow)
{
GetArry();
TCHAR szName[] = TEXT("My Windows"); //用于保存窗口类名
HWND hWnd;
MSG msg;
WNDCLASS wnd;
wnd.style = CS_VREDRAW | CS_HREDRAW;
wnd.lpfnWndProc = WndProc; //回调函数
wnd.cbClsExtra = 0;
wnd.cbWndExtra = 0;
wnd.hInstance = hInstance;// 应用程序实例句柄
wnd.hCursor = LoadCursor(NULL, IDC_ARROW);
wnd.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wnd.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wnd.lpszMenuName = NULL;
wnd.lpszClassName = szName; //指定窗口类名
if (!RegisterClass(&wnd))
{
MessageBox(NULL, TEXT("注册窗口失败!"), TEXT("警告"), MB_ICONWARNING);
return 0;
}
hWnd = CreateWindow(szName, TEXT("class"), WS_OVERLAPPEDWINDOW,
GetSystemMetrics(SM_CXSCREEN)/2-250, GetSystemMetrics(SM_CYSCREEN) / 2 - 250, //居中显示
500,500, NULL, NULL, hInstance, NULL);
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
while (GetMessage(&msg, 0, 0, 0))//获取到WM_CLOSE返回值为0,其他为非0值
{
TranslateMessage(&msg);// 将虚拟键消息转换为字符消息
DispatchMessage(&msg);// 将消息传送到窗口函数
}
return 0;
}
void GetArry()
{
QRcode *qrcode;
qrcode = QRcode_encodeString("This is a test", 2, QR_ECLEVEL_L, QR_MODE_8, 1);
int i, j;
for (i = 0; i<25; i++)
{
for (j = 0; j<25; j++)
{
if (qrcode->data[i * 25 + j] & 0x01)
{
a[i][j] = 1;
}
else
{
a[i][j] = 0;
}
}
}
}
另附 LibQREncode库
链接:http://pan.baidu.com/s/1kVwa5dd 密码:044t
使用方法:将整个目录放到工程目录下,并导入.c 和 .h 文件
VS配置: 项目属性 -> c/c++ -> 常规 -> 附加包含目录,添加 LibQREncode