僅供參考,以下是完整的程序:
#include <Windows.h>
// forward declarations
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); // WindowProcedure function
// The entry point into a windows program
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int windowStyle)
{
// create and register a local window class > exit on failure
WNDCLASSEX wcx;
HINSTANCE zhInstance = GetModuleHandle(NULL);
wcx.cbSize = sizeof(WNDCLASSEX); // size of structure
wcx.style = CS_HREDRAW | CS_VREDRAW; // redraw if size changes
wcx.lpfnWndProc = WndProc; // window procedure
wcx.cbClsExtra = 0; // no extra class memory
wcx.cbWndExtra = 0; // no extra windows memory
wcx.hInstance = zhInstance; // handle to instance (owner)
wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION); // predefined icon
wcx.hCursor = LoadCursor (NULL, IDC_ARROW); // predefined arrow
wcx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);//(HBRUSH) (COLOR_WINDOW + 1);// white background brush
wcx.lpszMenuName = NULL; // name of menu resource
wcx.lpszClassName = TEXT("BasicWindow"); // name of window class
wcx.hIconSm = (HICON)LoadImage(zhInstance, // small class icon
MAKEINTRESOURCE(5),
IMAGE_ICON,
GetSystemMetrics(SM_CXSMICON),
GetSystemMetrics(SM_CYSMICON),
LR_DEFAULTCOLOR);
if (!RegisterClassEx(&wcx))
{
MessageBoxA(0, "Error registering window class!","Error",MB_ICONSTOP | MB_OK);
DWORD result = GetLastError();
return 0;
}
// create window > exit on failure
HWND hwnd; // the window handle
hwnd = CreateWindowEx(
WS_EX_STATICEDGE,
wcx.lpszClassName,
TEXT("Basic Window"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
320,
240,
NULL,
NULL,
zhInstance,
NULL);
if (hwnd == NULL)
{
MessageBoxA(0,"Error creating window!","Error",MB_ICONSTOP | MB_OK);
return 0;
}
// show window
ShowWindow(hwnd, SW_MAXIMIZE);
// send a WM_PAINT message to the window
UpdateWindow(hwnd);
// enter message loop, break out of loop if there is an error (result = -1)
MSG msg; // for storing the windows messages
int status; // for storing the status of the windows message service where -1 = error, 0 = WM_QUIT, n = any other message)
while ((status = GetMessage(&msg,(HWND) NULL,0,0)) != 0 && status != -1)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
UNREFERENCED_PARAMETER(lpCmdLine);
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
default:
return DefWindowProc(hWnd,message,wParam,lParam);
}
return 0;
}
你在哪裏準確設置入口點? – Default 2012-01-09 16:08:00
屬性>配置屬性>鏈接器>高級>入口點= WinMain – 2012-01-09 16:16:41