当我在窗口中添加控件时出现图形问题(错误) [英] Graphic problems ( bugs ), when I add control in a window

查看:68
本文介绍了当我在窗口中添加控件时出现图形问题(错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!

我尝试在窗口中添加控件,但是控件出现图形问题.好吧,我知道,如果我在对话框窗口中添加控件,一切正常,但是我的情况又如何呢?

错误01
当应用程序启动时,groupbox的背景不好:
错误01
我如下解决:

Hello!

I try to add controls in a window, but graphic problems occur with my control. Well, I know that if I add control in a dialog window everithing is ok, but what about my case?

BUG 01
When the application start, background of groupbox is not good:
Bug 01
I solve it as follows:

// If this is TRUE, 1st problem is solved
if( FALSE ) {
    ShowWindow( hWnd, SW_MINIMIZE );
    ShowWindow( hWnd, SW_RESTORE );
}


无论如何,我不喜欢它,但是它可以工作

错误02
调整窗口大小时,我会看到:
错误02
我找不到解决此问题的方法!

目标
这是我想要实现的:
目标

这是整个程序(与VS2003,VS2008兼容):


Anyway, I do not like it, but it works

BUG 02
When size the window I see that:
Bug 02
I can not find a solution to this problem!

GOAL
This is what I want to achieve:
GOAL

This is the entire program ( VS2003, VS2008 compatible ):

#include <windows.h>
#include <commctrl.h>

const char *ClsName = "cn_TestSize";
const char *WndName = "TestSize";

// GroupBox Control
HWND hWndGroup;
// GroupBox relative dimensions
#define MACRO_GB_CONTROL	30, rc.top + 5, rc.right - 60, 50

LRESULT CALLBACK WndProcedure( HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam ) {
	switch( Msg ) {
		case WM_CREATE:
			{
				RECT rc;

				// Get size of the window
				GetClientRect( hWnd, &rc );

				// GroupBox Control
				hWndGroup = CreateWindowEx( NULL, WC_BUTTON, "Group Box",
					WS_VISIBLE | WS_CHILD | BS_GROUPBOX, MACRO_GB_CONTROL,
					hWnd, 0, GetModuleHandle( 0 ), NULL );

				// If this is TRUE, 1st problem is solved
				if( FALSE ) {
					ShowWindow( hWnd, SW_MINIMIZE );
					ShowWindow( hWnd, SW_RESTORE );
				}
			}
			break;
		case WM_SIZE:
			{
				RECT rc;
				GetClientRect( hWnd, &rc );
				MoveWindow( hWndGroup, MACRO_GB_CONTROL, TRUE );
			}
			break;
		case WM_DESTROY:
			PostQuitMessage(WM_QUIT);
			break;
		default:
			return DefWindowProc( hWnd, Msg, wParam, lParam );
	}
	return FALSE;
}

INT WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) {
	MSG			Msg;
	WNDCLASSEX	WndClsEx;
	HWND		hWnd;

	ZeroMemory( &WndClsEx, sizeof( WNDCLASSEX ) );

	WndClsEx.cbSize        = sizeof( WNDCLASSEX );
	WndClsEx.style         = CS_HREDRAW | CS_VREDRAW;
	WndClsEx.lpfnWndProc   = WndProcedure;
	WndClsEx.hIcon         = LoadIcon( NULL, IDI_APPLICATION );
	WndClsEx.hCursor       = LoadCursor( NULL, IDC_ARROW );
	WndClsEx.hbrBackground = (HBRUSH)COLOR_BTNSHADOW;
	WndClsEx.lpszClassName = ClsName;
	WndClsEx.hInstance     = hInstance;
	WndClsEx.hIconSm       = LoadIcon( NULL, IDI_APPLICATION );

	RegisterClassEx( &WndClsEx );

	hWnd = CreateWindow( ClsName,WndName, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN ,
		10, 10, 400, 240, NULL, NULL, hInstance, NULL );

	ShowWindow( hWnd, SW_SHOWNORMAL );
	UpdateWindow( hWnd );

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

	return (int)Msg.wParam;
}
</commctrl.h></windows.h>



如果您能帮助我,将不胜感激!



I would be grateful if you could help me!

推荐答案

从您的框架窗口样式中删除WS_CLIPCHILDREN.或调用InvalidateRect(hWndGroup,0,1);在WM_SIZE上.
问候.
Remove the WS_CLIPCHILDREN from your frame window style. Or call InvalidateRect( hWndGroup, 0, 1); on WM_SIZE.
Regards.


在哪里,何时以及如何处理消息(当需要重新绘制控件上的某些内容(WM_PAINT)时)?如果您在接收到WM_SIZE消息时使(<a href="http://msdn.microsoft.com/en-us/library/dd145002(v=vs.85).aspx">InvalidateRect</a>)客户区无效,则应该解决大小调整问题.您需要先确保正确地处理WM_PAINT.

问候,

—MRB
Where, when and how are you handling the message when something on the control needs to be repainted (WM_PAINT)? The sizing problem should be solved if you invalidate (<a href="http://msdn.microsoft.com/en-us/library/dd145002(v=vs.85).aspx">InvalidateRect</a>) the client area on receiving a WM_SIZE message. You need to make sure before though that you are handling WM_PAINT correctly.

Regards,

—MRB


这篇关于当我在窗口中添加控件时出现图形问题(错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