I have this code (example)

const char g_sz_className[] = "myWindowClass";

LRESULT CALLBACK WndProc(HWND hwnd, UNIT msg,WPARAM wParam, LPARAM lPraram)
{
    switch(msg)
    {
    case WM_CLOSE:
        DestroyWindow(hwnd);
        break;
    case WM_DESTROY:
        PostQuitMessage;
        break;
    default:
        return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
}

int WINAPI WinMain(HISTANCE hIstance, HISTANCE hPrevIstance, LPSTR lpCmdLine, int nShowCmd)
{

    WNDCLASSEX wc;
    HWND hwnd;
    MSG Msg;

    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = 0;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    wc.hInstance = hIstance;
    wc.hbrBackground = (HBRUSH) 13;
    wc.lpfnWndProc = WndProc;
    wc.lpszClassName = g_sz_className;
    wc.lpszMenuName = NULL; //change

    if(!RegisterClassEx)
    {
        MessageBox(NULL, "Err", "ERR", MB_OK | MB_EXCLAMATION);
        return 0;
    }

    hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_sz_className,
"My  app",
WS_OVERLAPPEDWINDOW,
CW_USERDEFAULT,
CW_USERDEFAULT,
600,
650,
NULL,NULL, hIstance, NULL);

    if(hwnd = NULL)
    {
        MessageBox(NULL,"ERROr", "HWND ERR", MB_OK | MB_ICONEXCLAMATION);
        return 0;
    }

    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);

    while(GetMessage(&Msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }

    return Msg.wParam;



}

But it looks like its not portable.

Now in Visual Studio I cannot compile that. There is a bit more complicated file with stdfax.cpp, stdfax.h, resouurce.h files. What should I do?


Where can I get a good tutorial which will teach me Win32 API as Visual Studio wants???

Thanks in advance,

Jan

Where can I get a good tutorial or book which will teach me Win32 API as Visual Studio wants???

sorry, but I am affraid this damn code is from link you just gave me...

Is there any good book?

> PostQuitMessage;
Maybe if this were a function call, say
PostQuitMessage(0);

Perhaps posting actual error messages instead of "it doesn't work" would help as well.

h I am so sorry,

I was in hurry when writing that code and it is full od bugs...

Sorry

sorry, but I am affraid this damn code is from link you just gave me...

Is there any good book?

The code in that link is perfect -- billions of people (:eek: ) have used it.

Yes I copyed the code from tutorial, and VS compiler gives me this errors.

------ Build started: Project: MyFirtsFile, Configuration: Debug Win32 ------
Compiling...
main.cpp
c:\users\jan\documents\visual studio 2005\projects\myfirtsfile\myfirtsfile\main.cpp(40) : error C2440: '=' : cannot convert from 'const char [14]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\users\jan\documents\visual studio 2005\projects\myfirtsfile\myfirtsfile\main.cpp(46) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [28]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\users\jan\documents\visual studio 2005\projects\myfirtsfile\myfirtsfile\main.cpp(57) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [14]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\users\jan\documents\visual studio 2005\projects\myfirtsfile\myfirtsfile\main.cpp(62) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [24]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\users\jan\documents\visual studio 2005\projects\myfirtsfile\myfirtsfile\main.cpp(75) : warning C4244: 'return' : conversion from 'WPARAM' to 'int', possible loss of data
Build log was saved at "file://c:\Users\jan\Documents\Visual Studio 2005\Projects\MyFirtsFile\MyFirtsFile\Debug\BuildLog.htm"
MyFirtsFile - 4 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Finally, actual error messages.

What you have there is a UNICODE problem. VS2003 onwards defaults to using UNICODE for all strings, not ASCII.

Anytime you see functions ending in 'W' or references to 'WSTR', it's a good bet it's something to do with migrating from ASCII to UNICODE.

The fix is pretty easy.
In the project settings, there is a section for the "Preprocessor"
Part of that will be a list of defines which are constant through the whole project (say WIN32). One of those should be "UNICODE", which you should remove.

After you've done that, rebuild it and see what happens.

Um...I have a problem

Under preprocessor->definitions there is no UNICODE

Its WIN32;_DEBUG;_WINDOWS only

But under list of options I have
/Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /MDd /Fo"Debug\\" /Fd"Debug\vc80.pdb" /W3 /nologo /c /Wp64 /ZI /TP /errorReport:prompt

I cannot edit that, because text browser is grayed

Perhaps it exists as a check box or something elsewhere in the project settings (in VS 2005)

When the /D "_UNICODE" have gone, then it should build 'as is'.

I should point out that the improved way is to start making your code UNICODE compatible.
Eg.

MessageBox(NULL, _T("Err"), _T("ERR"), MB_OK | MB_EXCLAMATION);

> if(hwnd = NULL)
Are you sure you copy/pasted, because this is yet another typo
= should be ==

You didn't say which version of VC++ compiler you are using. VC++ 6.0 and VC++ 2005 set UNICODE differently.

VC++ 2005: select menu Project --> Properties . Expand the Configuration Properties folder then select General category. Now on the right side see "Character Set" and change it to "Not Set".

Perhaps it exists as a check box or something elsewhere in the project settings (in VS 2005)

When the /D "_UNICODE" have gone, then it should build 'as is'.

I should point out that the improved way is to start making your code UNICODE compatible.
Eg.

MessageBox(NULL, _T("Err"), _T("ERR"), MB_OK | MB_EXCLAMATION);

> if(hwnd = NULL)
Are you sure you copy/pasted, because this is yet another typo
= should be ==

Okok...you got me...
I didnt copy/paste...I write a code on my own because I wanna learn fast.
BTW: I realy dislike UNICODE.
I use VS 2005. Where can I disable that UNICODE?
I searched a bit, but I didnt find that option

You didn't say which version of VC++ compiler you are using. VC++ 6.0 and VC++ 2005 set UNICODE differently.

VC++ 2005: select menu Project --> Properties . Expand the Configuration Properties folder then select General category. Now on the right side see "Character Set" and change it to "Not Set".

Thanks Dragon,

I use VC++ 2005 compiler...

It surely is UNICODE problem like Salem mentioned, search msdn.microsoft.com to find out how to write UNICODE compatible programs and what are the relevant project settings. You'll learn how to change your project settings AND how to change the code if you don't want it UNICODE compat..
From what I remember from my ancient times is you need to #define UNICODE 1 (but that seems to have already been done !)

From what I remember from my ancient times is you need to #define UNICODE 1 (but that seems to have already been done !)

Yup -- like me, you too are outdated and nearly obsolete. :)

This question has already been answered. Start a new discussion instead.