码迷,mamicode.com
首页 > Windows程序 > 详细

win32创建EDIT窗口,并把大小调整为父窗口工作区大小

时间:2016-03-20 18:12:12      阅读:287      评论:0      收藏:0      [点我收藏+]

标签:win32   api   edit   getclientrect   setwindowpos   

//Resource.h

#define IDC_MAIN_EDIT 101

//

//  函数:  WndProc(HWND, UINT, WPARAM, LPARAM)

//

//  目的:    处理主窗口的消息。

//

//  WM_COMMAND          - 处理应用程序菜单

//  WM_PAINT    - 绘制主窗口

//  WM_DESTROY              - 发送退出消息并返回

//

//

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam , LPARAM lParam)

{

                 int wmId, wmEvent;

                 PAINTSTRUCT ps;

                 HDC hdc;

                 HWND hEdit;

                 switch (message )

                {

                 case WM_CREATE :

                                 HFONT hfDefault;

                                

                                hEdit = CreateWindowEx(WS_EX_CLIENTEDGE ,L"EDIT",L "",

                                                 WS_CHILD|WS_VISIBLE |WS_VSCROLL| WS_HSCROLL|ES_MULTILINE |ES_AUTOHSCROLL| ES_AUTOVSCROLL,

                                                0,0,100,100, hWnd,(HMENU )IDC_MAIN_EDIT, GetModuleHandle(NULL ),NULL);// ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL  设置EDIT窗口为多行可编辑及能水平及垂直滚动

                                 if (hEdit == NULL ){

                                                 MessageBox(hWnd ,L"Could not create edit box.",L"Error", MB_OK|MB_ICONERROR );

                                }

                                hfDefault = ( HFONT)GetStockObject(DEFAULT_GUI_FONT );

                                 SendMessage(hEdit,WM_SETFONT ,(WPARAM)hfDefault, MAKELPARAM(FALSE ,0));

                                 break;

                 case WM_SIZE :

                                 RECT rcClient;

                                GetClientRect( hWnd, &rcClient);// 得到窗口客户区的大小  ,其中right及bottom即是客户区的width及height

                                hEdit = GetDlgItem( hWnd, IDC_MAIN_EDIT );

                                SetWindowPos(hEdit, NULL, 0, 0, rcClient.right, rcClient.bottom, SWP_NOZORDER);//修改子窗口、弹出窗口和顶层窗口的大小、位置和z轴

                                 TCHAR buf[1000];

                                swprintf_s(buf, _T("%d" ), rcClient.right);

                                 SendMessage(hEdit,

                                                 WM_SETTEXT,

                                                 NULL,

                                                ( LPARAM)buf);

                                 break;

                 case WM_COMMAND :

                                wmId    = LOWORD(wParam );

                                wmEvent = HIWORD(wParam );

                                 // 分析菜单选择:

                                 switch (wmId)

                                {

                                 case IDM_ABOUT :

                                                 DialogBox(hInst, MAKEINTRESOURCE (IDD_ABOUTBOX), hWnd, About);

                                                 break;

                                 case IDM_EXIT :

                                                DestroyWindow( hWnd);

                                                 break;

                                 default:

                                                 return DefWindowProc (hWnd, message, wParam, lParam );

                                }

                                 break;

                 case WM_PAINT :

                                hdc = BeginPaint( hWnd, &ps);

                                 // TODO:  在此添加任意绘图代码...

                                EndPaint( hWnd, &ps);

                                 break;

                 case WM_DESTROY :

                                PostQuitMessage(0);

                                 break;

                 default:

                                 return DefWindowProc (hWnd, message, wParam, lParam );

                }

                 return 0;

}


win32创建EDIT窗口,并把大小调整为父窗口工作区大小

标签:win32   api   edit   getclientrect   setwindowpos   

原文地址:http://quietnight.blog.51cto.com/7163892/1753143

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!