Click here to Skip to main content
16,005,389 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: close an application Pin
Jhony george13-Jun-07 1:01
Jhony george13-Jun-07 1:01 
GeneralRe: close an application Pin
Russell'13-Jun-07 1:21
Russell'13-Jun-07 1:21 
AnswerRe: close an application Pin
Hamid_RT13-Jun-07 3:40
Hamid_RT13-Jun-07 3:40 
GeneralRe: close an application Pin
Russell'13-Jun-07 3:45
Russell'13-Jun-07 3:45 
GeneralRe: close an application Pin
Russell'13-Jun-07 3:53
Russell'13-Jun-07 3:53 
GeneralRe: close an application Pin
Hamid_RT13-Jun-07 9:01
Hamid_RT13-Jun-07 9:01 
GeneralRe: close an application Pin
Hamid_RT13-Jun-07 8:59
Hamid_RT13-Jun-07 8:59 
Questionhelp with WM_KEYDOWN Pin
Sam Rens12-Jun-07 21:50
Sam Rens12-Jun-07 21:50 
need to save my output ( dataval10,dataval20,dataval30) in a file everytime
i press a key. Right now they are being written in a file continuously.

i thik i have to use the case WM_KEYDOWN ... but not sure how to fit it in my code
& how to get the output written to a file when the button was pressed... Help will be super !!!!!!

[code]

// **********************************************************************/

/* Include files */

#include <windows.h> /* Compiler's include files's */
#include <string.h>
#include <stdio.h>
#include "..\cbw.h" /* Universal Library's include file */

#define BOARD_NUM 1 /* Number of A/D board as defined with InstaCal */
#define ADRANGE BIP10VOLTS /* A/D voltage range */
#define TIMER_NUM 1 /* Windows timer used by this program */

HWND hWndMain; /* handle for main window */

LONG FAR PASCAL MainMessageHandler (HWND, UINT, WPARAM, LPARAM);



int PASCAL
WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR CmdLine, int nCmdShow)
{
MSG msg; /* MSG structure to pass to windows proc */
WNDCLASS wndclass;
char *AppName; /* Name for the window */

cbErrHandling (PRINTALL, STOPALL); /* Set library's error handling */

CmdLine = NULL; /* Not used */
AppName = "WINCDEMO"; /* The name of this application */
if(!hPrevInstance)
{
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc= MainMessageHandler;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (hInstance, AppName);
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = GetStockObject (WHITE_BRUSH);
wndclass.lpszMenuName = AppName;
wndclass.lpszClassName = AppName;
RegisterClass (&wndclass);
}


/* create application's Main window */
hWndMain = CreateWindow (AppName, /* Window class name */
"Sensor Output",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, /* Use default X, Y */
CW_USEDEFAULT, /* Use default X, Y */
GetSystemMetrics(SM_CXSIZE) * 12, /* x - fit text */
GetSystemMetrics(SM_CYSIZE) * 10, /* y - fit text */
NULL, /* Parent window's handle */
NULL, /* Default to Class Menu */
hInstance, /* Instance of window */
NULL); /* Create struct for WM_CREATE */


if (hWndMain == NULL)
{
MessageBox(NULL, "Could not create window in WinMain", NULL, MB_ICONEXCLAMATION);
return (1);
}

ShowWindow(hWndMain, nCmdShow); /* Display main window */
UpdateWindow(hWndMain);

// /* Start a 500ms timer to update display */
if(!SetTimer(hWndMain, TIMER_NUM, 50, NULL))
{
MessageBox(NULL, "Error starting Windows timer", NULL, MB_OK |
MB_ICONEXCLAMATION);
return (1);
}

while(GetMessage(&msg, NULL, 0, 0,PM_REMOVE)) /* Main message loop */
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

UnregisterClass (AppName, hInstance);
return (msg.wParam);
}




