?? mainwin.cpp
字號:
//
// 實例的主窗口
//
// Copyright (c) 2000-2001 Chihiro.SAKAMOTO (HyperWorks)
//
#include "StdAfx.h"
#include <file.h>
#include "Sample.h"
#include "Window.h"
#include "MainWin.h"
#include "resource.h"
//
// 產(chǎn)生窗口的前置作業(yè)
// 設(shè)定樣式與大小
//
//
BOOL CMainWin::PreCreateWindow(CREATESTRUCT &cs)
{
cs.dwExStyle = WS_EX_CLIENTEDGE;
cs.style = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
// 求出窗口大小
CRect rect(0, 0, 640, 480);
::AdjustWindowRectEx(&rect, cs.style, TRUE, cs.dwExStyle);
int width = rect.Width();
int height = rect.Height();
// 求出工作區(qū)域大小
// 工作區(qū)是指除了「工作列」以外部分
// 的整個畫面
CRect rcArea;
SystemParametersInfo(SPI_GETWORKAREA, NULL, &rcArea, NULL);
// 調(diào)整為移動到工作區(qū)域的正中央
int x = rcArea.left + (rcArea.Width() - width) / 2;
int y = rcArea.top + (rcArea.Height() - height) / 2;
cs.x = x;
cs.y = y;
cs.cx = width;
cs.cy = height;
cs.lpszClass = "MainWindow";
if (!Application->RegisterWndClass(cs.lpszClass,
CS_VREDRAW | CS_HREDRAW | CS_OWNDC, LoadCursor(NULL, IDC_ARROW),
(HBRUSH)::GetStockObject(BLACK_BRUSH), Application->LoadIcon(IDC_APPICON)))
return FALSE;
return TRUE;
}
//
// 事件處理
//
LRESULT CMainWin::WindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg) {
case WM_ERASEBKGND: // 去背景
return FALSE; // 無動作
default:
return CWindow::WindowProc(uMsg, wParam, lParam);
}
return 0L;
}
//
// WM_CREATE 的處理
//
BOOL CMainWin::OnCreate(CREATESTRUCT *cs)
{
LoadAccelTable(IDC_APPACCEL);
CFile file("sample.bmp"); // 開啟實例CG
if (!file || !ViewImage.LoadBMP(file)) {
MessageBox("無法讀取CG檔。");
return FALSE;
}
return TRUE;
}
//
// WM_PAINT 的處理(重新繪制)
//
void CMainWin::OnPaint()
{
CPaintDC dc(this);
// 顯示
::SetDIBitsToDevice(dc, 0, 0,
ViewImage.Width(), ViewImage.Height(),
0, 0, 0, ViewImage.Height(),
ViewImage.GetBits(),
ViewImage.GetInfo(),
DIB_RGB_COLORS);
}
//
// WM_COMMAND 的處理(菜單處理)
//
void CMainWin::OnCommand(UINT notifyCode, UINT id, HWND ctrl)
{
switch (id) {
case ID_APP_EXIT: // 結(jié)束
SendMessage(WM_CLOSE);
break;
default:
break;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -