用WIN32 SDK写记事本遇到了一个问题

       找了几个月工作,未果,今天试着写了一个简单的记事本程序,不过出现了一个问题,程序运行的窗口不可以编辑,这个问题很困惑,我对比源代码找了好久,始终找不到问题所在,希望好心人帮我看一下。为了方便调试,我把完整代码发出来,代码如下:

// 记事本程序.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include <windows.h>
#include "resource.h"


LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);

TCHAR szAppName[] = TEXT ("ClipBoard") ;

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)
{

 HWND     hwnd ;
 MSG      msg ;
 WNDCLASS wndclass ;
 
 wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
 wndclass.lpfnWndProc   = WndProc ;
 wndclass.cbClsExtra    = 0 ;
 wndclass.cbWndExtra    = 0 ;
 wndclass.hInstance     = hInstance ;
 wndclass.hIcon         = LoadIcon (hInstance, szAppName) ;
 wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
 wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
 wndclass.lpszMenuName  = szAppName ;
 wndclass.lpszClassName = szAppName ;
 
 if (!RegisterClass (&wndclass))
 {
  MessageBox (NULL, TEXT ("This program requires Windows NT!"),
   szAppName, MB_ICONERROR) ;
  return 0 ;
 }
 
 hwnd = CreateWindow (szAppName, szAppName,
  WS_OVERLAPPEDWINDOW,
  GetSystemMetrics (SM_CXSCREEN) / 4,
  GetSystemMetrics (SM_CYSCREEN) / 4,
  GetSystemMetrics (SM_CXSCREEN) / 2,
  GetSystemMetrics (SM_CYSCREEN) / 2,
  NULL, NULL, 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)
{

 static HWND  hwndedit;
 int iselect,iEnable;
 switch(message)
 {
 case WM_CREATE:
  hwndedit = CreateWindow("NOTEPAD",NULL,WS_CHILD | WS_VISIBLE |
   WS_BORDER | ES_LEFT | ES_MULTILINE ,
   0, 0, 0, 0, hwnd, NULL,
            LPCREATESTRUCT(lparam)->hInstance, HMENU(0)) ;
  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_INITMENUPOPUP:
  EnableMenuItem((HMENU)wparam,IDM_UNDO,
   SendMessage(hwndedit,EM_CANUNDO,0,0)?MF_ENABLED:MF_GRAYED);

  EnableMenuItem((HMENU)wparam,IDM_PASTE,
   IsClipboardFormatAvailable(CF_TEXT)?MF_ENABLED:MF_GRAYED);

  iselect = SendMessage(hwndedit,EM_GETSEL,0,0);
  iEnable = (LOWORD(iselect)==HIWORD(iselect))?MF_GRAYED:MF_ENABLED;

  EnableMenuItem((HMENU)wparam,IDM_CUT,iEnable);
  EnableMenuItem((HMENU)wparam,IDM_COPY,iEnable);
  EnableMenuItem((HMENU)wparam,IDM_SELECT,iEnable);
  return 0;
  break;

 case WM_COMMAND:
  switch(LOWORD(wparam))
  {
  case IDM_FILE_OPEN:
  case IDM_FILE_SAVE:
  case IDM_FILE_SAVE_AS:
  case IDM_FILE_CLOSE:
   return 0;
  case IDM_UNDO:
   SendMessage(hwnd,WM_UNDO,0,0);
   return 0;
  case IDM_COPY:
   SendMessage(hwnd,WM_COPY,0,0);
   return 0;
  case IDM_PASTE:
   SendMessage(hwnd,WM_PASTE,0,0);
   return 0;
  case IDM_CUT:
   SendMessage(hwnd,WM_CUT,0,0);
   return 0;
  case IDM_SELECT:
   SendMessage(hwnd,EM_SETSEL,0,-1);
   return 0;

  }
  break;

 case WM_DESTROY:
  PostQuitMessage(0);
  return 0;

 }
 return DefWindowProc(hwnd,message,wparam,lparam);
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值