#include <windows.h>   // include important windows stuff
#include "stdafx.h"
#include "resource.h"// 全局变量
HWND      main_window_handle = NULL; //主窗口全局变量
HINSTANCE main_instance      = NULL; //句柄全局变量
char buffer[80];                     //临时文本数组LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
   LPSTR lpCmdLine,int nCmdShow)
{
static TCHAR szAppName[]=TEXT("");
static TCHAR szClassName[]=TEXT("MainWinClass");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.style = CS_DBLCLKS | CS_OWNDC | 
CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground =  (HBRUSH)GetStockObject(BLACK_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szClassName; //设置句柄全局变量
main_instance = hInstance;

if(!RegisterClass(&wndclass))
{
MessageBox(NULL,TEXT("This program requires Windows NT !"),
szAppName,MB_ICONERROR);
return 0;
} hwnd = CreateWindow(szClassName,
TEXT(""),
WS_POPUP | WS_VISIBLE,
0,
0,
320,
240,
NULL,
NULL,
hInstance,
NULL );
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd); //设置主窗口全局变量
main_window_handle = hwnd;

    //主循环
while(TRUE)
{
//检测消息
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))

//是否退出程序
if (msg.message == WM_QUIT)
break;
//消息转换
TranslateMessage(&msg);
DispatchMessage(&msg);

    


return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,
 LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps; switch(message)
{
case WM_CREATE:
        SetTimer(hwnd,1,1000,NULL);
return 0; case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
EndPaint(hwnd,&ps);
return 0;
    case WM_LBUTTONDOWN:
 return 0;
case WM_DESTROY:
         KillTimer(hwnd,1);
   PostQuitMessage(0);
return 0;
} return DefWindowProc(hwnd,message,wParam,lParam);
}
请教:
wndclass.style = CS_DBLCLKS | CS_OWNDC | 
CS_HREDRAW | CS_VREDRAW;
怎样才能得到全屏?还有我按 ESC 为什么不退出啊?谢谢!

解决方案 »

  1.   

    ShowWindow前加MoveWindow(桌面大小)全屏
      

  2.   

    你的消息循环里没有响应ESC键消息的函数,当然退出不了了
      

  3.   

    谢谢楼上两位大哥
    全屏解决了为什么我按 ECS 
    不退出 程序啊
    谢谢!
      

  4.   

    谢谢
    case WM_DESTROY:
    不是响应 ESC 的啊
      

  5.   

    case WM_KEYUP:
    {

    if (wParam == VK_ESCAPE)
      SendMessage(hwnd, WM_CLOSE, 0, 0);//ESC
    }
    break;
      

  6.   

    case WM_KEYDOWN:
    if(wParam == VK_ESCAPE)
    {
         SendMessage(hwnd, WM_CLOSE, 0, 0);
    }
    break;
    加到switch里
      

  7.   

    谢谢!为什么我加上这句:
    SetTimer(HWND,1,1000,NULL);
    SetTimer(HWND,1,1000,NULL);
    ShowWindow(hwnd,nCmdShow);
    编译提示:
    --------------------Configuration: mygame - Win32 Debug--------------------
    Compiling...
    mygame.cpp
    C:\mygame\mygame.cpp(81) : error C2275: 'HWND' : illegal use of this type as an expression
            c:\program files\microsoft visual studio\vc98\include\windef.h(195) : see declaration of 'HWND'
    Error executing cl.exe.mygame.exe - 1 error(s), 0 warning(s)
    各位大哥,我错在哪里啊?
    谢谢!