Code:
#include <windows.h>
#include "resource.h"
#define ID_TIMER 1
#define ID_EDIT 1
LRESULT CALLBACK WndProc (HWND , UINT, WPARAM, LPARAM);
BOOL CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("WhatClr");
HWND hwnd;
MSG msg;
WNDCLASS wndc;
wndc.style = CS_HREDRAW | CS_VREDRAW;
wndc.lpfnWndProc = WndProc;
wndc.cbClsExtra = 0;
wndc.cbWndExtra = 0;
wndc.hInstance = hInstance;
wndc.hIcon = LoadIcon (hInstance, szAppName);
wndc.hCursor = LoadCursor (hInstance, szAppName);
wndc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
wndc.lpszMenuName = szAppName;
wndc.lpszClassName = szAppName;
if (!RegisterClass (&wndc))
{
MessageBox (NULL, TEXT ("Program Requiers Windows NT"),
szAppName, MB_ICONERROR);
return 0;
}
hwnd = CreateWindow (szAppName, TEXT ("Cheappad v0.5"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
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;
static HINSTANCE hInstance;
switch (message)
{
case WM_CREATE:
hInstance = ((LPCREATESTRUCT) lParam)->hInstance;
hwndEdit = CreateWindow (TEXT ("edit"),NULL,
WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_BORDER|
ES_LEFT | ES_MULTILINE|ES_AUTOVSCROLL,
0,0,0,0,hwnd, (HMENU) ID_EDIT,
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_INITMENUPOPUP:
if (lParam == 1)
{
EnableMenuItem ((HMENU) wParam, IDM_EDIT_UNDO,
SendMessage (hwndEdit, EM_CANUNDO, 0, 0) ?
MF_ENABLED : MF_GRAYED);
iSelect = SendMessage (hwndEdit, EM_GETSEL,0,0);
if (HIWORD (iSelect) == LOWORD (iSelect))
iEnable = MF_GRAYED;
else
iEnable = MF_ENABLED;
EnableMenuItem ((HMENU) wParam,IDM_EDIT_CUT,iEnable);
EnableMenuItem ((HMENU) wParam,IDM_EDIT_COPY, iEnable);
EnableMenuItem ((HMENU) wParam,IDM_EDIT_PASTE, iEnable);
return 0;
}
break;
case WM_COMMAND:
if (lParam)
{
if (LOWORD (lParam) == ID_EDIT &&
(HIWORD (wParam) == EN_ERRSPACE ||
HIWORD (wParam) == EN_MAXTEXT))
MessageBox (hwnd, TEXT ("Cheappad out of space"),
TEXT ("pop"), MB_OK | MB_ICONSTOP);
return 0;
}
else switch (LOWORD (wParam))
{
case IDM_FILE_NEW:
case IDM_FILE_OPEN:
case IDM_FILE_SAVE:
case IDM_FILE_SAVE_AS:
MessageBeep (0);
return 0;
case IDM_APP_EXIT:
SendMessage (hwnd, WM_CLOSE, 0, 0);
return 0;
case IDM_HELP_ABOUT:
DialogBox (hInstance, TEXT ("AboutBox"), hwnd, AboutDlgProc);
return 0;
return 0;
}
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc (hwnd, message, wParam, lParam);
}
BOOL CALLBACK AboutDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
switch (LOWORD (wParam))
{
case IDOK:
case IDCANCEL:
EndDialog (hDlg, 0);
return TRUE;
}
break;
}
return FALSE;
}
thanks in advance