在Win32 SDK程序中,Create时创建一个一个窗体。欲去除其边框标题栏等属性,宜在WM_CREATE消息中写,或者在子窗体(例如按钮)的单击消息中以
SetWindowLong(hwnd, GWL_STYLE,GetWindowLong(hwnd, GWL_STYLE) &
(~(WS_CAPTION | WS_BORDER|WS_SYSMENU|WS_THICKFRAME|WS_MINIMIZEBOX|WS_MAXIMIZEBOX )));
达到目的。
全部程序如下:
// ContactListDemo.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
//#include "windows.h"
#define ID_BUTTON 1;
HWND hButton;
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
TCHAR szAppName[]=TEXT("ContactListDemo");
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
int error;
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.style =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(WHITE_BRUSH);
wndclass.lpszMenuName =NULL;//szAppName;
wndclass.lpszClassName =szAppName;
if(!RegisterClass(&wndclass))
{
MessageBox(NULL,TEXT("ContactListDemo"),
szAppName,MB_ICONERROR
);
return 0;
}
error=::GetLastError ();
hwnd=CreateWindow(szAppName,TEXT("ContactListDemo"),
WS_OVERLAPPEDWINDOW /*&(~(WS_CAPTION | WS_BORDER|WS_SYSMENU|WS_THICKFRAME|WS_MINIMIZEBOX|WS_MAXIMIZEBOX ))*/,
CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,
NULL,NULL,hInstance,NULL);
error=::GetLastError ();
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam , LPARAM lParam)
{
switch(message)
{
case WM_CREATE:
//SetWindowLong(hwnd, GWL_STYLE,GetWindowLong(hwnd, GWL_STYLE) &
// (~(WS_CAPTION | WS_BORDER|WS_SYSMENU|WS_THICKFRAME|WS_MINIMIZEBOX|WS_MAXIMIZEBOX )));
hButton=CreateWindow(TEXT("button"),TEXT("CHANGE WINDOW STYLE"),WS_CHILD | WS_VISIBLE,
/*CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,*/
20,20,200,50,
hwnd, (HMENU)1,
((LPCREATESTRUCT)lParam)->hInstance,NULL);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case 1:
SetWindowLong(hwnd, GWL_STYLE,GetWindowLong(hwnd, GWL_STYLE) &
(~(WS_CAPTION | WS_BORDER|WS_SYSMENU|WS_THICKFRAME|WS_MINIMIZEBOX|WS_MAXIMIZEBOX )));
//MessageBox(hwnd,TEXT("Clicked Button"),TEXT("Test"),MB_OK);
break;
default:
break;
}
break;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}