I have an application in Visual c++ (Win32 API). In my application the main window boarder is displayed in old windows styled. I have tried changing the wndWc.style values to WS_OVERLAPPED,WS_POPUP and other which are given in WinUser.h but there is no change in the appearance of the main window were as all my pop-up window are displayed in windows 7 style how this can be rectified. Any help in this regards will be highly appreciated. I have attached both the images the main window and the pop up window.
Code :
// our window class
WNDCLASS wndWc;
// ---------------------------------------------------------
// fill window class members
// ---------------------------------------------------------
wndWc.style = CS_GLOBALCLASS;
wndWc.lpfnWndProc = (WNDPROC) WndProc;
wndWc.cbClsExtra = 0;
wndWc.cbWndExtra = 0;
wndWc.hInstance = GetModuleHandle(NULL);
wndWc.hIcon = NULL;
wndWc.hCursor = LoadCursor(0, IDC_ARROW);
wndWc.hbrBackground = (HBRUSH)GetStockObject(0);
wndWc.lpszMenuName = NULL;
wndWc.lpszClassName = "XYZ";
// register class
if (!RegisterClass(&wndWc)) return false;
// ---------------------------------------------------------
// get actual screen resolution
int iSw = (WORD)GetSystemMetrics(SM_CXSCREEN); // height
int iSh = (WORD)GetSystemMetrics(SM_CYSC开发者_开发知识库REEN); // height
// make a rectangle on the center of the screen
RECT rc = {(iSw - iWidth)/2, (iSh - iHeight)/2, width, height};
// create the window. the spaces on the window title
// are just to make sure this will be visible when the region
// is active. just run the app and you'll understand. =)
hWnd = CreateWindow("XYZ", "XYZ",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT, width,height,
NULL, NULL, GetModuleHandle(NULL), NULL);
It could be that your EXE has been flagged to run in compatibility mode for a previous OS version. Right-click the EXE, choose Properties, then ensure everything is switched off on the Compatibility tab. (Especially "Disable visual themes" and "run this program in compatibility mode for...")
Failing that...
It's unusual to need to do anything at all, but try this at the start of the app:
SetThemeAppProperties(STAP_ALLOW_NONCLIENT|STAP_ALLOW_CONTROLS)
If that doesn't work, try explicitly setting the theme for your window:
SetWindowTheme(hWnd, "WINDOW", NULL);
FWIW, I pasted your code in to a new Visual Studio 2008 project created using the "Win32 project" wizard, and it came out with a Windows 7 border. You usually have to go out of your way not to get the border, in fact.
There could be something unusual about the EXE you are building, like a flag in the EXE's header being set incorrectly. e.g. If it isn't specifying that it is a Windows GUI app, or maybe there are some version fields...
The EXE's manifest may also play a part, but I just tried deleting the manifest completely and my program still got a themed window, so it's probably not that.
If you look closely, you'll see that it's not just the border. The close button also uses the old visual style. Therefore, it's not sufficient that you change the window style. You must indicate that your app is Vista- and Aero-aware
精彩评论