只输出最终的一个调用结果 。一开始怀疑是 console 程序和 win32 界面程序的不同,决定新建一个新的 win32 应用试试,由于 Win32 应用的主线程要做消息循环,这里启动一个单独的线程跑扫码的逻辑:
int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow){ UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); // TODO: Place code here. // Initialize global strings LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadStringW(hInstance, IDC_DEMOHIDPROTOCAL, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // Perform application initialization: if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } hThread = CreateThread(NULL, 0, qrscanner_loop, NULL, 0, NULL); HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_DEMOHIDPROTOCAL)); MSG msg; // Main message loop: while (GetMessage(&msg, nullptr, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return (int) msg.wParam;}qrscanner_loop 就是之前 console main 那一堆东西了,为了展示信息,在默认的视图中间填充一个 edit 控件:
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow){ hInst = hInstance; // Store instance handle in our global variable HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr); if (!hWnd) { return FALSE; } RECT rect = { 0 }; GetClientRect(hWnd, &rect); hEdit = CreateWindowW(TEXT("Edit"), TEXT(""), WS_CHILD | WS_VISIBLE | ES_LEFT | ES_MULTILINE | ES_WANTRETURN | WS_VSCROLL | ES_AUTOVSCROLL, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, hWnd, (HMENU)10002, hInstance, NULL); ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return TRUE;}至于编辑框随视图大小变化而变化这种基本功,就不赘述了,后面会放出完整源码 。注意这里的 hEdit,它存储着编辑框的句柄,后面会用到 。
经验总结扩展阅读
- 通过openlayers加载dwg格式的CAD图并与互联网地图叠加
- 互联网电视机哪个好 国产品牌小米果断上榜
- vivo互联网机器学习平台的建设与实践
- Go的网络编程详解
- bt是什么
- 三星手机互联网已停止如何修复
- 为什么互联网公司没有进入汽车终端领域
- MES与工业互联网的关联边界在哪里?
- 工业互联网领域的企业,都已经接入了ERP或者MES系统了吗?
- 互联网迷信是什么意思?