Hello. Studying WINAPI functions according to Ganeev, I came across the fact that his program does not want to work. VS 10 finds errors here:
if (!RegClass(WndProc, szClassName, COLOR_WINDOW)) return FALSE; hwnd=CreateWindowEx(szClassName, "Ex1", WS_OVERLAPPEDWINDOW|WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, hInstance, NULL); Where is the mistake? Here is the whole source:
#include"windows.h" extern HINSTANCE hInstance; BOOL RegClass(WNDPROC, LPCTSTR, UINT); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); HINSTANCE hInstance; char szClassName[]="WindowsAppClass"; INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { MSG msg; HWND hwnd; hInstance=hInst; if (!RegClass(WndProc, szClassName, COLOR_WINDOW)) return FALSE; hwnd=CreateWindowEx(szClassName, "Ex1", WS_OVERLAPPEDWINDOW|WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, hInstance, NULL); if(!hwnd) return FALSE; while(GetMessage(&msg, NULL, 0, 0)) DispatchMessage(&msg); return (int)msg.wParam; } LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_DESTROY:{PostQuitMessage(0); return 0;} } return DefWindowProc(hwnd, msg, wParam, lParam); } BOOL RegClass(WNDPROC Proc, LPCTSTR szName, UINT brBackground) { WNDCLASSEX 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)(brBackground+1); wc.lpszMenuName = (LPCTSTR)NULL; wc.lpszClassName = szName; return (RegisterClassEx(&wc)!=0); }