如何在Windows记事本菜单中添加新项目 [英] How to add a new item to menu of windows notepad

查看:64
本文介绍了如何在Windows记事本菜单中添加新项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Windows记事本的菜单栏中添加一个新项目(扩展名)?

使用C ++语言(Windows系统编程)



例如:

文件编辑格式帮助扩展程序



我尝试过:



//

 #includestdafx.h
#includeNotepadProject .h

#define MAX_LOADSTRING 100

//全局变量:
HINSTANCE hInst; //当前实例
TCHAR szTitle [MAX_LOADSTRING]; //标题栏文本
TCHAR szWindowClass [MAX_LOADSTRING]; //主窗口类名

//此代码模块中包含的函数的前向声明:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE,int);
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
INT_PTR CALLBACK关于(HWND,UINT,WPARAM,LPARAM);

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);

// TODO:在这里放置代码。
MSG msg;
HACCEL hAccelTable;

//初始化全局字符串
LoadString(hInstance,IDS_APP_TITLE,szTitle,MAX_LOADSTRING);
LoadString(hInstance,IDC_NOTEPADPROJECT,szWindowClass,MAX_LOADSTRING);
MyRegisterClass(hInstance);

//执行应用程序初始化:
if(!InitInstance(hInstance,nCmdShow))
{
return FALSE;
}

hAccelTable = LoadAccelerators(hInstance,MAKEINTRESOURCE(IDC_NOTEPADPROJECT));

//主消息循环:
while(GetMessage(& msg,NULL,0,0))
{
if(!TranslateAccelerator(msg.hwnd) ,hAccelTable,& msg))
{
TranslateMessage(& msg);
DispatchMessage(& msg);
}
}

return(int)msg.wParam;
}



//
//功能:MyRegisterClass()
//
//目的:注册窗口类。
//
//评论:
//
//只有当你想让这个代码
//与Win32兼容时,才需要这个函数及其用法添加到Windows 95的'RegisterClassEx'
//函数之前的系统。调用此函数
//非常重要,这样应用程序将获得格式良好的小图标关联
//用它。
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX);

wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance,MAKEINTRESOURCE(IDI_NOTEPADPROJECT));
wcex.hCursor = LoadCursor(NULL,IDC_ARROW);
wcex.hbrBackground =(HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszMenuName = MAKEINTRESOURCE(IDC_NOTEPADPROJECT);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance,MAKEINTRESOURCE(IDI_SMALL));

返回RegisterClassEx(& wcex);
}

//
//功能:InitInstance(HINSTANCE,int)
//
//目的:保存实例句柄并创建主窗口
//
// COMMENTS:
//
//在这个函数中,我们将实例句柄保存在一个全局变量中,
//创建并显示主程序窗口。
//
BOOL InitInstance(HINSTANCE hInstance,int nCmdShow)
{
HWND hWnd;

hInst = hInstance; //在我们的全局变量中存储实例句柄

hWnd = CreateWindow(szWindowClass,szTitle,WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,0,CW_USEDEFAULT,0,NULL,NULL,hInstance,NULL);

if(!hWnd)
{
返回FALSE;
}

ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);

返回TRUE;
}

//
//功能:WndProc(HWND,UINT,WPARAM,LPARAM)
//
// PURPOSE:处理消息主窗口。
//
// WM_COMMAND - 处理应用程序菜单
// WM_PAINT - 绘制主窗口
// WM_DESTROY - 发布退出消息并返回
//
//
LRESULT CALLBACK WndProc(HWND hWnd,UINT消息,WPARAM wParam,LPARAM lParam)
{
int wmId,wmEvent;
PAINTSTRUCT ps;
HDC hdc;

switch(message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
//解析菜单选项:
switch(wmId)
{
case IDM_ABOUT:
DialogBox(hInst,MAKEINTRESOURCE(IDD_ABOUTBOX),hWnd,About);
休息;
case IDM_EXIT:
DestroyWindow(hWnd);
休息;
默认值:
返回DefWindowProc(hWnd,message,wParam,lParam);
}
休息;
case WM_PAINT:
hdc = BeginPaint(hWnd,& ps);
// TODO:在这里添加任何绘图代码...
EndPaint(hWnd,& ps);
休息;
案例WM_DESTROY:
PostQuitMessage(0);
休息;
默认值:
返回DefWindowProc(hWnd,message,wParam,lParam);
}
返回0;
}

