/* 2010-02-20 jpfeiffer
When Next button is pressed get data from
File and update Window display , can convert char[] to wchar[] BUT zero wchar before pass by ref!
*/
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <aygshell.h>
#include "stringToWchar.txt"
#include "drawText.txt"
#include "getFileLine.txt"
#define BUFFERMAX 127
#define IDC_ExitButton 40099
#define IDC_textRefreshButton 40098
LRESULT CALLBACK MenuWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{ wchar_t text[ 128 ];
char buffer[ BUFFERMAX ];
char temp[ BUFFERMAX ];
int textpointX=0;
int textpointY=100;
int mousepointX =0;
int mousepointY =0;
char c;
FILE* fp;
fp=NULL;
RECT rc;
switch (message)
{
case WM_CREATE:
break;
case WM_LBUTTONDOWN:
mousepointX = LOWORD(lParam);
mousepointY = HIWORD(lParam);
printf( "click at: %d,%d \n",
mousepointX ,HIWORD(lParam) );
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_ExitButton:
PostQuitMessage(0);
break;
case IDC_textRefreshButton:
/* opens in root directory */
fp = fopen("test.txt","r");
if( fp==NULL )
{ printf("\nfopen error\n");
exit(1);
}else{
memset( buffer , 0, sizeof( buffer ));
getFileLine( fp, buffer, BUFFERMAX );
sprintf( temp,"%d", mousepointX);
strcat( buffer , temp );
fclose(fp);
}
memset( text , 0, sizeof( text ));
stringToWchar( buffer , text);
/* invalidateRect(hwnd,NULL,TRUE);
GetWindowRect(hwnd, &rc);
MoveWindow(hwnd, rc.left, rc.top, rc.right, rc.bottom, FALSE);
*/
drawText( hwnd, text, textpointX, textpointY );
break;
default:
break;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_PAINT:
initializeBackground( hwnd );
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
int APIENTRY WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int ncmdshow )
{
HWND hwnd = NULL;
HWND ExitButton = NULL;
HWND textRefreshButton = NULL;
MSG msg;
WNDCLASS wc;
HMENU hMenu;
wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = (WNDPROC)MenuWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = 0;
wc.hCursor = 0;
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = (LPTSTR) L"Menu App";
if(! RegisterClass (&wc))
{
MessageBox(NULL, TEXT("errors "),
L"IMPORTANT", MB_OK);
return 0;
}
hwnd = CreateWindow (L"Menu App", L"refresh text", WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, (HWND)NULL, NULL, hInstance, (LPSTR)NULL);
ExitButton = CreateWindow(
L"BUTTON", L"quit", WS_CHILD |
WS_VISIBLE | BS_PUSHBUTTON,
0, 0, /* top left x,y */
40, 40, /* width & height */
hwnd, (HMENU)IDC_ExitButton,
hInstance, NULL);
textRefreshButton = CreateWindow(
L"BUTTON", L"Next", WS_CHILD |
WS_VISIBLE | BS_PUSHBUTTON,
160, 160, 40, 40, hwnd, (HMENU)IDC_textRefreshButton,
hInstance, NULL);
ShowWindow(hwnd, ncmdshow);
UpdateWindow(hwnd);
while(GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
} /* end WinMain */