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...
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)
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;
}
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
Enabling Visual Styles: http://msdn.microsoft.com/en-us/library/bb773175.aspx
It was a long time since I was doing Win32 GUI stuff but as I remember it you should use WS_EX_CLIENTEDGE and not zero as an extended style (at least the sunken 3d effect, not sure what you mean with the "Animated border").
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With