我有这个程序,我在其中创建了一个窗口,并在其中使用纯 C(没有 MFC 或对话框)添加了一个编辑控件,编辑控件创建代码如下
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);
但是渲染的控件看起来很难看...
这就是我希望我的控件看起来像...
我尝试打电话InitCommonControlsEx
并包括在内comctl32.lib
,但没有任何改变。
我认为添加描述所有依赖项的应用程序清单文件可以解决问题,但我不知道如何使用 Visual Studio 1010 IDE(我自己无法编辑清单文件)
是否可以仅使用 c/c++(没有 MFC 或 .NET 之类的东西)获得正常的 vista 样式控件。如果添加清单资源可以解决问题,那么我如何编写/生成一个清单文件并将其添加到我的 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 字符集/库,现在视觉样式正在工作,除了编辑控件......看看..
我使用了编辑控件的样式 WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL|ES_NOHIDESEL