LONG FAR PASCAL
MainMessageHandler(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
HDC hDC; /* handle for the display device */
PAINTSTRUCT ps; /* holds PAINT information */
TEXTMETRIC tm; /* holds TEXT information */

static HRGN hRgn; /* Rectangle region Handles */
static int CharWidth, CharHeight;
static unsigned short DataVal, DataVal1, DataVal2, DataVal3;
static unsigned long DataVal0, DataVal10, DataVal20, DataVal30;

int x, y;
static char OutString[5000], *str;
// float Voltage;
static double yn,mu;
double t = 10000;

FILE *fp;
fp = fopen("Data1.txt", "a");

switch (Message) /* Windows Message Loop */
{
case WM_CREATE:
hDC = GetDC(hWndMain); /* Get the device context for window */
GetTextMetrics(hDC, &tm); /* From context, get size of font */
CharWidth = tm.tmAveCharWidth;
CharHeight = tm.tmHeight + tm.tmExternalLeading;
ReleaseDC(hWndMain, hDC);
hRgn = CreateRectRgn(0,0, CharWidth*30, CharHeight*12);
break;

case WM_TIMER: /* All Timer Events Processed Here */
InvalidateRgn(hWndMain, hRgn, FALSE); /* Force screen update */
break;





case WM_PAINT: /* Repaint client area of window */
hDC = BeginPaint(hWndMain, &ps);
x = CharWidth * 2; /* Position cursor within window */
y = CharHeight; /* One line down and 2 chars in */
str = " Output"; /* Print title */
TextOut(hDC, x, y, str, strlen (str));

y += CharHeight; /* Print current index */
cbAIn (BOARD_NUM, 0, ADRANGE, &DataVal);
cbAIn (BOARD_NUM, 1, ADRANGE, &DataVal1);
cbAIn (BOARD_NUM, 2, ADRANGE, &DataVal2);
cbAIn (BOARD_NUM, 3, ADRANGE, &DataVal3);

mu = t / ( t + 3 );

DataVal0 = (double)mu * ( (double)DataVal - (double)DataVal0 ) + DataVal0;

y += CharHeight*2; /* Print raw data value */
sprintf (OutString,"Sensor0 = %u ", DataVal0);
TextOut(hDC, x, y, OutString, strlen (OutString));

DataVal10 = (double)mu * ( (double)DataVal1 - (double)DataVal10 ) + DataVal10;

y += CharHeight*2; /* Print raw data value */
sprintf (OutString,"Sensor1 = %u ", DataVal10);
TextOut(hDC, x, y, OutString, strlen (OutString));

DataVal20 = (double)mu * ( (double)DataVal2 - (double)DataVal20 ) + DataVal20;

y += CharHeight*2; /* Print raw data value */
sprintf (OutString,"Sensor2 = %u ", DataVal20);
TextOut(hDC, x, y, OutString, strlen (OutString));

DataVal30 = (double)mu * ( (double)DataVal3 - (double)DataVal30 ) + DataVal30;

y += CharHeight*2; /* Print raw data value */
sprintf (OutString,"Sensor3 = %u ", DataVal30);
TextOut(hDC, x, y, OutString, strlen (OutString));


fprintf(fp,"%u %u %u %u \n",DataVal0,DataVal10,DataVal20,DataVal30);
fclose(fp);

// y += CharHeight; /* Convert raw A/D to volts and print */
// cbToEngUnits (BOARD_NUM,ADRANGE,DataVal,&Voltage);
// sprintf (OutString,"Voltage = %.2f ", Voltage);
// TextOut(hDC, x, y, OutString, strlen (OutString));

SetTextAlign(hDC, TA_LEFT | TA_TOP);
EndPaint(hWndMain, &ps);
break;

case WM_CLOSE: /* Close the window */
DestroyWindow(hWnd);
if (hWnd == hWndMain)
PostQuitMessage(0); /* Send message to Quit application */
break;

default:
return (DefWindowProc(hWnd, Message, wParam, lParam));
}
return (0l);
}

[/code]
AnswerRe: help with WM_KEYDOWN Pin
Nelek12-Jun-07 23:28
protectorNelek12-Jun-07 23:28 
GeneralRe: help with WM_KEYDOWN Pin
Sam Rens13-Jun-07 0:16
Sam Rens13-Jun-07 0:16 
GeneralRe: help with WM_KEYDOWN Pin
Nelek13-Jun-07 7:36
protectorNelek13-Jun-07 7:36 
QuestionVC++ Pin
srinivasa phani kiran12-Jun-07 21:47
srinivasa phani kiran12-Jun-07 21:47 
AnswerRe: VC++ Pin
Naveen12-Jun-07 21:57
Naveen12-Jun-07 21:57 
AnswerRe: VC++ Pin
Nelek12-Jun-07 23:25
protectorNelek12-Jun-07 23:25 
QuestionGDI & Image Processing Pin
KienNT7812-Jun-07 21:05
KienNT7812-Jun-07 21:05 
AnswerRe: GDI & Image Processing Pin
CPallini12-Jun-07 21:23
mveCPallini12-Jun-07 21:23 
AnswerRe: GDI & Image Processing Pin
Nelek12-Jun-07 23:22
protectorNelek12-Jun-07 23:22 
Questionproblem in file open dialog box Pin
trioum12-Jun-07 20:57
trioum12-Jun-07 20:57 
AnswerRe: problem in file open dialog box Pin
Hamid_RT12-Jun-07 21:30
Hamid_RT12-Jun-07 21:30 
AnswerRe: problem in file open dialog box Pin
trioum13-Jun-07 1:26
trioum13-Jun-07 1:26 
GeneralRe: problem in file open dialog box Pin
Hamid_RT13-Jun-07 3:34
Hamid_RT13-Jun-07 3:34 
QuestionUsing OpenGL Text Output with DIB Section Pin
beko12-Jun-07 20:37
beko12-Jun-07 20:37 
QuestionNeWbie Rook Programmer! Pin
brandonsjo12-Jun-07 20:36
brandonsjo12-Jun-07 20:36 
AnswerRe: NeWbie Rook Programmer! Pin
Hamid_RT12-Jun-07 21:30
Hamid_RT12-Jun-07 21:30 
AnswerRe: NeWbie Rook Programmer! Pin
Nelek12-Jun-07 23:18
protectorNelek12-Jun-07 23:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.