1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
//Main.cpp
#include <windows.h>
#define IDC_TEXT 1500
LRESULT CALLBACK fnWndProc(HWND hwnd, unsigned int msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
{
RECT rc;
HINSTANCE hIns=((LPCREATESTRUCT)lParam)->hInstance;
HFONT hFont=(HFONT)GetStockObject(SYSTEM_FIXED_FONT);
GetClientRect(hwnd,&rc);
HWND hCtrl=
CreateWindow
(
"edit",
"",
WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_HSCROLL|ES_MULTILINE,
0,
0,
rc.right,
rc.bottom,
hwnd,
(HMENU)IDC_TEXT,
hIns,
0
);
SendMessage(hCtrl,WM_SETFONT,(WPARAM)hFont,MAKELPARAM(FALSE,0));
HANDLE hFile=CreateFile("Main.cpp",GENERIC_READ,0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
DWORD dwSize=GetFileSize(hFile,NULL);
DWORD dwBytesRead;
HGLOBAL pBuffer=GlobalAlloc(GPTR,dwSize+1);
if(pBuffer)
{
if(hFile!=INVALID_HANDLE_VALUE)
{
ReadFile(hFile,pBuffer,dwSize,&dwBytesRead,NULL);
SetWindowText(hCtrl,(char*)pBuffer);
GlobalFree(pBuffer);
CloseHandle(hFile);
}
}
}
return 0;
case WM_CLOSE:
{
DestroyWindow(hwnd);
PostQuitMessage(0);
}
return 0;
}
return (DefWindowProc(hwnd, msg, wParam, lParam));
}
int WINAPI WinMain(HINSTANCE hIns, HINSTANCE hPrev, LPSTR lpszArgument, int iShow)
{
char szClassName[]="Form1";
WNDCLASSEX wc;
MSG messages;
HWND hWnd;
wc.lpszClassName=szClassName, wc.lpfnWndProc=fnWndProc;
wc.cbSize=sizeof (WNDCLASSEX), wc.style=CS_DBLCLKS;
wc.hIcon=LoadIcon(NULL,IDI_APPLICATION), wc.hInstance=hIns;
wc.hIconSm=LoadIcon(NULL, IDI_APPLICATION), wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground=(HBRUSH)COLOR_BTNSHADOW, wc.cbWndExtra=0;
wc.lpszMenuName=NULL, wc.cbClsExtra=0;
RegisterClassEx(&wc),
hWnd=CreateWindowEx(0,szClassName,szClassName,WS_OVERLAPPEDWINDOW,50,150,900,750,HWND_DESKTOP,0,hIns,0);
ShowWindow(hWnd,iShow);
while(GetMessage(&messages,NULL,0,0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
|