当前位置:网站首页>使用C语言代码实现工厂端LCD RGB的测试程序
使用C语言代码实现工厂端LCD RGB的测试程序
2022-06-12 09:20:00 【Tody Guo】
如下代码使用CreateWindow实现窗口的最大无边框及最前代码,可以编译成32位或64位的程序均可。不用担心无法编译版本的问题。
#include <windows.h>
int i = 0;
/* This is where all the input to the window goes to */
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
HDC hdc; // handle to a device context
switch (Message) {
/* Upon destruction, tell the main thread to stop */
case WM_DESTROY: {
PostQuitMessage(0);
break;
}
case WM_LBUTTONDOWN:
case WM_KEYDOWN:
{
i++;
RECT rect;
hdc = GetDC(hwnd);
GetClientRect(hwnd, &rect);
switch (i) {
case 1:
FillRect(hdc, &rect, CreateSolidBrush(RGB(255, 0, 0)));
break;
case 2:
FillRect(hdc, &rect, CreateSolidBrush(RGB(0, 255, 0)));
break;
case 3:
FillRect(hdc, &rect, CreateSolidBrush(RGB(0, 0, 255)));
break;
case 4:
FillRect(hdc, &rect, CreateSolidBrush(RGB(255, 255, 255)));
break;
case 5:
ReleaseDC(hwnd, hdc);
PostQuitMessage(0);
break;
}
// release the dc back
ReleaseDC(hwnd, hdc);
}
/* 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.hbrBackground = CreateSolidBrush(RGB(0, 0, 0));
wc.lpszClassName = L"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, L"Window Registration Failed!", L"Error!", MB_ICONEXCLAMATION | MB_OK);
return 0;
}
hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,
L"WindowClass",
L"LCD RGB Test",
WS_VISIBLE | WS_POPUP | WS_MAXIMIZE | WS_THICKFRAME | WS_EX_TOPMOST,
0, /* x */
0, /* y */
1920, /* width */
1080, /* height */
NULL, NULL, hInstance, NULL);
if (hwnd == NULL) {
MessageBox(NULL, L"Window Creation Failed!", L"Error!", MB_ICONEXCLAMATION | MB_OK);
return 0;
}
LONG Style = GetWindowLongA(hwnd, GWL_STYLE);
Style = Style & ~WS_CAPTION & ~WS_SYSMENU & ~WS_SIZEBOX;
SetWindowLongA(hwnd, GWL_STYLE, Style);
/*
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;
}
边栏推荐
- Mysql database ignores case
- Selection of interview questions for software testing
- Autojs学习笔记6:text(txt).findOne()切换app时会报错,最后解决实现效果,切换任何app直到脚本找到指定的txt文字的控件进行点击。
- ABC253F Operations on a Matrix
- Is it necessary to separate databases and tables for MySQL single table data of 5million?
- Financial test interview questions to help you get the offer
- TAP 系列文章3 | Tanzu Application Platform 部署参考架构介绍
- ADB command collection, let's learn together
- NiO principle
- Consumer configuration related
猜你喜欢
Financial test interview questions to help you get the offer

Distributed transactions - Theoretical Overview

测试用例如何编写?
Database common interview questions are ready for you

Implementation of hotspot reference

JVM virtual machine

Node sample background setup
Share the basic knowledge of software testing and write something you don't know

QQ,微信能聊天都靠它(socket)?

Principle analysis of mongodb storage engine wiredtiger
随机推荐
自动化测试学习路线,快来学吧
Principle analysis of mongodb storage engine wiredtiger
Auto.js学习笔记9:脚本引擎使用,启动指定路径脚本文件和关闭等基础方法
After going to the bathroom, I figured out the ES search server
软件测试基础知识分享,写点你不知道的
MySQL installation
QQ,微信能聊天都靠它(socket)?
Test case and bug description specification reference
JVM virtual machine
Node sample background setup
Notes on data mining in Tsinghua University (1)
电阻的作用有哪些?(超全)
128. longest continuous sequence hash table
III Regular expression to finite state automata: NFA to DFA
Full alphabetic arrangement (pure alphabetic password dictionary)
MySQL learning record - II. MySQL create table command
Tool classes for extracting zip files
榜样访谈——董宇航:在俱乐部中收获爱情
Description of string
更改tabledata列名