//关于框的消息处理程序。
INT_PTR CALLBACK关于(HWND hDlg,UINT消息,WPARAM wParam,LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch(message)
{
case WM_INITDIALOG:
return(INT_PTR)TRUE;

case WM_COMMAND:
if(LOWORD(wParam)== IDOK || LOWORD(wParam)== IDCANCEL)
{
EndDialog(hDlg,LOWORD(wParam) ));
return(INT_PTR)TRUE;
}
休息;
}
return(INT_PTR)FALSE;
}

解决方案

这是不可能的,但也是非法的。这没有任何意义。一个简单的记事本,你可以在几个小时内从模板中写出来。



但是如果你真的想为编辑器做一些扩展我可以推荐你的开源编辑器< a href =https://notepad-plus-plus.org/download/v6.9.2.html> Notepad ++ ,您不仅可以下载该应用程序的来源,还可以下载该应用程序的来源记录的扩展接口。



最好的起点是 Notepad ++社区

i want add a new item(Extension) to menu bar in windows notepad ?
for use C++ Language (Windows System Programing)

for example:
File Edit Format Help Extension

What I have tried:

//

#include "stdafx.h"
#include "NotepadProject.h"

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst;								// current instance
TCHAR szTitle[MAX_LOADSTRING];					// The title bar text
TCHAR szWindowClass[MAX_LOADSTRING];			// the main window class name

// Forward declarations of functions included in this code module:
ATOM				MyRegisterClass(HINSTANCE hInstance);
BOOL				InitInstance(HINSTANCE, int);
LRESULT CALLBACK	WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK	About(HWND, UINT, WPARAM, LPARAM);

int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);

 	// TODO: Place code here.
	MSG msg;
	HACCEL hAccelTable;

	// Initialize global strings
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	LoadString(hInstance, IDC_NOTEPADPROJECT, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance);

	// Perform application initialization:
	if (!InitInstance (hInstance, nCmdShow))
	{
		return FALSE;
	}

	hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_NOTEPADPROJECT));

	// Main message loop:
	while (GetMessage(&msg, NULL, 0, 0))
	{
		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	return (int) msg.wParam;
}



//
//  FUNCTION: MyRegisterClass()
//
//  PURPOSE: Registers the window class.
//
//  COMMENTS:
//
//    This function and its usage are only necessary if you want this code
//    to be compatible with Win32 systems prior to the 'RegisterClassEx'
//    function that was added to Windows 95. It is important to call this function
//    so that the application will get 'well formed' small icons associated
//    with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
	WNDCLASSEX wcex;

	wcex.cbSize = sizeof(WNDCLASSEX);

	wcex.style			= CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc	= WndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= LoadIcon(hInstance, MAKEINTRESOURCE(IDI_NOTEPADPROJECT));
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW+1);
	wcex.lpszMenuName	= MAKEINTRESOURCE(IDC_NOTEPADPROJECT);
	wcex.lpszClassName	= szWindowClass;
	wcex.hIconSm		= LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

	return RegisterClassEx(&wcex);
}

//
//   FUNCTION: InitInstance(HINSTANCE, int)
//
//   PURPOSE: Saves instance handle and creates main window
//
//   COMMENTS:
//
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;

   hInst = hInstance; // Store instance handle in our global variable

   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}

//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND	- process the application menu
//  WM_PAINT	- Paint the main window
//  WM_DESTROY	- post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;

	switch (message)
	{
	case WM_COMMAND:
		wmId    = LOWORD(wParam);
		wmEvent = HIWORD(wParam);
		// Parse the menu selections:
		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: Add any drawing code here...
		EndPaint(hWnd, &ps);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}

// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	UNREFERENCED_PARAMETER(lParam);
	switch (message)
	{
	case WM_INITDIALOG:
		return (INT_PTR)TRUE;

	case WM_COMMAND:
		if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
		{
			EndDialog(hDlg, LOWORD(wParam));
			return (INT_PTR)TRUE;
		}
		break;
	}
	return (INT_PTR)FALSE;
}

解决方案

That is only not possible but also would be illegal. And it makes no sense. A simple notepad you can write from the template in some hours.

But if you really want to make some extension for an editor I can recommend you the open source editor
Notepad++, for which you not only can download the sources of the app, but who has also a well documented extension interface.

The best starting point is Notepad++ community.


这篇关于如何在Windows记事本菜单中添加新项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