|
|
debug编译能通过,就是打开执行文件后,什么也没发生,窗口也没有
不过release版能正常运行出来,不过新建个项目后,一样的代码,设置
release版就不能运行了
编译器使用vc8.0,设置上就是把默认的unicode改成了多字节字符支持
主要代码如下
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windowsx.h>
#define WINDOWED true //标识是否为窗口程序
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg,
WPARAM wparam,
LPARAM lparam)
{
PAINTSTRUCT ps; // used in WM_PAINT
switch(msg)
{
case WM_CREATE:
{
// do initialization stuff here
return(0);
} break;
case WM_PAINT:
{
BeginPaint(hwnd,&ps);
// end painting
EndPaint(hwnd,&ps);
return(0);
} break;
case WM_DESTROY:
{
// kill the application
PostQuitMessage(0);
return(0);
} break;
default:break;
} // end switch
return (DefWindowProc(hwnd, msg, wparam, lparam));
} // end WinProc
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance LPSTR lpcmdline, int ncmdshow)
{
MSG msg;
WNDCLASSEX winclass;
winclass.cbSize = sizeof(WNDCLASSEX);
winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc = WndProc;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hInstance = hinstance;
winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
winclass.lpszMenuName = NULL;
winclass.lpszClassName = "BasicWinFrame";
// register the window class
if (!RegisterClassEx(&winclass))
return(0);
if(!(MainWndH=CreateWindowEx (NULL,
"BasicWinFrame",
"BasicWindow",
(WINDOWED ? (WS_OVERLAPPED | WS_SYSMENU |WS_CAPTION) : (WS_POPUP |WS_VISIBLE)),
0,0,
WINDOW_WIDTH,WINDOW_HEIGHT,
NULL,
NULL,
hinstance,
NULL)))
return(0);
MainInstance = hinstance;
// resize the window so that client is really width x height
if (WINDOWED)
{
// now resize the window, so the client area is the actual size requested
// since there may be borders and controls if this is going to be a windowed app
// if the app is not windowed then it won't matter
RECT window_rect = {0,0,WINDOW_WIDTH-1,WINDOW_HEIGHT-1};
// make the call to adjust window_rect
AdjustWindowRectEx(&window_rect,
GetWindowStyle(MainWndH),
GetMenu(MainWndH) != NULL,
GetWindowExStyle(MainWndH));
// now resize the window with a call to MoveWindow()
MoveWindow(MainWndH,
0, // x position
0, // y position
window_rect.right - window_rect.left, // width
window_rect.bottom - window_rect.top, // height
FALSE);
ShowWindow(MainWndH, SW_SHOW);
} // end if windowed
// enter main event loop
while(true)
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
// test if this is a quit
if (msg.message == WM_QUIT)
break;
// translate any accelerator keys
TranslateMessage(&msg);
// send the message to the window proc
DispatchMessage(&msg);
} // end if
} // end while
}
|
|