|
No more easy cut-n-paste eh?
|
|
|
|
|
johtib wrote:
No more easy cut-n-paste eh?
Not with FF. CP is optimized for IE, FF seconds. Maybe you post in the 'Suggestions' forum?
|
|
|
|
|
i write some codes,that compute the fibonacci number:
#include<iostream.h>
#include<iomanip.h>
int fib(int n)
{
if(n<=2) return 1;
else
{
int i,j,k,l;
j=k=1;
for(i=2;i<=n;i++)
{
l=j;
j+=k;
k=l;
}
//if there has the return statement,the result "2" will be absent!
//return j;
}
}
void main()
{
int n,i;
cout<<"Compute fibonacci number,pelease input the index:"<<endl;
cin="">>n;
cout<<"fibonacci "<
|
|
|
|
|
kcynic wrote:
but if i alter the Cyc like this :for(i=2;isomebody would tell me why?
???
Don't try it, just do it!
|
|
|
|
|
i'm sorry,there should be :for(i=2;i
|
|
|
|
|
When you post your code, check the "Do not treat <'s as HTML tags" so that your for(int n = 0; n < 10; n++) comes out correctly.
|
|
|
|
|
Hello,
I was just wondering how hard it would be to take 'output' from a 3rd party program and use it as 'input' into my program. for example.
list_folder_contents.exe | myprog.exe
What I'm trying to do...
I have a 3rd party program that images drives. This program allows you to pipe the data/image as its creating it, so my thought was to pipe it into my program and as that data is coming in I would send it over a TCP socket.. The sending and receiving via the socket is easy enough.. I just havent ever tried to take output from another program and used it as input..
Any pointers on where I should start?
Thanks,
Rob
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|
|
Would these lines allocate valid memory for a 2D dynamic array?
.
.
.
float (*tmp)[4] = NULL;
if (( tmp = (float (*)[4])calloc(somenumberofmemblocks,4*sizeof(float) )) == NULL)
... error occurred
|
|
|
|
|
What error are you getting? This compiles cleanly and works under VC++ 7.1. Observe:
<br />
#include "stdafx.h"<br />
#include <iostream><br />
#include <conio.h><br />
<br />
int _tmain(int argc, _TCHAR* argv[])<br />
{<br />
const int block_count = 12;<br />
const int float_count = 4;<br />
<br />
float (*tmp)[float_count] = (float (*)[float_count]) <br />
calloc(block_count, float_count * sizeof(float));<br />
if(!tmp)<br />
{<br />
std::cout << "calloc failed";<br />
char c = getch();<br />
return 1;<br />
}<br />
<br />
float counter = 0;<br />
for(int n = 0; n < block_count; n++)<br />
{<br />
for(int nn = 0; nn < float_count; nn++)<br />
{<br />
tmp[n][nn] = counter;<br />
counter += 1.0;<br />
}<br />
}<br />
<br />
for(int n = 0; n < block_count; n++)<br />
{<br />
for(int nn = 0; nn < float_count; nn++)<br />
{<br />
std::cout << tmp[n][nn] << std::endl;<br />
}<br />
}<br />
<br />
char c = getch();<br />
return 0;<br />
}
Prints from 0 to 47.
|
|
|
|
|
Mark, thanks for the effort.
I was hoping I was doing my memory allocation wrong. I hadn't seen any text explicitly using the same technique, so I was hoping it was the source of my crashing which only seems to occur on certain machines. I've studied the code for days now and I'm just missing something.
|
|
|
|
|
Hi!
I need help to print out the points to the rectangles and save it in a array and use it for other functions...
The code:
void CObligatorisk_oppgaveView::OnLButtonDown(UINT nFlags, CPoint point)
{
leftdown = point;
}
void CObligatorisk_oppgaveView::OnLButtonUp(UINT nFlags, CPoint point)
{
leftup = point;
array.Add(CRect(leftup, leftdown));
Invalidate(false);
}
void CObligatorisk_oppgaveView::OnPaint()
{
CPaintDC dc(this);
//rect = CRect(leftdown,leftup);
//dc.Rectangle (rect);
int length = array.GetSize();
for(int i=0;i
|
|
|
|
|
Did it work for one rectangle when the lines below CPaintDC dc(this); were uncommented? Is there anymore information you can add? Your code looks fine to me.
|
|
|
|
|
I'll assume you are tracking the point passed to OnMouseMove for drawing purposes.
As for drawing: You need to normalize the rectangle before drawing it. That is the lower right-hand courner of the rectangle must be greater than (or equal to) the upper left-hand courner.
top <= bottom
left <= right
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
I have a wtl project with date time picker control on it.
simple question hopefully.
how do I get the time or date back from it once the user changes it?
I want to compare the current time with what the user enters.
|
|
|
|
|
The CDateTimePickerCtrl uses the SYSTEMTIME structure for it’s time. Getting it goes a little something like this:
CDateTimePickerCtrl dtp(GetDlgItem(IDC_DATETIME1));<br />
SYSTEMTIME st;<br />
Dtp.GetSystemTime(&st);
If your using it with the SHOW NONE property you can check the return value of GetSystemTime() making sure it returns GDT_VALID , if it’s GDT_NONE then the checkmark is cleared. If you want to use WTL::CTime add #include <atltime.h> to your stdafx.h and you can pass the SYSTEMTIME to it’s constructor and bam. CTime from a CDateTimePickerCtrl .
CDateTimePickerCtrl dtp(GetDlgItem(IDC_DATETIME1));<br />
SYSTEMTIME st;<br />
Dtp.GetSystemTime(&st);<br />
CTime t(st);
|
|
|
|
|
Thanks Mark
works a treat!
|
|
|
|
|
I have my small program which creates process, but now i want to manipulate more than one process at a time. Is that possible? Like i have created a notepad process and later while notepad is running i create another process cmd.exe, can i suspend them all one after the other or shut them consecutively maybe by specifying process id,s or handles
-oam-
|
|
|
|
|
Aww man you can do all kinds of rad things with processes. Pretty much everything that Task Manager can do you can do. What you want to do is call CreateProcess() and pay attention to the last argument, a PROCESS_INFORMATION structure which has the hProcess handle. With that your free to call functions like TerminateProcess() and SuspendThread() . However TerminateProcess() is pretty drastic and does not guarantee that anything will be freed and the process may need to run critical cleanup code. TerminateProcess() is like shutting a program off by unplugging the power. You could see if a process is associated with a window by calling EnumWindows() and comparing the ProcessId, which you can get from GetWindowThreadProcessId() .
Check out http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/process_and_thread_functions.asp[^] for Process/Thread manipulation.
|
|
|
|
|
Well my question lies in how to specify the handle or the process id of one the processes i have created to shut it down or suspend it that particular process. Pliz give me a segment code if you have.
<br />
<br />
#include <windows.h><br />
#include <stdio.h><br />
#include <windef.h><br />
#include <winbase.h><br />
#include <imagehlp.h><br />
#include <stdlib.h><br />
typedef struct _iobuf FILE;<br />
#include <assert.h><br />
#include <sys/types.h><br />
#include <sys/stat.h><br />
int menu(void)<br />
{<br />
int choice;<br />
<br />
printf ("\n");<br />
printf ("*****************************************\n");<br />
printf ("*\t\t\t\t\t*\n*\tCHECKPOINTING SYSTEM \t\t*\n");<br />
printf ("=========================================");<br />
printf ("\n=\t 1: Create a process \t=");<br />
printf ("\n=\t 2: Suspend the process\t=");<br />
printf ("\n=\t 3: Resume the process\t=");
printf ("\n=\t 4: System Information\t=");<br />
printf ("\n=========================================\n");<br />
printf ("\n");<br />
<br />
printf("\nEnter choice (1-4): ");<br />
scanf("%d", &choice);<br />
return choice; <br />
}<br />
<br />
int main(int argc, char **argv) <br />
{<br />
<br />
PROCESS_INFORMATION pi; <br />
STARTUPINFO si; <br />
HANDLE hProcess;<br />
HANDLE hThread = 0;<br />
DWORD NumberOfBytesRead = 0;<br />
DWORD baseaddr = 0;<br />
DWORD lpAddr = 0;<br />
PMEMORY_BASIC_INFORMATION lpBuffer = 0;<br />
DWORD dwLength = 200000;<br />
DWORD flNewProtect =0;<br />
PDWORD lpflOldProtect = 0;<br />
DWORD dwSize =0;<br />
LPCVOID lpBaseAddress = 0;<br />
DWORD nSize = 0;<br />
LPDWORD lpNumberOfBytesWritten = 0;<br />
TCHAR lpApplicationName[_MAX_PATH]="";<br />
SYSTEM_INFO sinfo;<br />
LPDWORD lpExitCode = 0;<br />
HWND hWnd = 0;<br />
DWORD dwProcessID = 0;<br />
UINT GetBase();<br />
LPCONTEXT lpContext = 0;<br />
int nRet = 0;<br />
unsigned int regnum = 0;<br />
<br />
<br />
char* ans="";<br />
int choice;<br />
<br />
while((choice = menu())!=5)<br />
{<br />
switch (choice)<br />
{<br />
<br />
case 1: <br />
<br />
GetStartupInfo(&si);<br />
lpAddr = 0;<br />
ZeroMemory( &si, sizeof(si) );<br />
si.cb = sizeof(si);<br />
ZeroMemory( &pi, sizeof(pi) );<br />
printf("Enter process you want to execute: ",lpApplicationName);<br />
scanf ("%s",lpApplicationName);<br />
printf("Process %d reporting for creation\n",GetCurrentProcessId());
<br />
CreateProcess(NULL, <br />
lpApplicationName, <br />
NULL, <br />
NULL, <br />
FALSE, <br />
CREATE_NEW_CONSOLE, <br />
NULL, <br />
NULL, <br />
&si, <br />
&pi <br />
); <br />
hProcess = pi.hProcess;<br />
printf("New Process ID: %d ",pi.dwProcessId);<br />
printf("has started \n"); <br />
break;<br />
<br />
case 2:<br />
<br />
SuspendThread(pi.hThread);
<br />
printf("\nThe thread of ID: %d",pi.dwProcessId);<br />
printf(" has been suspended!\n");<br />
GetLastError();<br />
<br />
break;<br />
<br />
case 3:<br />
<br />
ResumeThread(pi.hThread);
GetLastError();<br />
break;<br />
<br />
case 4:<br />
printf("\nSystem Info: ",&sinfo);
break;<br />
<br />
default:<br />
printf("\nInvalid choice: ");<br />
}<br />
}<br />
<br />
return (0);<br />
}<br />
|
|
|
|
|
You code looks fine, your passing the handles of the process and thread from the PROCESS_INFORMATION structure that gets filled out when you call CreateProcess(). Perhaps make sure that these calls are succeeding by checking the return values. If you wanted to keep track of more then one process then you could use a container class like MFC's CArray or CList or STL's vector or list.
|
|
|
|
|
Mark Petrik Sosa wrote:
Perhaps make sure that these calls are succeeding by checking the return values. If you wanted to keep track of more then one process then you could use a container class like MFC's CArray or CList or STL's vector or list.
I don't have any idea about MFC arrays because i am using C unless if they can work in c code. But i have no idea with MFC or CList nor STL vector. You can give me a go ahead or segment code to handle it
-oam-
|
|
|
|
|
I’m going to save and load an XML-file in an SQL server. I really like suggestions on how to tackle the problem. My application is an MFC C++ project.
_____________________________
...and justice for all
APe
|
|
|
|
|
I use checker = atoi( (LPCTSTR)str) to convert CString to int and checker to check if the number typed in CEdit box is within valid range.
Now the problem is when user type a number then follow by letters. 1234abcd would return checker as 1234. How would I go about checking for non-integer characters?
Or is there anyway to limit user to only type in integers?
|
|
|
|
|
Anonymous wrote:
Or is there anyway to limit user to only type in integers?
edit controls have a "number only" property. check for it in the resource editor / property viewre.
Image Toolkits | Image Processing | Cleek
|
|
|
|