[英]Why my edit control looks odd in my win32 c++ application using no MFC?
我有這個程序,我創建了一個窗口,在里面,我添加了一個使用普通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 charset / libraries,現在視覺樣式正在工作,除了編輯控件...看看..
我使用樣式進行編輯控制WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL | ES_NOHIDESEL
自從我做Win32 GUI之后很長一段時間,但是我記得你應該使用WS_EX_CLIENTEDGE而不是零作為擴展樣式(至少是凹陷的3D效果,不確定你對“動畫邊框”的意思)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.