读书人

请问:小弟我建立的 win32 applicatio

发布时间: 2012-02-29 16:44:10 作者: rapoo

请教:我建立的 win32 application 怎么才能得到全屏啊?谢谢!
#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 为什么不退出啊?

谢谢!


[解决办法]
ShowWindow(hWnd, SW_MAXIMIZE);

改成这个就全屏了。

[解决办法]
1.全屏
int wid=GetSystemMetrics(SM_CXSCREEN);
int hei=GetSystemMetrics(SM_CYSCREEN);
Width=wid;
Height=hei;
long style;
style=GetWindowLong(hWnd,GWL_STYLE);
SetWindowLong(hWnd,GWL_STYLE,style&(~WS_OVERLAPPEDWINDOW));
SetWindowPos(hWnd,
HWND_NOTOPMOST,0,0,
wid, hei,
SWP_SHOWWINDOW);
}

2.按 ESC 为什么不退出
switch(message)
{
case WM_KEYDOWN:
switch( wParam )
{
case VK_ESCAPE:
//Do Sth
break;
}
[解决办法]
加上这个,知道哪里加吧?

case WM_CHAR:
{

if (wParam == VK_ESCAPE)
{
PostQuitMessage(0);
}
}
break;

[解决办法]
-_-
SetTimer(hwnd,1,1000,NULL);
HWND是一个类型

C是分大小写的

楼主学Win32是不是早了点
应该把语言基础打好
[解决办法]
SetTimer(hwnd,1,1000,NULL);


SetTimer(hwnd,1,1000,NULL);


HWND是个类型。。。 。。。

读书人网 >C++

热点推荐