Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

WIN API simple error

hello everybody! I am beginer in WIN API so i need some help :S

this program has some errors and can someone fix it?
I will appreciate it if you help me


#include

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCMDLine, int nCmdShow)

{
HWND hMainWnd;
char szClassName[] = "MyClass";
MSG msg;
WNDCLASSEX wc;


wc.cbSize = sizeof(wc);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = szClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

if (!RegisterClassEx(&wc)) {
MessageBox(NULL, NULL, NULL, MB_OK);
return 0;
}

hMainWnd = CreateWindow(
szClassName, NULL, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
(HWND)NULL, (HMENU)NULL,
(HINSTANCE)hInstance, NULL
);

if (IhMainWnd) {
MessageBox(NULL, NULL, NULL, MB_OK);
return 0;
}

ShowWindow(hMainWnd, nCmdShow);

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

return msg.wParam;
}


LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
HDC hDC;
PAINTSTRUCT ps;
RECT rect;
switch (uMsg)
{
case WM_PAINT:
hDC = BeginPain(hWnd, &ps);
GetClientRect(hWnd, &rect);
DrawText(hDC, "Hello, World!", -1, &rect,
DT_SINGLELINE | DT_CENTER | DT VCENTER);
EndPaint(hWnd, &ps);
break;

case WM_CLOSE:
DestroyWindow(hWnd);
break;

case WM_DESTROY:
PostQuitMessage(0);
break;

default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return 0;
}


Comments

  • anthrax11anthrax11 Member Posts: 511
    The parameters for CreateWindow are: x, y, width, height. You can only use CW_USEDEFAULT for x and y, but not for the width and height. The dimensions can't be 0 either. So use something like CW_USEDEFAULT, CW_USEDEFAULT, 200, 300.

    The rest are just typos, which I'm sure you can find with the help of your compiler.
  • newtronnewtron Member Posts: 4
    tnks but it's still an error
    .main.cpp(24) : error C2440: '=' : cannot convert from 'char [8]' to 'LPCWSTR'

  • AsmGuru62AsmGuru62 Member Posts: 6,519
    [color=Blue]Instead of char type use WCHAR type and all text constants then should be prefixed with L:[/color]
    [code]
    WCHAR s [] = L"some text";
    [/code]
  • newtronnewtron Member Posts: 4
    tnks, that worked
Sign In or Register to comment.