64,654
社区成员
发帖
与我相关
我的任务
分享
#include<windows.h>
#pragma comment(lib,"winmm.lib")
#pragma comment( linker, "/subsystem:\"windows\" /entry:\"WinMainCRTStartup\"" )
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
#define IDC_EDIT 101
HWND myedit;
void ResizeEdit(HWND hwndEdit,HWND hwnd);
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int iCmdShow)
{
static TCHAR szAppName[]=TEXT("HelloWin") ;
HWND hwnd;
MSG msg ;
RECT rect;
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)CreateSolidBrush(RGB(0,0,255));
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox ( NULL, TEXT ("This program requires Windows NT!"),szAppName, MB_ICONERROR);
return 0 ;
}
hwnd=CreateWindow(szAppName, // window class name
TEXT("The Hello Program"), // window caption
WS_OVERLAPPEDWINDOW, // window style
(GetSystemMetrics(SM_CXSCREEN)-800)/2,// initial x position
(GetSystemMetrics(SM_CYSCREEN)-600)/2,// initial y position
800,// initial x size
600,// initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL) ; // creation parameters
myedit=CreateWindowEx(0,"Edit", "",
WS_VSCROLL|WS_CHILD|ES_MULTILINE|ES_AUTOVSCROLL|WS_BORDER|WS_VISIBLE, GetClientRect(hwnd,&rect),
GetClientRect(hwnd,&rect), rect.right-rect.left-10,rect.bottom-rect.top,hwnd,(HMENU)IDC_EDIT,
hInstance,0);
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_CREATE:
PlaySound(TEXT ("BuzzingBee.wav"),NULL,SND_FILENAME|SND_ASYNC) ;
return 0 ;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
EndPaint (hwnd, &ps);
return 0 ;
case WM_SIZE:
ResizeEdit(myedit,hwnd);
return 0;
//case WM_KEYDOWN:
//myedit=NULL;
//return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0 ;
}
return DefWindowProc (hwnd,message,wParam,lParam) ;
}
void ResizeEdit(HWND hwndEdit,HWND hwnd)
{
RECT rect;
GetClientRect(hwnd,&rect);
int nWidth =rect.right-rect.left-10;
int nLeight =rect.bottom-rect.top;
//if(hwndEdit!=NULL)
MoveWindow(hwndEdit,GetClientRect(hwnd,&rect),GetClientRect(hwnd,&rect), rect.right-rect.left,rect.bottom-rect.top,SWP_SHOWWINDOW|SWP_NOZORDER);
//else SendMessage(myedit,WM_PAINT,0,0);
}
RECT rect = { 0 };
int nLeight = rect.bottom - rect.top - 10;
//if(hwndEdit!=NULL)
MoveWindow(hwndEdit,
5,
5,
nWidth,
nLeight,
SWP_SHOWWINDOW | SWP_NOZORDER);
#include<windows.h>
#pragma comment(lib,"winmm.lib")
#pragma comment( linker, "/subsystem:\"windows\" /entry:\"WinMainCRTStartup\"" )
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
#define IDC_EDIT 101
HWND myedit;
void ResizeEdit(HWND hwndEdit, HWND hwnd);
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT("HelloWin");
HWND hwnd;
MSG msg;
RECT rect = { 0 };
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)CreateSolidBrush(RGB(0,0,255));
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
if (!RegisterClass(&wndclass))
{
MessageBox(NULL, TEXT ("This program requires Windows NT!"), szAppName, MB_ICONERROR);
return 0;
}
hwnd = CreateWindow(szAppName, // window class name
TEXT("The Hello Program"),// window caption
WS_OVERLAPPEDWINDOW,// window style
(GetSystemMetrics(SM_CXSCREEN)-800)/2,// initial x position
(GetSystemMetrics(SM_CYSCREEN)-600)/2,// initial y position
800,// initial x size
600,// initial y size
NULL,// parent window handle
NULL,// window menu handle
hInstance,// program instance handle
NULL);// creation parameters
myedit = CreateWindowEx(0,
"Edit",
"",
WS_VSCROLL | WS_CHILD | ES_MULTILINE | ES_AUTOVSCROLL | WS_BORDER
| WS_VISIBLE,
GetClientRect(hwnd, &rect),
GetClientRect(hwnd, &rect),
rect.right - rect.left - 10,
rect.bottom - rect.top,
hwnd,
(HMENU)IDC_EDIT,
hInstance,
NULL);
ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_CREATE:
PlaySound(TEXT ("BuzzingBee.wav"), NULL, SND_FILENAME | SND_ASYNC);
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
EndPaint(hwnd, &ps);
return 0;
case WM_SIZE:
ResizeEdit(myedit, hwnd);
return 0;
//case WM_KEYDOWN:
//myedit=NULL;
//return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
void ResizeEdit(HWND hwndEdit, HWND hwnd)
{
RECT rect;
GetClientRect(hwnd, &rect);
int nWidth = rect.right - rect.left - 10;
int nLeight = rect.bottom - rect.top - 10;
//if(hwndEdit!=NULL)
MoveWindow(hwndEdit,
5,
5,
nWidth,
nLeight,
SWP_SHOWWINDOW | SWP_NOZORDER);
//else SendMessage(myedit,WM_PAINT,0,0);
}
GetClientRect(hwnd, &rect); //先获得rect,
myedit=CreateWindowEx(0,TEXT("Edit"), TEXT(""),
WS_VSCROLL|WS_CHILD|ES_MULTILINE|ES_AUTOVSCROLL|WS_BORDER|WS_VISIBLE, rect.left,
rect.top, rect.right-rect.left-10,rect.bottom-rect.top,hwnd,(HMENU)IDC_EDIT,
hInstance,0);
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;