창 속성 변경
창 을 만 들 기 전에 창 속성 을 변경 합 니 다.
MFC 에서 PreCreate Window 재 작성 () 가상 함수 가 AppWizard 에서 생 성 된 창의 기본 속성 을 변경 합 니 다.
① PreCreate Window () 함 수 를 변경 하 는 CREATSTRUCT 를 통 해 변경 합 니 다.
typedef struct tagCREATESTRUCT {
LPVOID lpCreateParams;
HANDLE hInstance; //
HMENU hMenu; //
HWND hwndParent; //
int cy; //
int cx; //
int y; // y
int x; // x
LONG style; // ( / 、 / 、 、 )
LPCSTR lpszName; // ( style , style FWS_ADDTOTITLE )
LPCSTR lpszClass; // WNDCLASS , 、 、 , SDI ,Frame View , Frame PreCreateWindow() , , :View , View , View , , View PreCreateWindow() CREATESTRUCT lpszClass 。
DWORD dwExStyle; //
} CREATESTRUCT;
NOTE: CREATSTRUCT 구조 체 의 변 화 를 통 해 lpszName 창 제목 을 변경 하 였 으 나 변경 되 지 않 았 습 니 다. 결 성 된 창 형식 이 WS 이기 때 문 입 니 다.OVERLAPPEDWINDOW FWSADDTOTITLE 연합.FWSADDTOTITLE 는 프레임 워 크 에 문서 의 제목 을 창의 제목 으로 알 리 는 데 사 용 됩 니 다. 창 제목 을 수정 하려 면 이 속성 을 제거 해 야 합 니 다.
so:
cs.style = cs.style & ~FWS_ADDTOTITLE; 혹은
cs.style &= ~FWS_ADDTOTITLE; style 에 직접 값 을 부여 할 수도 있 습 니 다:
cs.style = WS_OVERLAPPEDWINDOW;
더 많은 웃음, 더 많은 서 프 라 이 즈, 더 많은 style 사용 가능 한 값 (Available styles) MSDN 만 나 기 CWnd::PreCreateWindow
노트: 창 클래스 는 창의 일부분 일 뿐 입 니 다. 완전한 창 수정 은 CREATSTRUCT 구조 체 를 수정 하 는 것 입 니 다. 이 구조 체 는 창 에 대응 하 는 창 클래스 를 포함 합 니 다. (클래스 이름 을 지정 하여 창 에 대응 하 는 창 클래스 를 수정 합 니 다.)
② 구체 적 인 예 (방법 1: 새 창 클래스)
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
cs.cx = 800; //
cs.cy = 600; //
cs.style = cs.style & ~WS_MAXIMIZEBOX & ~WS_MINIMIZEBOX & ~FWS_ADDTOTITLE;
cs.lpszName = " ";
// new WNDCLASS
WNDCLASS wndcls;
wndcls.cbClsExtra = 0;
wndcls.cbWndExtra = 0;
wndcls.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
wndcls.hCursor = LoadCursor(NULL, IDC_CROSS);
wndcls.hInstance = AfxGetInstanceHandle(); //
TRACE("Application instance handle1 is 0x%0X/n", AfxGetInstanceHandle()); //
//wndcls.hInstance = (HINSTANCE) GetWindowLong(m_hWnd, GWL_HINSTANCE);// , , : , 。
TRACE("Application instance handle2 is 0x%0X/n", GetWindowLong(m_hWnd, GWL_HINSTANCE)); // 。
//wndcls.lpfnWndProc = (WNDPROC)GetWindowLong(m_hWnd, GWL_WNDPROC); // , “ ”, : PreCreateWindow() , SetWindowLong() Set
wndcls.lpfnWndProc = ::DefWindowProc; // ( : )。
wndcls.lpszClassName = "cuihaoWndClass";
wndcls.lpszMenuName = MAKEINTRESOURCE(IDR_MAINFRAME);
wndcls.style = CS_HREDRAW | CS_VREDRAW;
wndcls.hIcon = LoadIcon(NULL, IDI_WARNING);
RegisterClass(&wndcls);
cs.lpszClass = "cuihaoWndClass";
return TRUE;
}
BOOL CMy44View::PreCreateWindow(CREATESTRUCT& cs)
{
cs.lpszClass = "cuihaoWndClass"; // , cuihaoWndClass
return CView::PreCreateWindow(cs);
}
③ 구체 적 인 예 (방법 2: 창 클래스 를 빠르게 만 드 는 방법)
AfxRegisterWndClass 이 함 수 는 창 클래스 를 빠르게 등록 합 니 다. 매개 변 수 는 클래스 스타일, 커서, 배경 색, 아이콘 만 있 습 니 다.창 클래스 의 클래스 이름 을 되 돌려 줍 니 다.
LPCTSTR AFXAPI AfxRegisterWndClass(
UINT nClassStyle,
HCURSOR hCursor=0,
HBRUSHhbr Background=0,
HICON hIcon=0
);
eg.
CString strClass = ""; // , , View CREATESTRUCT
// lpszClass = strClass;
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
cs.cx = 800;
cs.cy = 600;
cs.style = cs.style & ~WS_MAXIMIZEBOX & ~WS_MINIMIZEBOX & ~FWS_ADDTOTITLE;
cs.lpszName = " ";
strClass = cs.lpszClass = AfxRegisterWndClass(CS_VREDRAW | CS_HREDRAW, LoadCursor(NULL, IDC_CROSS),
(HBRUSH)GetStockObject(BLACK_BRUSH), LoadIcon(NULL, IDI_WINLOGO));
return TRUE;
}
BOOL CMy44View::PreCreateWindow(CREATESTRUCT& cs)
{
extern CString strClass; //
cs.lpszClass = strClass; // OK
return CView::PreCreateWindow(cs);
}
3 창 생 성 후 창 속성 변경
창 OnCreate () 함수 에서 coding
①LONG SetWindowLong
LONG SetWindowLong(
HWND hWnd, // , CWnd m_hWnd
int nIndex, // 0
LONG dwNewLong // nIndex
);
nIndex:
GWL_EXSTYLE
Sets a new extended window style. For more information, seeCreateWindowEx.
GWL_STYLE
창 형식 MSDN 참조: window style.
GWL_WNDPROC
창 프로 세 스 함수
GWL_HINSTANCE
응용 프로그램 인 스 턴 스 핸들
GWL_ID
Sets a new identifier of the window.
GWL_USERDATA
Sets the user data associated with the window. This data is intended for use by the application that created the window. Its value is initially zero.
hwnd 가 대화 상자 일 때 아래 값 을 사용 합 니 다.
DWL_DLGPROC
Sets the new address of the dialog box procedure.
DWL_MSGRESULT
Sets the return value of a message processed in the dialog box procedure.
DWL_USER
Sets new extra information that is private to the application, such as handles or pointers.
② 창 속성 용 함수 획득
LONG GetWindowLong(
HWND hWnd, // handle to window
int nIndex // offset of value to retrieve
);
NOTE: 최소한 창 생 성 이 끝 난 후에 야 이 함 수 를 호출 할 수 있 습 니 다.
③SetClassLong
DWORD SetClassLong(
HWND hWnd, // handle to window
int nIndex, // index of value to change
LONG dwNewLong // new value
);
④GetClassLong
DWORD GetClassLong(
HWND hWnd, // handle to window
int nIndex // offset of value to retrieve
);
4 요약:
창 을 만 들 기 전에 PreCreate Window () 함수 에서 AfxRegisterWNClass 로 창 클래스 를 만 듭 니 다.
창 생 성 후 OnCreate () 함수 에서 사용 SetWindowLong() SetClassLong()
SetWindowLong () 창 속성 설정, SetClassLong () 창 클래스 속성 설정
GetWindowLong () 은 창 속성 을, GetClassLong () 은 창 클래스 속성 을 가 져 옵 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.