??C??д????±?
?????yueguanghaidao ???????[ 2016/12/1 10:55:38 ] ???????????±? ????
????????ú??о?C????????ü??±????С???????????
??????????????????????????????????????ɡ???????
???????????
???????????????->??????????
???????????????d??????????note?????
????1.????note.rc?????????????????
#include "sample.h"
A ICON MOVEABLE PURE LOADONCALL DISCARDABLE "sample.ico"
MAINMENU MENU
{
POPUP "???(&F)"
{
MENUITEM "??(&O)..."?? CM_FILE_OPEN
MENUITEM "????(&S)..."?? CM_FILE_SAVEAS
MENUITEM SEPARATOR
MENUITEM "???"?? CM_FILE_EXIT
}
POPUP "????(&H)"
{
MENUITEM "????(&A)"?? CM_ABOUT
}
}
????2.???sample.h??????????
????#define CM_FILE_SAVEAS 9072
????#define CM_FILE_EXIT 9071
????#define CM_FILE_OPEN 9070
????#define CM_ABOUT 9069
????3.????????note.c ??????????
#include <windows.h>
#include "sample.h"
static char g_szClassName[] = "MyWindowClass";
static HINSTANCE g_hInst = NULL;
#define IDC_MAIN_TEXT 1001
BOOL LoadFile(HWND hEdit?? LPSTR pszFileName)
{
HANDLE hFile;
BOOL bSuccess = FALSE;
hFile = CreateFile(pszFileName?? GENERIC_READ?? FILE_SHARE_READ?? NULL??
OPEN_EXISTING?? 0?? 0);
if(hFile != INVALID_HANDLE_VALUE)
{
DWORD dwFileSize;
dwFileSize = GetFileSize(hFile?? NULL);
if(dwFileSize != 0xFFFFFFFF)
{
LPSTR pszFileText;
pszFileText = (LPSTR)GlobalAlloc(GPTR?? dwFileSize + 1);
if(pszFileText != NULL)
{
DWORD dwRead;
if(ReadFile(hFile?? pszFileText?? dwFileSize?? &dwRead?? NULL))
{
pszFileText[dwFileSize] = 0;
if(SetWindowText(hEdit?? pszFileText))
bSuccess = TRUE;
}
GlobalFree(pszFileText);
}
}
CloseHandle(hFile);
}
return bSuccess;
}
BOOL SaveFile(HWND hEdit?? LPSTR pszFileName)
{
HANDLE hFile;
BOOL bSuccess = FALSE;
hFile = CreateFile(pszFileName?? GENERIC_WRITE?? 0?? 0??
CREATE_ALWAYS?? FILE_ATTRIBUTE_NORMAL?? 0);
if(hFile != INVALID_HANDLE_VALUE)
{
DWORD dwTextLength;
dwTextLength = GetWindowTextLength(hEdit);
if(dwTextLength > 0)
{
LPSTR pszText;
pszText = (LPSTR)GlobalAlloc(GPTR?? dwTextLength + 1);
if(pszText != NULL)
{
if(GetWindowText(hEdit?? pszText?? dwTextLength + 1))
{
DWORD dwWritten;
if(WriteFile(hFile?? pszText?? dwTextLength?? &dwWritten?? NULL))
bSuccess = TRUE;
}
GlobalFree(pszText);
}
}
CloseHandle(hFile);
}
return bSuccess;
}
BOOL DoFileOpenSave(HWND hwnd?? BOOL bSave)
{
OPENFILENAME ofn;
char szFileName[MAX_PATH];
ZeroMemory(&ofn?? sizeof(ofn));
szFileName[0] = 0;
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = "?????? (*.txt)