当前位置:网站首页>使用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 learning records -- III. MySQL query statements
- Network layer IP protocol ARP & ICMP & IGMP nat
- Summary of APP test interview questions, which must be taken in the interview
- Leetcode 336 palindrome pair (palindrome string + hash)
- 2022 极术通讯-安谋科技纷争尘埃落定,本土半导体产业基石更稳
- Grab screen and ground glass effect
- Distributed transactions - Theoretical Overview
- ABC253F Operations on a Matrix
- 128. 最長連續序列-哈希錶
- Meeting time (topology sorting +dp)
猜你喜欢
随机推荐
(15) Tweenrunner
Implementation of hotspot synchronized
解压缩zip文件的工具类
Filters and listeners
Sword finger offer II 016 Longest substring without repeating characters - sliding window
Cas d'essai et spécification de description des bogues référence
L1-002 print Hourglass (20 points)
测试用例如何编写?
128. 最长连续序列-哈希表
Distributed transaction solution 1: TCC (compensation transaction)
Tool classes for extracting zip files
更改tabledata列名
How to write test cases?
Thread deadlock and its solution
Selenium interview question sharing
【云原生】Eureka服务注册的搭建
软件测试需求分析方法有哪些,一起来看看吧
Counting haybales (difference + discretization)
Unittest test framework
Hotspot Metaspace





