好文档 - 专业文书写作范文服务资料分享网站

VC++编程实例与技巧

天下 分享 时间: 加入收藏 我要投稿 点赞

//如何确定窗口的最大最小值以及如何定位窗口

//Modify the Application Class

1.初始化application’s window 的最大、最小值。先找到InitInstance()函数:

pMainFrame->ShowWindow(SW_SHOWMAXIMIZED);//者 SW_SHOWMINIMIZED pMainFrame->UpdateWindow();

//Modify the Mainframe Class

1) modify the PreCreateWindow() function

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) {

// 2) to center window at 90% of full screen

int xSize = ::GetSystemMetrics (SM_CXSCREEN); // 3) to keep document title out of main window's caption cs.style &= ~ FWS_ADDTOTITLE;

// 4) to remove min/max boxes

cs.style &= ~(WS_MAXIMIZEBOX|WS_MINIMIZEBOX);

// 5) to fix your application's window size cs.style &= ~WS_THICKFRAME;

return CMDIFrameWnd::PreCreateWindow(cs); }

int ySize = ::GetSystemMetrics (SM_CYSCREEN); cs.cx = xSize*9/10; cs.cy = ySize*9/10; cs.x = (xSize-cs.cx)/2; cs.y = (ySize-cs.cy)/2;

//an include file that defines a project's registry keys

//Modify the Application Class

// 1) locate the SetRegistryKey() function and change argument to company key // (failure to do this will cause your application's options to be saved to // a .ini file in your system's os directory)

SetRegistryKey(COMPANY_KEY);

// 2) replace the \// function with the following:

//Modify the MainFrame Class

UINT err; HKEY key;

DWORD size, type; WINDOWPLACEMENT wp;

if((err=RegOpenKeyEx( HKEY_CURRENT_USER,APPLICATION_KEY,0,KEY_READ,&key)) == { }

if (err==ERROR_SUCCESS) { } else { }

pMainFrame->UpdateWindow();

pMainFrame->ShowWindow(m_nCmdShow); pMainFrame->SetWindowPlacement(&wp); type = REG_BINARY;

size = sizeof(WINDOWPLACEMENT);

err=RegQueryValueEx( key,WINDOWPLACEMENT_KEY,0,&type,(LPBYTE)&wp,&size ); RegCloseKey( key );

ERROR_SUCCESS )

// 1) load previous bar states at end of OnCreate()

// 2) save toolbar state and screen size and position in OnClose() void CMainFrame::OnClose() {

// save size of screen HKEY key;

DWORD size, type, disposition; WINDOWPLACEMENT wp;

if (RegOpenKeyEx( HKEY_CURRENT_USER,APPLICATION_KEY,0, {

RegCreateKeyEx( HKEY_CURRENT_USER,APPLICATION_KEY,0,\// save state of control bars SaveBarState(\LoadBarState(\

KEY_WRITE,&key)!=ERROR_SUCCESS)

}

}

REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,

&key,&disposition);

type = REG_BINARY;

size=sizeof(WINDOWPLACEMENT); GetWindowPlacement(&wp);

RegSetValueEx( key,WINDOWPLACEMENT_KEY,0,type,(LPBYTE)&wp,size ); RegCloseKey( key );

CMDIFrameWnd::OnClose();

//a CommandLineInfo class that parses for additional command line switches

//Modify the Application Class

1) use new CommandLineInfo class

CWzdCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo);

//Modify any class

// 1) to change your application's icon

// 2) to change any frame window's icon

GetParentFrame()->SetIcon(AfxGetApp()->LoadIcon(IDI_STATUS_ICON),TRUE); AfxGetMainWnd()->SetIcon(AfxGetApp()->LoadIcon(IDI_STATUS_ICON),TRUE);

//sample property page classes //Modify the MainFrame Class

// 1) include \

// 2) add a declaration for a message which will be sent by the property sheet // when the user hits the \

// 3) add this handler to the message map BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)

//{{AFX_MSG_MAP(CMainFrame) protected:

//{{AFX_MSG(CMainFrame) //}}AFX_MSG

afx_msg void OnApply(); DECLARE_MESSAGE_MAP()

VC++编程实例与技巧

//如何确定窗口的最大最小值以及如何定位窗口//ModifytheApplicationClass1.初始化application’swindow的最大、最小值。先找到InitInstance()函数:pMainFrame->ShowWindow(SW_SHOWMAXIMIZED);//者SW_SHOWMINIMIZEDpMai
推荐度:
点击下载文档文档为doc格式
9tarm1abow44p5d1brnl
领取福利

微信扫码领取福利

微信扫码分享