NO

Author Topic: Style won't change: Win32 app and CreateWindowEx  (Read 7645 times)

admiraln

  • Guest
Style won't change: Win32 app and CreateWindowEx
« on: February 24, 2013, 08:19:22 PM »
On the recomendation from this post http://forum.pellesc.de/index.php?topic=3348.msg12703#msg12703
on C tutorials for windows programming I am running through the tutorial.   

To set the stage I am an experience programmer but not in C nor the Win32 API.

I am running PellesC 64 bit under Windows 7.

As I compiled each example I would fiddle with the parameters for each call to see how things
changed.

In the second example in the tutorial on the call

 hwnd = CreateWindowEx(
     WS_EX_CLIENTEDGE,
     g_szClassName,
     "The title of my window",
     WS_OVERLAPPEDWINDOW,
     CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
     NULL, NULL, hInstance, NULL);

the first parameter is a frame styling parameter.
http://msdn.microsoft.com/en-us/library/windows/desktop/ff700543%28v=vs.85%29.aspx.

I tried changing them to different values (0,WS_EX_CLIENTEDGE,WS_EX_WINDOWEDGE etc)
and got the same results each time.  There were no visible style differences.

Being unfamiliar with too many things at once : C, Win32 API, Pelles C compiler settings I am not sure
were to look for the reason for this.    Suggestions.

I attached the source from the tutorial.

I will continue looking at this so I may have more detail later

Offline Stefan Pendl

  • Global Moderator
  • Member
  • *****
  • Posts: 582
    • Homepage
Re: Style won't change: Win32 app and CreateWindowEx
« Reply #1 on: February 24, 2013, 10:23:13 PM »
The extended and regular window styles are not only for edge styles, but change quite much of a window or widget.

In addition the styles are heavily bound to the type of window/widget you are creating, so they highly depend on the g_szClassName variable.

Some styles include others, so they might have been already set initially.

The styles affecting mostly the window appearance are the regular styles.

The description of the CreateWindowEx function should shed more light on this.
---
Stefan

Proud member of the UltraDefrag Development Team

CommonTater

  • Guest
Re: Style won't change: Win32 app and CreateWindowEx
« Reply #2 on: February 25, 2013, 10:08:22 AM »
As I compiled each example I would fiddle with the parameters for each call to see how things
changed.

In the second example in the tutorial on the call

 hwnd = CreateWindowEx(
     WS_EX_CLIENTEDGE,
     g_szClassName,
     "The title of my window",
     WS_OVERLAPPEDWINDOW,
     CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
     NULL, NULL, hInstance, NULL);

the first parameter is a frame styling parameter.
http://msdn.microsoft.com/en-us/library/windows/desktop/ff700543%28v=vs.85%29.aspx.
...
I tried changing them to different values (0,WS_EX_CLIENTEDGE,WS_EX_WINDOWEDGE etc)
and got the same results each time.  There were no visible style differences.
...
I will continue looking at this so I may have more detail later

What the others have said ... plus a lot of those "styles" are hangovers from OSs past. With UXThemes (Part of "user experience" starting with XP) a lot of them have been disabled when using visual styles.  As you've observed, WS_EX_CLIENTEDGE (sunken) now does about the same thing as WS_BORDER ... But if you switch off Visual Styles (i.e. use the "Windows Classic" theme) you will probably see quite a difference between them.
 
Also, in this case, the first parameter is not simply a frame styling parameter... For example: WS_EX_CONTROLPARENT is not about frame styling, it's about the keyboard navigator recursing into to child controls when searching for the next control to Tab to.  The standard window styles also contain many frame styling constants.
 
Also some of those constants will only work on child windows (WS_CHILD) and some only work on fixed size dialog boxes.
 
Finally, you should be aware that Windows wide, not all constants are current... some are duplicates, provided only for compatibility with older OS versions, some don't do anything, some  of the newer ones will cause problems with older Windows versions, if you aren't careful.  This is why I generally suggest people should have a copy of the Windows SDK ( download HERE ) on hand, and check each thing out as you work... It may sound silly at first but I've had some truly strange things happen when I wasn't checking the SDK for version information.
 

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Style won't change: Win32 app and CreateWindowEx
« Reply #3 on: February 25, 2013, 03:42:21 PM »
Simple simulation of styles
Code: [Select]
#define UNICODE
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
VOID CALLBACK TimerProc(HWND, UINT, UINT_PTR, DWORD);

TCHAR *szAppName = TEXT("WinExStyle");
TCHAR *szFrameClass = TEXT("cWinFrame");
HWND hFrame;

int nStyle;

struct _tWinStyles {
DWORD dwStyle;
TCHAR *Name;
} WinStyles[] = {
{WS_EX_CLIENTEDGE,TEXT("WS_EX_CLIENTEDGE")},
{WS_EX_DLGMODALFRAME,TEXT("WS_EX_DLGMODALFRAME")},
{WS_EX_STATICEDGE,TEXT("WS_EX_STATICEDGE")},
{WS_EX_WINDOWEDGE,TEXT("WS_EX_WINDOWEDGE")},
{WS_EX_TOOLWINDOW,TEXT("WS_EX_TOOLWINDOW")},
{WS_EX_PALETTEWINDOW,TEXT("WS_EX_PALETTEWINDOW")},
{0, TEXT("NONE")},
};

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wcx;
MSG msg;

wcx.cbSize = sizeof(WNDCLASSEX);
wcx.style = CS_HREDRAW | CS_VREDRAW;
wcx.lpfnWndProc = (WNDPROC) WndProc;
wcx.cbClsExtra = 0;
wcx.cbWndExtra = 0;
wcx.hInstance = hInstance;
wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcx.hCursor = LoadCursor(NULL, IDC_ARROW);
wcx.hbrBackground= (HBRUSH)COLOR_3DSHADOW;
wcx.lpszMenuName = NULL;
wcx.lpszClassName= szFrameClass;
wcx.hIconSm = 0;

if (!RegisterClassEx(&wcx))
return 0;

hFrame = CreateWindowEx(0, szFrameClass, szAppName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
300, 100,
NULL, NULL, hInstance, NULL);
if(!hFrame) return 0;
ShowWindow(hFrame, nCmdShow);
UpdateWindow(hFrame);

while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg) {
case WM_CREATE:
SetTimer(hWnd, 1, 2000, TimerProc);
return 0;
case WM_DESTROY:
KillTimer(hWnd, 1);
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}

VOID CALLBACK TimerProc( HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
{
SetWindowText(hWnd, WinStyles[nStyle].Name);
SetWindowLongPtr(hWnd, GWL_EXSTYLE, WinStyles[nStyle].dwStyle);
ShowWindow(hWnd, SW_HIDE);
ShowWindow(hWnd, SW_SHOW);
HDC hDC = GetDC(hWnd);
TextOut(hDC, 5, 5, WinStyles[nStyle].Name, lstrlen(WinStyles[nStyle].Name));
ReleaseDC(hWnd, hDC);
if (++nStyle >= sizeof(WinStyles)/sizeof(WinStyles[0]))
nStyle = 0;
}
May the source be with you