怎么用Dev-C++来把二进制数转成二维码?
同上:怎么用Dev-C++来把二进制数转成二维码?
先建立一个windows项目
将程序改为以下的
#include <windows.h>
/* This is where all the input to the window goes to */
char data[35][36]=
{
"00000000000000000000000000000000000",
"01111111011101111010101110011111110",
"01000001010001100010101110010000010",
"01011101001111100001001100010111010",
"01011101010011100011011110010111010",
"01011101010011010000100101010111010",
"01000001011000001110111100010000010",
"01111111010101010101010101011111110",
"00000000000110101001111110000000000",
"00001001001010000100101011001110110",
"00101010011110100001110000001111000",
"00100001111000011001010010011111100",
"01100100110011000010111100000011010",
"00110011010111011000000110010001000",
"00011110000000110101101110100100110",
"00011101110111000001000100111011010",
"00100100110101010010101001110011110",
"00001011001100011010001000101111010",
"01011110100001000001110110011100010",
"00111011111001100101111111000111100",
"00011110100011000110011100001100100",
"00011101110010001011111111100001110",
"00000010000100010011010000100110100",
"01101101001010110001010010001011110",
"00110110111001100111110010011110010",
"01010111101100100110001011111101100",
"00000000010100100011010011000101110",
"01111111000110011001100101010111000",
"01000001000100100101011011000101010",
"01011101001010010101110001111111100",
"01011101010000111101101010101101010",
"01011101001101010110011011001010010",
"01000001000100010101000100101100010",
"01111111001001011110100011010011000",
"00000000000000000000000000000000000"
};
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
/* Upon destruction, tell the main thread to stop */
case WM_DESTROY:
{
PostQuitMessage(0);
break;
}
case WM_PAINT:
{
char c;
int x,y;
HDC dc=GetDC(hwnd);
for(x=0; x<35*4; x++)
for(y=0; y<35*4; y++)
{
c=data[x/4][y/4];
if (c=='0')
SetPixel(dc,x,y,0x00000000);
else
SetPixel(dc,x,y,0x00FF0000);
}
break;
}
/* All other messages (a lot of them) are processed using default procedures */
default:
return DefWindowProc(hwnd, Message, wParam, lParam);
}
return 0;
}
/* The 'main' function of Win32 GUI programs: this is where execution starts */
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc; /* A properties struct of our window */
HWND hwnd; /* A 'HANDLE', hence the H, or a pointer to our window */
MSG msg; /* A temporary location for all messages */
/* zero out the struct and set the stuff we want to modify */
memset(&wc,0,sizeof(wc));
wc.cbSize = sizeof(WNDCLASSEX);
wc.lpfnWndProc = WndProc; /* This is where we will send messages to */
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
/* White, COLOR_WINDOW is just a #define for a system color, try Ctrl+Clicking it */
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszClassName = "WindowClass";
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); /* Load a standard icon */
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); /* use the name "A" to use the project icon */
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
return 0;
}
hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,"WindowClass","Test",WS_VISIBLE|WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, /* x */
CW_USEDEFAULT, /* y */
35*4+30, /* width */
35*4+50, /* height */
NULL,NULL,hInstance,NULL);
if(hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
return 0;
}
/*
This is the heart of our program where all input is processed and
sent to WndProc. Note that GetMessage blocks code flow until it receives something, so
this loop will not produce unreasonably high CPU usage
*/
while(GetMessage(&msg, NULL, 0, 0) > 0) /* If no error is received... */
{
TranslateMessage(&msg); /* Translate key codes to chars if present */
DispatchMessage(&msg); /* Send it to WndProc */
}
return msg.wParam;
}
然后运行项目就可以看到结果的
下一篇:勇敢的心世界大战电脑版在哪儿下载
上一篇:为什么编程的代码都是英文呢?