为什么我的编辑控制看起来奇怪在我的win32 c ++应用程序没有MFC? [英] Why my edit control looks odd in my win32 c++ application using no MFC?
问题描述
我有这个程序,我创建一个窗口,里面,我添加了一个编辑控件使用简单的C(没有MFC或对话框),编辑控制创建代码为
I have this program where i created a window and inside that i added an edit control using plain C (no MFC or dialogs), the edit control creation code is as
hWnd=::CreateWindowExA(NULL, //no extended style
"EDIT",
NULL, //no title
WS_CHILD|WS_VISIBLE|WS_BORDER,
x,
y,
Width,
Height,
hWndParent,
(HMENU)id,
(HINSTANCE) GetWindowLong(hWndParent, GWL_HINSTANCE),//the module instance
NULL);
但呈现的控制项看起来很丑陋...
But the rendered control looks ugly...
$
这里是我想要的控件看起来像...
$
And here's what i want my controls to look like...
我尝试调用 InitCommonControlsEx
,并包括 comctl32 .lib
但没有更改。
我想添加一个描述所有依赖项的应用程序清单文件将解决这个问题,但我不知道如何使用Visual Studio 1010 IDE(我不能自己编辑清单文件)
I tried calling InitCommonControlsEx
and included comctl32.lib
but nothing changed.
I think adding an application manifest file describing all the dependencies would fix the problem but I don't know how to do that using Visual Studio 1010 IDE(I can't edit a manifest file myself)
可以只使用c / c ++获得正常的vista样式控件)。如果添加清单资源会解决这个问题,那么如何编写/生成一个清单文件并将其添加到我的exe?
Is it possible to get the normal vista style controls using just c/c++(no MFC or anything like .NET). If adding manifest resource would fix the problem then how can I write/generate one manifest file and add it to my exe?
#include<Windows.h>
#include <commctrl.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")
HWND hwndEdit;
LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM wp,LPARAM lp)
{
switch(uMsg)
{
case WM_CREATE:
hwndEdit = CreateWindow(
"EDIT", /* predefined class */
NULL, /* no window title */
WS_CHILD | WS_VISIBLE |
ES_LEFT | ES_AUTOHSCROLL|WS_BORDER,
0, 0, 100, 50, /* set size in WM_SIZE message */
hWnd, /* parent window */
(HMENU) 1, /* edit control ID */
(HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE),
NULL); /* pointer not needed */
return 0;
break;
case WM_CLOSE:
::PostQuitMessage(0);//quit application
break;
default:
return ::DefWindowProcA(hWnd,uMsg,wp,lp);
}
return 0l;
}
int WINAPI WinMain(HINSTANCE hinstance,HINSTANCE hPrevinstance,char *cmd,int show)
{
INITCOMMONCONTROLSEX icc;
icc.dwICC=ICC_ANIMATE_CLASS|ICC_NATIVEFNTCTL_CLASS|ICC_STANDARD_CLASSES;
icc.dwSize=sizeof(icc);
InitCommonControlsEx(&icc);
char* tst="Simple edit control";
WNDCLASSEX mywindow;
MSG msg;
HWND hwnd;
mywindow.cbClsExtra=0;
mywindow.cbWndExtra=0;
mywindow.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
mywindow.hCursor=LoadCursor(NULL,IDC_CROSS);
mywindow.hIcon=LoadIcon(NULL,IDI_APPLICATION);
mywindow.hInstance=hinstance;
mywindow.lpfnWndProc=WndProc;
mywindow.lpszClassName="Test";
mywindow.lpszMenuName=NULL;
mywindow.style=0;
mywindow.cbSize=sizeof(WNDCLASSEX);
mywindow.hIconSm=NULL;
if(!RegisterClassEx(&mywindow))
MessageBox(NULL,"Window Registration failed","Error occured",NULL);
hwnd=CreateWindowEx(WS_EX_TOPMOST,"Test","My window",WS_OVERLAPPEDWINDOW,900,300,400,350,NULL,NULL,hinstance,tst);
if(hwnd==NULL)
MessageBox(NULL,"Window creation failed","error",NULL);
::ShowWindow(hwnd,SW_SHOW);
::UpdateWindow(hwnd);
while (1) //NOTE: Game engine type message loop
{ Sleep(1);
if ( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) )
{
if (msg.message == WM_QUIT)
break;
TranslateMessage( &msg );
DispatchMessage ( &msg );
}
}
return msg.wParam;
}
更新:我更新了我的项目使用unicode charset / libraries,正在工作除了编辑控制...看看。
我使用样式进行编辑控制WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL | ES_NOHIDESEL
UPDATE: I updated my project to use unicode charset/libraries and now visual styles are working except for the edit control...take a look..
I used styles for edit control WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL|ES_NOHIDESEL
推荐答案
启用视觉样式: http://msdn.microsoft.com/en-us/library/bb773175 .aspx
这篇关于为什么我的编辑控制看起来奇怪在我的win32 c ++应用程序没有MFC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!