arif_alig
February 28th, 2003, 06:53 AM
plz help me i m using this code but it is not properly work on win-ME and 98 . but on 2000 it is work properly.plz helpme reply on arif_alig78@yahoo.co.in .
--------------------------------code ------------------
#include <windows.h>
#define ID_TIMER 1
HWND app_hwnd;
int iIndex;
TCHAR szWindowData[5000];
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam);
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("Beeper2") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("Program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName, TEXT ("Beeper2 Timer Demo"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL) ;
app_hwnd=hwnd;
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)
{
DWORD dwBytesWritten;
HANDLE hFile;
int dwPos,i;
switch (message)
{
case WM_CREATE:
SetTimer (hwnd, ID_TIMER, 30000, 0) ;
return 0 ;
case WM_DESTROY:
KillTimer (hwnd, ID_TIMER) ;
PostQuitMessage (0) ;
return 0 ;
case WM_TIMER:
EnumDesktopWindows(0,EnumWindowsProc ,0 );
hFile = CreateFile("MYFILE.TXT", // open MYFILE.TXT
GENERIC_WRITE, // open for reading
0, // share for reading
NULL, // no security
OPEN_ALWAYS, // existing file only
FILE_ATTRIBUTE_NORMAL, // normal file
NULL); // no attr. template
dwPos = SetFilePointer(hFile, 0, NULL, FILE_END);
//WriteFile(hFile, szWindowData, iWindLength, &dwBytesWritten, NULL);
WriteFile(hFile, szWindowData, iIndex, &dwBytesWritten, NULL);
CloseHandle(hFile);
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
int iWindLength;
TCHAR szText [255];
iWindLength= GetWindowText (hwnd, szText, sizeof (szText)) ;
if ( szText!= NULL )
{
szText[iWindLength]='\r';
iWindLength++;
szText[iWindLength]='\n';
iWindLength++;
for(i=0;i<iWindLength;i++)
szWindowData[++iIndex]=szText[i];
}
return 1;
}
--------------------------------code ------------------
#include <windows.h>
#define ID_TIMER 1
HWND app_hwnd;
int iIndex;
TCHAR szWindowData[5000];
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam);
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("Beeper2") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("Program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName, TEXT ("Beeper2 Timer Demo"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL) ;
app_hwnd=hwnd;
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)
{
DWORD dwBytesWritten;
HANDLE hFile;
int dwPos,i;
switch (message)
{
case WM_CREATE:
SetTimer (hwnd, ID_TIMER, 30000, 0) ;
return 0 ;
case WM_DESTROY:
KillTimer (hwnd, ID_TIMER) ;
PostQuitMessage (0) ;
return 0 ;
case WM_TIMER:
EnumDesktopWindows(0,EnumWindowsProc ,0 );
hFile = CreateFile("MYFILE.TXT", // open MYFILE.TXT
GENERIC_WRITE, // open for reading
0, // share for reading
NULL, // no security
OPEN_ALWAYS, // existing file only
FILE_ATTRIBUTE_NORMAL, // normal file
NULL); // no attr. template
dwPos = SetFilePointer(hFile, 0, NULL, FILE_END);
//WriteFile(hFile, szWindowData, iWindLength, &dwBytesWritten, NULL);
WriteFile(hFile, szWindowData, iIndex, &dwBytesWritten, NULL);
CloseHandle(hFile);
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
int iWindLength;
TCHAR szText [255];
iWindLength= GetWindowText (hwnd, szText, sizeof (szText)) ;
if ( szText!= NULL )
{
szText[iWindLength]='\r';
iWindLength++;
szText[iWindLength]='\n';
iWindLength++;
for(i=0;i<iWindLength;i++)
szWindowData[++iIndex]=szText[i];
}
return 1;
}