• 全部
  • VC综合技术
  • 互联网技术
  • MFC AppLauncher
  • .NET 技术
  • 界面
  • 进程
  • 算法
  • 硬件/系统
  • 数据库
  • VC++技术资源

怎么edit子窗口不起作用了?

sms88 2004-11-22 11:27:30
我是要在住窗口中加入菜单来控制edit,编译后没有任何错误,也能运行。
但是客户区并没有光标输入点,就是说edit不起作用,客户区不能输入任何字符

#include<windows.h>
#include "resource.h"
static TCHAR szAppName[]=TEXT("EDIT");
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowComd)
{
HACCEL hAccel;
HWND hwnd;
WNDCLASS wndclass;
MSG msg;
wndclass.style=CS_HREDRAW|CS_VREDRAW;
wndclass.lpszMenuName=szAppName; //载入菜单
wndclass.lpszClassName=szAppName;
wndclass.lpfnWndProc=WndProc;
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.cbWndExtra=0;
wndclass.cbClsExtra=0;
if(!RegisterClass(&wndclass) )
{
MessageBox(NULL,szAppName,TEXT("Oh,NO!"),MB_ICONERROR);
return 0;
}
hwnd=CreateWindow(szAppName,TEXT("edit"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,
NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,nShowComd);
UpdateWindow(hwnd);
hAccel=LoadAccelerators(hInstance,TEXT("IDR_ACCELERATOR1")); //载入加速键
while(GetMessage(&msg,NULL,0,0) )
{
if(!TranslateAccelerator(hwnd,hAccel,&msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
static HWND hwndEdit;
switch(message)
{
case WM_CREATE: //创建edit子窗口
hwndEdit=CreateWindow(TEXT("edit"),NULL,
WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|
WS_BORDER|ES_LEFT|ES_MULTILINE|
ES_AUTOVSCROLL|ES_AUTOHSCROLL,
0,0,0,0,hwnd,(HMENU)1,
((LPCREATESTRUCT)lParam)->hInstance,NULL);
return 0;
case WM_SETFOCUS:
SetFocus(hwndEdit);
return 0;
case WM_SIZE:
MoveWindow(hwndEdit,0,0,LOWORD(lParam),HIWORD(lParam),TRUE);
return 0;
case WM_COMMAND:
if(lParam)
{
if(LOWORD(wParam)==1 &&HIWORD(wParam)==EN_ERRSPACE||
HIWORD(wParam)==EN_MAXTEXT)
MessageBox(hwnd,TEXT("OH!"),szAppName,MB_OK|MB_ICONSTOP);
return 0;

}
else switch(LOWORD(wParam)) //处理菜单
{
case IDM_EDIT_CUT:
SendMessage(hwndEdit,WM_CUT,0,0);
return 0;
case IDM_EDIT_PASTE:
SendMessage(hwndEdit,WM_PASTE,0,0);
return 0;
case IDM_EDIT_SELECT_ALL:
SendMessage(hwndEdit,EM_SETSEL,0,-1);
return 0;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}


...全文
71 点赞 收藏 8
写回复
8 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
wenxi2004 2004-11-23
#include<windows.h>
#include "resource.h"
static TCHAR szAppName[]=TEXT("EDIT");
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowComd)
{
HACCEL hAccel;
HWND hwnd;
WNDCLASS wndclass;
MSG msg;
wndclass.style=CS_HREDRAW|CS_VREDRAW;
wndclass.lpszMenuName=szAppName; //载入菜单
wndclass.lpszClassName=szAppName;
wndclass.lpfnWndProc=WndProc;
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.cbWndExtra=0;
wndclass.cbClsExtra=0;
if(!RegisterClass(&wndclass) )
{
MessageBox(NULL,szAppName,TEXT("Oh,NO!"),MB_ICONERROR);
return 0;
}
hwnd=CreateWindow(szAppName,TEXT("edit"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,
NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,nShowComd);
UpdateWindow(hwnd);
hAccel=LoadAccelerators(hInstance,TEXT("IDR_ACCELERATOR1")); //载入加速键
while(GetMessage(&msg,NULL,0,0) )
{
if(!TranslateAccelerator(hwnd,hAccel,&msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
static HWND hwndEdit;
switch(message)
{
case WM_CREATE: //创建edit子窗口
hwndEdit=CreateWindow(TEXT("edit"),NULL,
WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|
WS_BORDER|ES_LEFT|ES_MULTILINE|
ES_AUTOVSCROLL|ES_AUTOHSCROLL,
0,0,0,0,hwnd,(HMENU)1,
((LPCREATESTRUCT)lParam)->hInstance,NULL);
return 0;
case WM_SETFOCUS:
SetFocus(hwndEdit);
return 0;
case WM_SIZE:
MoveWindow(hwndEdit,0,0,LOWORD(lParam),HIWORD(lParam),TRUE);
return 0;
case WM_COMMAND:
if(lParam)
{
if(LOWORD(wParam)==1 &&HIWORD(wParam)==EN_ERRSPACE||
HIWORD(wParam)==EN_MAXTEXT)
MessageBox(hwnd,TEXT("OH!"),szAppName,MB_OK|MB_ICONSTOP);
//return 0;

}
/*else */switch(LOWORD(wParam)) //处理菜单
{
case IDM_EDIT_CUT:
SendMessage(hwndEdit,WM_CUT,0,0);
return 0;
case IDM_EDIT_PASTE:
SendMessage(hwndEdit,WM_PASTE,0,0);
return 0;
case IDM_EDIT_SELECT_ALL:
SendMessage(hwndEdit,EM_SETSEL,0,-1);
return 0;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
回复
bigchinacake 2004-11-23
up
回复
wenxi2004 2004-11-23
#include<windows.h>
#include "resource.h"
static TCHAR szAppName[]=TEXT("EDIT");
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowComd)
{
HACCEL hAccel;
HWND hwnd;
WNDCLASS wndclass;
MSG msg;
wndclass.style=CS_HREDRAW|CS_VREDRAW;
wndclass.lpszMenuName=szAppName; //载入菜单
wndclass.lpszClassName=szAppName;
wndclass.lpfnWndProc=WndProc;
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.cbWndExtra=0;
wndclass.cbClsExtra=0;
if(!RegisterClass(&wndclass) )
{
MessageBox(NULL,szAppName,TEXT("Oh,NO!"),MB_ICONERROR);
return 0;
}
hwnd=CreateWindow(szAppName,TEXT("edit"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,
NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,nShowComd);
UpdateWindow(hwnd);
hAccel=LoadAccelerators(hInstance,TEXT("IDR_ACCELERATOR1")); //载入加速键
while(GetMessage(&msg,NULL,0,0) )
{
if(!TranslateAccelerator(hwnd,hAccel,&msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
static HWND hwndEdit;
switch(message)
{
case WM_CREATE: //创建edit子窗口
hwndEdit=CreateWindow(TEXT("edit"),NULL,
WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|
WS_BORDER|ES_LEFT|ES_MULTILINE|
ES_AUTOVSCROLL|ES_AUTOHSCROLL,
0,0,0,0,hwnd,(HMENU)1,
((LPCREATESTRUCT)lParam)->hInstance,NULL);
return 0;
case WM_SETFOCUS:
SetFocus(hwndEdit);
return 0;
case WM_SIZE:
MoveWindow(hwndEdit,0,0,LOWORD(lParam),HIWORD(lParam),TRUE);
return 0;
case WM_COMMAND:
if(lParam)
{
if(LOWORD(wParam)==1 &&HIWORD(wParam)==EN_ERRSPACE||
HIWORD(wParam)==EN_MAXTEXT)
MessageBox(hwnd,TEXT("OH!"),szAppName,MB_OK|MB_ICONSTOP);
//return 0;

}
else switch(LOWORD(wParam)) //处理菜单
{
case IDM_EDIT_CUT:
SendMessage(hwndEdit,WM_CUT,0,0);
return 0;
case IDM_EDIT_PASTE:
SendMessage(hwndEdit,WM_PASTE,0,0);
return 0;
case IDM_EDIT_SELECT_ALL:
SendMessage(hwndEdit,EM_SETSEL,0,-1);
return 0;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
回复
sms88 2004-11-23
up
回复
sms88 2004-11-23
是啊
现在我自己都一头雾水了,弄不明白
回复
linxy2002 2004-11-23
那岂不是((LPCREATESTRUCT)lParam)->hInstance用的不对?
回复
sms88 2004-11-23
楼上的还是没有用
我把
case WM_CREATE: //创建edit子窗口
hwndEdit=CreateWindow(TEXT("edit"),NULL,
WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|
WS_BORDER|ES_LEFT|ES_MULTILINE|
ES_AUTOVSCROLL|ES_AUTOHSCROLL,
0,0,0,0,hwnd,(HMENU)1,
((LPCREATESTRUCT)lParam)->hInstance,NULL);

改成:
HINSTANCE hInstance;
//...
case WM_CREATE: //创建edit子窗口
hwndEdit=CreateWindow(TEXT("edit"),NULL,
WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|
WS_BORDER|ES_LEFT|ES_MULTILINE|
ES_AUTOVSCROLL|ES_AUTOHSCROLL,
0,0,0,0,hwnd,(HMENU)1,
hInstance,NULL);
就能够通过了

回复
NOMADBLUE 2004-11-22
带码好长,STUDY
回复
相关推荐
发帖
VC/MFC
创建于2007-09-28

1.5w+

社区成员

VC/MFC相关问题讨论
申请成为版主
帖子事件
创建了帖子
2004-11-22 11:27
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……