cannot initialize WNDCLASSW, WNDCLASSEX, WNDCLASSEXW window structs

Phil Lavoie maidenphil at hotmail.com
Sun Jan 27 06:39:37 PST 2013


On Sunday, 27 January 2013 at 14:06:00 UTC, rsk82 wrote:
> Ok, nevermind, found, it, it was so easy that it simply didn't 
> have to had an example:
>
>     struct WNDCLASSEXW {
>       UINT      cbSize;
>       UINT      style;
>       WNDPROC   lpfnWndProc;
>       int       cbClsExtra;
>       int       cbWndExtra;
>       HINSTANCE hInstance;
>       HICON     hIcon;
>       HCURSOR   hCursor;
>       HBRUSH    hbrBackground;
>       LPCWSTR   lpszMenuName;
>       LPCWSTR   lpszClassName;
>       HICON     hIconSm;
>     }

If you find yourself desiring other bindings of the win32 api and 
don't want them to define them by hand, a project was started 
some time ago by Stewart Gordon that contains an almost complete 
set of bindings: 
http://dsource.org/projects/bindings/wiki/WindowsApi

Set the import directory of your compiler appropriately and use 
it like that:
import win32.winuser; //example, where you will probably find 
wndclassexw

Additionnally, you should know that SOMETHINGA and SOMETHINGW 
means something like ascii and wide chars (UCS-2, so every char 
is two bytes instead of one). Normally, the api was intented to 
be used without the extra letter at the end:

WNDCLASSEX wndclass; //No suffix: defaults to ascii.

When people compile with the preprocessor Unicode defined, then 
all aliases are mapped to their W counterpart. What changes is 
how you pass and receive strings.
Keep in mind they must be null terminated (as in C).

The microsoft bunch also defined another macro that would help 
you make your code independant of the version used, it is called 
TCHAR.
TCHAR * someString; //Will be char * without unicode or wchar 
with.
someString = "My window class".toUTFz!( TCHAR * ); //This is how 
I use the std library to convert my strings. Try to keep a handle 
on strings that might be kept by the OS, to prevent them from 
being garbage collected.

WNDCLASSEX wndclass;
...
wndclass.lpszClassName = someString;

Peace,
Phil



More information about the Digitalmars-d mailing list