gpt4 book ai didi

c++ - 尽管应用了已知的抗闪烁技术,但我的应用程序在调整大小时略微闪烁

转载 作者:太空狗 更新时间:2023-10-29 23:02:55 24 4
gpt4 key购买 nike

我从 WM_ERASEBKGND 处理程序返回ed 1L,通过添加 InvalidateRect( hWnd, NULL, FALSE ); 并删除了 CS_HREDRAW |来 self 的窗口类的 CS_VREDRAW 样式。

选项卡控件上的闪烁最为明显。这是一个说明问题的小演示:

1.) 在 Visual Studio 中创建空的 C++ 项目。

2.) 创建 header pomocne_funkcije.h 并复制/粘贴以下内容:

#include <windows.h>
#include <windowsx.h>
#include <comutil.h>
#include <commctrl.h>
#include <stdio.h>
#include <vector>
#include <ole2.h>
#include <string>
#include <stdlib.h>
#include <locale.h>
#include <Uxtheme.h>

#pragma comment( linker, "/manifestdependency:\"type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' \
language='*'\"")

#pragma comment( lib, "comctl32.lib")
#pragma comment( lib,"Msimg32.lib")
#pragma comment( lib, "comsuppw.lib")
#pragma comment( lib, "UxTheme.lib")

3.) 创建名为 main.cpp.cpp 文件并复制/粘贴以下内容:

#include "pomocne_funkcije.h"

static HINSTANCE hInst;

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
{
RECT rcClient = {0};
::GetClientRect( hwnd, &rcClient );

HWND hwndTab = CreateWindowEx( 0, WC_TABCONTROL,
L"Ugovori", WS_CHILD | WS_VISIBLE,
10, 10, rcClient.right - rcClient.left - 20,
rcClient.bottom - rcClient.top - 63,
hwnd, (HMENU)3000,
((LPCREATESTRUCT)lParam)->hInstance, 0 );

TCITEM tci = {0};

tci.mask = TCIF_TEXT;
tci.pszText = L"Основни подаци";
TabCtrl_InsertItem( hwndTab, 0, &tci );

tci.pszText = L"Анекси";
TabCtrl_InsertItem( hwndTab, 1, &tci );

tci.pszText = L"Подиѕвођачки радови";
TabCtrl_InsertItem( hwndTab, 2, &tci );

SendMessage( hwnd, WM_SETFONT,
(WPARAM)(HFONT)GetStockObject(DEFAULT_GUI_FONT),
(LPARAM)TRUE );

SendMessage( hwndTab, WM_SETFONT,
(WPARAM)(HFONT)GetStockObject(DEFAULT_GUI_FONT),
(LPARAM)TRUE );

}
return 0L;
case WM_MOVE:
case WM_MOVING:
case WM_SIZING:
case WM_SIZE:
{
RECT rcClient = {0};
GetClientRect( hwnd, &rcClient );

SetWindowPos( GetDlgItem( hwnd, 3000 ), NULL,
rcClient.left + 10, rcClient.top + 10,
rcClient.right - rcClient.left - 20,
rcClient.bottom - rcClient.top - 63,
SWP_NOZORDER | SWP_NOCOPYBITS );

InvalidateRect( hwnd, NULL, FALSE );
}
return 0L;
case WM_ERASEBKGND:
return 1L;
case WM_PAINT:
{
PAINTSTRUCT ps = {0};
HDC hdc = BeginPaint( hwnd, &ps );
SendMessage( hwnd, WM_PRINTCLIENT, (WPARAM)hdc, 0 );
EndPaint( hwnd, &ps );
}
return 0L;
case WM_PRINTCLIENT:
{
RECT rcClient = {0};
GetClientRect( hwnd, &rcClient );

FillRect( (HDC)wParam, &rcClient,
(HBRUSH)GetStockObject(WHITE_BRUSH) );
}
return 0L;
case WM_CLOSE:
::DestroyWindow(hwnd);
return 0L;
case WM_DESTROY:
::PostQuitMessage(0);
return 0L;
default:
return ::DefWindowProc( hwnd, msg, wParam, lParam );
}
return 0;
}

// WinMain

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
int nCmdShow)
{
// store hInstance in global variable for later use

hInst = hInstance;

WNDCLASSEX wc;
HWND hwnd;
MSG Msg;

// initialize common controls

INITCOMMONCONTROLSEX iccex;
iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
iccex.dwICC = ICC_LISTVIEW_CLASSES | ICC_UPDOWN_CLASS |
ICC_STANDARD_CLASSES | ICC_TAB_CLASSES;
InitCommonControlsEx(&iccex);

// register main window class

wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInst;
wc.hIcon = LoadIcon( hInstance, IDI_APPLICATION );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH );
wc.lpszMenuName = NULL;
wc.lpszClassName = L"Main_Window";
wc.hIconSm = LoadIcon( hInstance, IDI_APPLICATION );

if(!RegisterClassEx(&wc))
{
MessageBox(NULL,
L"Window Registration Failed!", L"Error!",
MB_ICONEXCLAMATION | MB_OK);

return 0;
}

// create main window

hwnd = CreateWindowEx( 0, L"Main_Window",
L"Contract manager",
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL, NULL, hInstance, 0 );

if(hwnd == NULL)
{
MessageBox(NULL, L"Nemogu da napravim prozor!", L"Greska!",
MB_ICONEXCLAMATION | MB_OK);

return 0;
}

ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);

while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}

return Msg.wParam;
}

我在 Windows XP 上使用 C++WinAPIVisual Studio 2008 中工作。

问题:

如何消除选项卡控件(以及窗口的其余部分)的闪烁?

谢谢。最好的祝福。

最佳答案

我认为你不需要这条线:

InvalidateRect( hwnd, NULL, FALSE );

因为当你调整表单大小时已经有一个强制重绘。我删除了它,窗口仍然显示并重新绘制,没有闪烁。

关于c++ - 尽管应用了已知的抗闪烁技术,但我的应用程序在调整大小时略微闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27083387/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com