triumphost 120 Posting Whiz

Did this:

BOOL CALLBACK WorkerProc(HWND hwnd, LPARAM lParam){
    GetWindowText(hwnd, buffer, 50);
    if(buffer, L"FireFox") {
        // do something with hwnd here
		::SendMessage(hwnd, WM_KEYDOWN, VK_F12,0);
        return FALSE;
    }

    return TRUE;
}

Called it like so:

EnumWindows(WorkerProc, NULL);

But it didnt compile :S

triumphost 120 Posting Whiz

Can someone explain why it wont find the window?? I did everything right, Im pretty sure of it :S Yet it just wont find it.

EDIT: Admin delete.. I think I just figured it out..

private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
					Form1::Visible = false;
					Query ^ F = gcnew Query();   //<-- Form2
                    //F->Show();
					F->ShowDialog();
					System::String^ StringF = F->textBox1->Text;
					IntPtr ptr2 = System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(StringF);

				 HWND Simba = FindWindowW(0, (LPCWSTR)ptr2.ToPointer());
				 if(Simba != NULL)
				 {
					 MessageBox::Show("Found Script");
				 }
				 else
				 {
					 MessageBox::Show("Cannot Find Window");
				 }
				 System::Runtime::InteropServices::Marshal::FreeHGlobal(ptr2);

EDIT (MY FIX):

HWND Simba = FindWindowW(0, (LPCWSTR)ptr2.ToPointer());

//changed to

HWND Simba = FindWindow(0, (LPCSTR)ptr2.ToPointer());
triumphost 120 Posting Whiz

Oh damn that was hella hard to read!! Next time put it in code tags so I wont hurt my eyes..

.Net Version that I usually Use..:

RegisterHotKey(NULL,1,0x4000,0x7A);  //0x7A is 'F11'         <---- 0x4000 is MOD_NOREPEAT

MSG msg = {0};
  while (GetMessage(&msg, NULL, 0, 0) != 0)           <--- Notice the while...
   {
	if (msg.message == WM_HOTKEY)
	{
	 //MessageBox::Show("WM_HOTKEY received");
	   ::SendMessage(Simba, WM_KEYDOWN, VK_F12,0);
	}
   }

For what u need..:

#include "stdafx.h"

int _cdecl _tmain (
    int argc, 
    TCHAR *argv[])
{           
    if (RegisterHotKey(
        NULL,
        1,
        MOD_ALT | MOD_NOREPEAT,
        0x42))  //0x42 is 'b'
    {
        _tprintf(_T("Hotkey 'ALT+b' registered, using MOD_NOREPEAT flag\n"));
    }
 
    MSG msg = {0};
    while (GetMessage(&msg, NULL, 0, 0) != 0)
    {
        if (msg.message == WM_HOTKEY)
        {
            _tprintf(_T("WM_HOTKEY received\n"));            
        }
    } 
 
    return 0;
}

http://msdn.microsoft.com/en-us/library/ms646309.aspx

triumphost 120 Posting Whiz

How do I find a window by partial title.. or if the title contains a certain word..

I was thinking GetWindowText but that requires that I have the handle already..
I was going to enum windows I think that I can search for a window title containing the string.. if it finds the string, compare it to mine and if it is the same then get the handle.

Or is there a better way to find the window for sure?
By Process? By FileName? *gah* brain overload.

triumphost 120 Posting Whiz

I believe he is trying to do this:

#include <iostream>

using namespace std;

char Package;

int main()
{
  cout<<"Choose a package: 1 = Package A, 2 = Package B\n";
  cin>>Package;                         //This is how u get the user choice..

  if(Package == '1')                    //I guess u mean split choice by if and else meaning if this then... else...
  {
    //Do stuff
  }
  else if(Package == '2')               //The If and else statement will let do something depending on the choice made.
  {
    //Do stuff
  }
return 0;
}
mrnutty commented: bad code -1
WaltP commented: And why do his homework for him? -3
Derek Elensar commented: Global variable = bad, bad, bad. +0
triumphost 120 Posting Whiz
RegisterHotKey(hWnd,1,MOD_ALT,0x53);
				 if(WM_HOTKEY == 1)
				 {
					 MessageBox::Show("fdg");
				 }

Put the Registerhotkey in the part that initialized the program.. for example:

private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
RegisterHotKey(hWnd,1,MOD_ALT,0x53);
}

Then call the If hotkey wherever its supposed to check..

or:
http://windowscoding.com/blogs/blake/archive/2009/05/19/how-to-register-a-keyboard-shortcut-hot-key-in-a-net-windows-forms-application.aspx

triumphost 120 Posting Whiz
#pragma once
#pragma comment(lib, "advapi32.lib")
#pragma comment(lib, "user32.lib")
#include <windows.h>
#include <tlhelp32.h>
#include <iostream>
#include <conio.h>
#include <string.h>
#include <string>
#include <sstream>
#include <cstdlib>

#using<system.dll>

namespace Testing {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for Form1
	///
	/// WARNING: If you change the name of this class, you will need to change the
	///          'Resource File Name' property for the managed resource compiler tool
	///          associated with all .resx files this class depends on.  Otherwise,
	///          the designers will not be able to interact properly with localized
	///          resources associated with this form.
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Button^  button1;
	protected: 

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
			this->button1 = (gcnew System::Windows::Forms::Button());
			this->SuspendLayout();
			// 
			// button1
			// 
			this->button1->BackColor = System::Drawing::Color::Tan;
			this->button1->BackgroundImage = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"button1.BackgroundImage")));
			this->button1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 7, System::Drawing::FontStyle::Italic, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0), true));
			this->button1->ForeColor = System::Drawing::Color::Gold;
			this->button1->Location = System::Drawing::Point(1, 1);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(27, 33);
			this->button1->TabIndex …
triumphost 120 Posting Whiz

Not really a question?? Explain what u want properly.. The code above shows me nothing except that you have it set up like a telephone thats all.. and it prints a corresponding number when the person types a letter..

What exactly do u want?

you can do something like after the first character is pressed, printf("-") then after 3 characters is pressed do the same and then another three

triumphost 120 Posting Whiz

NVM solved it... only problem I got now is:

"Compiling Main.cpp"
The syntax of the command is incorrect.
make: *** [build/windows/Main.o] Error 1

triumphost 120 Posting Whiz

Open a console and go to the folder that contains Makefile and type

make windows

I have mingw, codeblocks-mingw10, devc++-mingw, vs2010, vs2008.. Just installed most of that just to compile this :(


:( Ur really helpful by replying but I tried that, didnt work.. this is what I did..

Right clicked my computer, went to advanced, Environment variables, added "C:\MinGW\bin" to the end of the Path variable.

exited everything.. Opened cmd prompt by typing CMD in the start menu (windows7)

Cmd comes up, i typed:

Cd C:\Users\BT\Desktop\public-smart

Pressed Enter/Return.
Then I typed:

Make windows <-- didnt work.

Make Makefile <-- didnt work.
'make' is not recognized as....

triumphost 120 Posting Whiz

Uhhh I've never compile with a makefile before... I download codeblocks-mingw10 because someone said itll work.

I just dont know the steps to take.. I know I need to use command prompt and the cd command and the make command.. but Other than that, Im completely lost.

triumphost 120 Posting Whiz
#include <iostream>
#include <windows.h>
#include <stdlib.h>
#include <windows.h>
#include <iostream>
#include <string>
using namespace std;

string elementname;
string mainmenuyesno;
int consoletextcolour;
HANDLE hConsole;

void Mainmenu()
{
    consoletextcolour = 234;
	SetConsoleTextAttribute(hConsole, consoletextcolour);
	cout <<"Welcome to Valestrom's Periodic Table"<<endl;
	cout <<"Please report any problems to Blackmethod@gmx.com"<<endl;
	system("cls");
	cout <<"Valestrom's Periodic table. By Blackmethod and Valestrom"<<endl;
	system("cls");
	cout <<"Valestrom's periodic table V1.0"<<endl;
	cout <<"Type the name of an element to get info on it: ";
}

int main () {
do{
    
	Mainmenu();
    cin>>elementname;
	if (elementname == "Lithium" || elementname == "Li")
    {
	 system("cls");
	 cout <<"LITHIUM (Li): Atomic Weight: 6.941" <<endl;
	 cout <<"Ionic Charge: +1, Melting Point: 180.54 C" <<endl;
	 cout <<"Boiling Point: 1342 °C"<<endl;
	 cout <<"Return to main menu? Yes/No: ";
	 cin>>mainmenuyesno;
        if (mainmenuyesno == "Yes")
		   Mainmenu();
	    else 
           exit(1);
	}
	else if (elementname == "Hydrogen" || elementname == "H")
	{
	 system("cls");
	 cout <<"HYDROGEN (H): Atomic Weight: 1.00794" <<endl;
	 cout<<"Ionic Charge: +1 -1, Melting Point: -259.14 C" <<endl;
	 cout<<"Boiling Point: -252.87 C"<<endl;
	 cout <<"Return to main menu? Yes/No: ";
	 cin>>mainmenuyesno;
	   if (mainmenuyesno == "Yes")
		  Mainmenu();
	   else 
          exit(1);
	}
		
}while(mainmenuyesno == "Yes");
	return 0;
}

Well you would have to make a map of the strings or Chars since Switch() only accepts integrals and chars. and thats kinda too much work to make a map of it all.. If it was C# then sure you can do something like:

cout<<"Enter Element Name";
cin>>elementname;
switch(elementname)
{
   case "Lithium": cout<<"fdgsdg";        <---- Notice the strings "Lithium".. In c++ u can only do that for integers and …
triumphost 120 Posting Whiz

Ummm First off dont Use Goto because it skips over a bunch of code... Use function-prototypes or else make a function with the mainmenu before int main().. Second why not use Switches and Cases?

I will test it..

Edit: Your problem was the GoTo.. it skips over the code.. and whatever was already inputted, stays in the input buffer.. Clearing the buffer for me is always a pain in the ass so instead Just made a function called Mainmenu(); and called it whenever..

#include <iostream>
#include <windows.h>
#include <stdlib.h>
#include <windows.h>
#include <iostream>
#include <string>
using namespace std;

string elementname;
string mainmenuyesno;
int consoletextcolour;
HANDLE hConsole;

void Mainmenu()
{
    consoletextcolour = 234;
	SetConsoleTextAttribute(hConsole, consoletextcolour);
	cout <<"Welcome to Valestrom's Periodic Table"<<endl;
	cout <<"Please report any problems to Blackmethod@gmx.com"<<endl;
	system("cls");
	cout <<"Valestrom's Periodic table. By Blackmethod and Valestrom"<<endl;
	system("cls");
	cout <<"Valestrom's periodic table V1.0"<<endl;
	cout <<"Type the name of an element to get info on it: ";
	cin>>elementname;
}

int main () {

	Mainmenu();



	if (elementname == "Lithium" || elementname == "Li")       //Try to use Cases instead of if this and if that and if the other..
		do {
		system("cls");
	cout <<"LITHIUM (Li): Atomic Weight: 6.941" <<endl;
	cout <<"Ionic Charge: +1, Melting Point: 180.54 C" <<endl;
	cout <<"Boiling Point: 1342 °C"<<endl;
	cout <<"Return to main menu? Yes/No: ";
	cin>>mainmenuyesno;
	if (mainmenuyesno == "Yes")
		Mainmenu();
	else 
		exit(1);
		} while (elementname == "Lithium" || elementname == "Li");
	
	
	
	if (elementname == "Hydrogen" || elementname == "H")
		do {
		
	system("cls");
	cout <<"HYDROGEN (H): …
valestrom commented: Damn good help. +1
triumphost 120 Posting Whiz

I've download this following program source from a SVN repository..
http://blanddns.no-ip.org:81/repos/public-smart/

How do I compile it?? I've tried but it has c++ and java files included in it.. and some are even in separate folders.

Can someone tell me how? Do I have to do command line? Do I need linux? Im on windows 7 with devc++ and visual studio 2010 and 2008.

Im only used to compiling c++ but not c++ and both java and it has no sln/project file include.. its just pure source code :S

triumphost 120 Posting Whiz

K I just got this Idea that I want to implement into a program I downloaded. Yes the program is open source but I dont wanna compile it, I just want to sort of Inject?..

What I want to do is add a button to the program and have the button execute my own code without affecting itself..

I was thinking of making a program with a button and then setting the parent to the one I downloaded but then realized that my program will still be running.

If possible I would also like to resize the buttons that already exist on the program to make space for my own..

Does anyone have any idea how to go about this?? I dont need source code I just need to know how. If u do have source code then thats fine and always a plus but its not "NEEDED".

triumphost 120 Posting Whiz

LOL where is the source code... how can we know what the program is doing just by u giving us a name?? And please insert the source code into code tags..

triumphost 120 Posting Whiz

Dont know if thats even possible but I do know how to make the DLL a resource and then have the program extract the Dll when needed... Your basically asking for the decompilation of the DLL

triumphost 120 Posting Whiz

KK I've been using mouse_eventf for clicking buttons in another application..

To do this I've done GetClientRect to get the size of the client and then click the button at a certain distance from one edge of the client...


What I noticed that is that if the user's computer is slow as hell and I run this command, it just moves onto the next command..

I want it to wait until a window shows up ON SCREEN.. or detect if the button was clicked in another app.

Or is there a way to read text in the other app??

P.S. Originally I was going to do something like:
If FindBitmapIn(x,y, x2, y2) then Mouse_Eventf(x,y,0,0,0); But I realized thats kinda impossible in c++

Or if FindWindow(0, "asfsd") then Mouse_Eventf(x,y,0,0,0); but the reason this doesnt work is that even when the window is minimized to the systray, it will move the mouse no matter what.

triumphost 120 Posting Whiz

I dont know how to get binary code from memory or anything but I do have code that can extract a binary from resources if that helps..

triumphost 120 Posting Whiz

Sigh Ill mark this one as solved too.. no one has an answer so no point keeping the thread open.. I assume they think im coding a virus or malicious program :S.. Though I'd question if I was capable of doing such a thing, i'd have answered my own thread and questions already.

triumphost 120 Posting Whiz

Sigh not exactly what i was looking for.. I just wanted to know if its possible strictly in c++ but I guess no so ill just mark this one as solved.. If ppl have responses then they can respond as im always checking back.. ty for your response though sir.

triumphost 120 Posting Whiz

Is this possible to embed a console into the gui like the picture below??
If so I wanna know how.

[img]http://img229.imageshack.us/img229/6995/cmdahk.jpg[/img]

found it here: http://www.autohotkey.com/forum/topic45935.html

triumphost 120 Posting Whiz

Well If you wanna see the source code, here it is.. It basically just constantly runs on the computer checking if a process is running.. and exits it if its running too long.. Thing is the user isnt supposed to exit the program in any form or way other than removing it from the startup folder, or through the task manager..

Yes they can close the program through the task manager, and they can stop it from running on startup by removing it from the start up folder.. But I dont want the program to be closed by any buttons.. and the button shows up on the TASKBAR allowing it to be closed that way.

If it can be done with windows form command: ShowInTaskbar = false; Why cant it be done with a simple console program?

Also saw an example where someone said:

ShowWindow(hwnd, SW_HIDE);
SetWindowLong(hWnd, GWL_STYLE, GetWindowLong(hWnd, GWL_STYLE) | WS_APPWINDOW);
ShowWindow(hwnd, SW_SHOW);

I guess changing the style should make it disappear from the taskbar.. but it doesnt work for my console app :S

I believe those examples only works for API, MFC, FORM..

It really isnt meant to annoy the user.. My cousin has been put on a guest account on MY computer because he 2 classes and I wanted to test my c++ skills and write a program to limit how much time he plays a game or does a specific activity. Thats y I dont want it …

triumphost 120 Posting Whiz

*sigh* Guess I needa simplify my question since there were no responses for 17 hrs straight..

I know how to do this in windows form with the command this->ShowInTaskbar = false..

How do I do this in a normal console app?!?!

triumphost 120 Posting Whiz

I would assume these slight differences would be due to rounding... as we know floats and doubles never ever come out pefectly and is usually rounded. Not sure if machines have anything to do with it though but there is a possibility that it does.. I wouldnt bet my money on the difference in processors.. I dont think a sandy bridge processor should affect the result in comparison to the i7.. I just believed those were rounding tolerances :S

triumphost 120 Posting Whiz

add this to the top of your code:

#include <iostream>   //U already have iostream so no need to put that again.. but put the following:

using namespace std;  //Without this, every line beginning with cout would have to be replaced with std::cout.

*sigh* No offense or anything.. You are better than me cuz I dont know arrays PERFECTLY but Im not exactly sure how you learned about arrays and functions without knowing that.. when your if-else statements contain more than one calc/statements/whatever.. it needs cbrackets..

Example:
This is ok..

if(x == 1)  //this is fine because it only contains cout<<x and the else part only contains cout<<"x != 1"..
   cout<<x;
else
   cout<<"x != 1";

This is not OK..

if(x == 1)  //this is not ok because it contains cout<<x & cout<<"try again" and the else part also has two statements..
   cout<<x;       //statement 1
   cout<<"try again";   //statement 2
                                   //no brackets here!?!?! why not?? that = bad..
else
   cout<<"x != 1";    //statement 1, no opening cbrackets
   cout<<"sigh";      //statement 2, also with no closing cbrackets..

The fix for the above "not ok" code.

if(x == 1)  //this is ok because it contains cout<<x & cout<<"try again" in cbrackets and the else part also has {two statements}..
{  
 cout<<x;               //statement 1
 cout<<"try again";     //statement 2
}
else
{
   cout<<"x != 1";   //statement 1
   cout<<"sigh";     //statement 2
}
triumphost 120 Posting Whiz

Hello everyone, I have one question.. should be relatively simple but I just cant seem to find any info anywhere.. maybe Im just looking in the wrong place and need guidance..

Here is my problem.. I have the following code:

EnableMenuItem(GetSystemMenu(GetConsoleWindow(), FALSE), SC_CLOSE , MF_GRAYED);
    DrawMenuBar(GetConsoleWindow());
    GetSystemMenu(GetConsoleWindow(), FALSE);   //Disables [(CTRL + SPACE) && (ALT + F4)]
    //HWND hWnd = GetConsoleWindow();     //Gets a handle to the console window...
    //ShowWindow( hWnd, SW_HIDE );        //Will Hide Console Itself..
    //ShowWindow( hWnd, SW_RESTORE );     //Restores Console Itself..

It disables the close(x) button on a console program but lets you minimize and maximize..
It also disables the ctrl space click and alt f4.. so they cant exit it that way either..

I have commented out the hiding and showing of the window because thats not what I want to do.. I want the user to see the program running, know that its running but not be able to exit it until its finished running!

I have gotten as far as disabling the close buttons and shortcuts that way, but they can right click the program on the taskbar and press close that way Or they can close it through task manager..

I want to disable those options while its running but KEEP the program ON Screen.
Show/Restore console makes it disappear completely.. (again not what I want).

Question: Is there a way to make it not show in task manager & to make it not right clickable on …

triumphost 120 Posting Whiz

In main, you have not declared what type x is.. whether is is int, double or float.. I have declared it for u as int type as your other functions show that you want it as int.

invalid initialization of reference of type ‘std::string&’ from expression of type ‘int’

thats because here:

void shift(score_struct* scores, string& name, int x, int& int_score)
//declares that the function should return in this order.. scores, name, int x, score...

//Instead you have it returning score, int x, name, int_score.. when you should have switched around name and x...
highScore(scores, x, name, int_score);

as for the other errors which I have not fixed, your functions are returning more arguments than they are declared for.. or they are being passed more than the amount they should hold due to your declarations.

You can either declare x BEFORE function main() or inside main();
#include<iostream>

#include<iomanip>

#include<string.h>

#include<sstream>

#include <string>



using namespace std;

const int SIZE = 5;//Constant for the size of the array



struct score_struct//Struct declaration

{

     string name;//string declaration in the struct class 
     int score;//int declaration in the struct class

};



void getInput(score_struct* scores, string& name, int& int_score);//getInput function declaration

void createList(score_struct* scores);//createList function declaration

void search(score_struct* scores, string& name, int x, int& int_score);//search function declaration

void highScore(score_struct* scores, string& name, int x, int& int_score);//sethigh function declaration

void shift(score_struct* scores, string& name, int x, int& int_score);



int main()

{
    int x;

     score_struct* scores = new score_struct[SIZE];//creates a new array pointer

     string name;//variable …
triumphost 120 Posting Whiz

Post the code here?? Like the entire thing.. or the .cpp file or both.

triumphost 120 Posting Whiz

I noticed that in the first code posting, you had if(moneyA == half) you didnt have the && index>= quantity.
Did you do that purposely?

triumphost 120 Posting Whiz

:O Didnt think of that... Yeah it looks scary with all the process checking and loops and stuff.. I'll clean it up as soon as I solve all the bugs. Usually while im coding it gets out of control and then when the program is done, it gets all neat.

Thanks again! I had a feeling you'd be the only one to reply -_-

btw how did your learn about threads?? I mean I know a little bit of it after you showed me an example but there isnt very good tutorials out there :S Or maybe Im just being difficult or blind.

triumphost 120 Posting Whiz

I've compiled your program this time to see what you are talking about... your while loop in the main() determines how your program will run... so while the user keeps entering Y or y, the program will keep running.. but when the user presses N or n, the program will then give the option to continue.. and when you do continue, it exits..

So far Each time I pressed Y or y, the program asks me to enter a new length.. and a new width. This is how the program is supposed to run. Nothing is wrong with is :S... Your "n" character on your keyboard maybe stuck..

Try the code below.. It works for the decimals that you wanted in your previous post.. I've shown you this in the previous threads but it doesnt seem like I explained well enough so instead i've just changed a few of your int's to double's..

Other than that, your program is perfect, the input stream is fine.. it does not constantly repeat if the user doesnt press y.. So I will assume your keyboard 'n' character button may be down or stuck.

example: area/COVERAGE can now out put 0.XX gallons instead of outputting 0.00 if area < coverage... (I changed approx. 3 int's to double's)

#include <iostream>
#include <iomanip>
#include <string>
using namespace std ;


// function prototypes
int GetLength();
int GetWidth();
double GetGallonCost();
double ComputeArea( int, int );
double FindGallons( double );
double ComputeCost( double, double …
triumphost 120 Posting Whiz

your code is

int FindGallons( int );  //line 12...   it should be double FindGallons(double);

and

//lines 134-138
int FindGallons( int paint_area )
{
  int area;
  paint_area = (area/COVERAGE);
  return paint_area;
}

Lines 134-138 should be..

double FindGallons( double paint_area )
{
  double area;
  paint_area = (area/COVERAGE);
  return paint_area;
}

double = decimal places.. or else use float..

Thought I already showed you that in the previous thread you posted.. I declared rounding as double.. AreaRounding..

For future reference try to post the problem in the same thread rather than start a brand new one unless really necessary... And someone passing through should see it.

triumphost 120 Posting Whiz
int ComputeArea( int length, int width )
{
int area;
area = length * width;
return length;
}

That should definitely not return length.. it should actually return area.. and is messing up your calculations..

Also to round up the amount of gallons:

int FindGallons( int paint_area )
{
int Area;
paint_area = (Area/COVERAGE);
return paint_area;
}

you would do something like:

int FindGallons( int paint_area )
{
int Area;
double AreaRounding = (Area%COVERAGE);  //Returns the remainder of the division if any..
paint_area = ((Area/COVERAGE) + AreaRounding);
return paint_area;
}
//use this to do the rounding..
double round( double value )
  {
    return floor( value + 0 );
  }
triumphost 120 Posting Whiz

This is the function in question...

What happens is the user opens notepad, if notepad is open then they are required to type a password.. If its invalid, notepad is closed.. if the password is valid, it continues.. else if the user hasn't entered a password within 10 seconds, timeout..

So the function works when the password is valid/invalid.. the problem is when the user times out, and they open notepad again, they cannot enter the password as it wont allow them..

Try compiling the attached .cpp file and see what I mean..

void pwget()
{    
     string password;
     password.clear();
     REPEAT
     char cProcess[80] = "notepad.exe";
     DWORD dwReturn;
     dwReturn = CountProcesses(cProcess);
     if(dwReturn != -1)
     {
                           if(dwReturn == 1)
                           {
                              cout<<"User Attempted to Open Program!\n\n";
                              
                              using namespace jsw::threading;
                              char pword[1024];
                              auto_event e;
                              LPVOID args[2] = {pword, &e};
                              thread worker = thread::start(get_password, args);
                              
                              if (e.wait(10000)){
                              string password(pword);
                                 if(password == "brandon")
                                 {
                                  system("cls");
                                  cout<<"Password was entered correctly.\n\n";
                                  Sleep(1000);
                                  system("cls");
                                  break;
                                  }
                                  else
                                  {
                                      system("cls");
                                      cout<<"Password is Invalid...\n\n";
                                      Sleep(1000);
                                      system("taskkill /IM notepad.exe");
                                      cout<<"\n";
                                      system("cls");
                                      cout<<"Welcome to GameBlock v1.0\n\n";
                                      pwget();
                                  }
                              }
                              else {
                              worker.abort(NO_ERROR);
                              cout<<"\n\nUser Timedout..\n\n";
                              Sleep(1000);
                              system("taskkill /IM notepad.exe");
                              cout<<"\n";
                              system("cls"); 
                              cout<<"Welcome to GameBlock v1.0\n\n";
                              pwget();
                              }
                           }
                           else if(dwReturn == 0)
                           {
                               cout<<"Program Not Running\n";
                               Sleep(1000);
                               main();
                           }
     }
    UNTIL((password == "brandon"));
    password.clear();
    cout<<"In Minutes, enter the length of time the program should run: ";
    cin>>x;
    cin.ignore();
    x = x*60;
}

Extra problems but not required to help fix: Timer Pause function doesnt work.. Find by me for now. I …

triumphost 120 Posting Whiz
if(isdigit(choice)

this is not gonna work , assume the input has already been corrupted it will hold a garbage value. Instead , he should probably check to see if input has been successful by using cin.good() and then loop though asking user to re-enter the value.

Uh might wanna check that again... it works :S I just compiled it.. as such:

[Edit]: Just read that you said "assume the input is already corrupted".. Uh I cant do that because the user has choice declared in the userChoice() function.. It if was declared outside the function or in main(), then I suppose you can assume that..

#include <iostream>
#include <windows.h>
#include <cctype>

using namespace std;


int userChoice()
{
    char choice;
    cin>>choice;
    if(isdigit(choice))
    {
        while((choice != '1') && (choice != '2'))
        {
          cout<<"that is not a valid choice please choose again ";
          cin>>choice;
        }
    }
    else
    {
        cout<<"Choice Is not a digit! ";
        userChoice();
    }
    return choice;
}

int main()
{
 userChoice();
}
triumphost 120 Posting Whiz

i dont understand any of that

Check out the isdigi() and isalpha() functions please.. To understand the code below.. The guys above are absolutely correct but clearing the input buffer will not help here.. instead a work around is to declare choice as a char and then to call isdigit() or isalpha() to check.. if it is a digit, run your while loop.. if it is a letter, re-run function userChoice(); and return choice;

Note: since it choice is of type char, you must use '1' (single quotes!) instead of.. 1 or "1"..

#include <cctype>   //This must be used as isdigit() and isalpha() is defined here.

int userChoice()  //Function userChoice();
{
    char choice;   //Declare choice as type char.
    cin>>choice;    //char choice accepts user input.
    if(isdigit(choice))   //check if the input in char choice is a digit.
    {
        while((choice != '1') && (choice != '2'))    //while choice is a digit and !=1 & !=2, run the code between {...} Note: '1' != "1"
        {
          cout<<"that is not a valid choice please choose again ";
          cin>>choice;      // Get the choice if it is digit, !=2 & !=1..
        }
    }
    else //Else if char choice is not a digit, run code between {...}
    {
        cout<<"Choice Is not a digit! ";
        userChoice();   //Since user entered an unacceptable choice (letter), rerun function userChoice();
    }
    return choice;
}

I added comments for extra explanation incase you dont read up on isdigit() and isalpha(), though I ask that u do. Also You must now use the …

triumphost 120 Posting Whiz

Well you see the thing is when getting process by id, the ID can change when the process restarts or exits depending on if another program already took the id during that interval. Meh Just look at how to Enumerate processes and look here: http://msdn.microsoft.com/en-us/library/ms683215

int isRunning(char *pProcessName)
{
    HANDLE hSnap = INVALID_HANDLE_VALUE;
    HANDLE hProcess = INVALID_HANDLE_VALUE;
    PROCESSENTRY32 ProcessStruct;
    ProcessStruct.dwSize = sizeof(PROCESSENTRY32);
    hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    if(hSnap == INVALID_HANDLE_VALUE)
        return -1;
    if(Process32First(hSnap, &ProcessStruct) == FALSE)
        return -1;
    do
    {
        if(stricmp(strupr(ProcessStruct.szExeFile), pProcessName)==0)
        {
            CloseHandle( hSnap );
            return  ProcessStruct.th32ProcessID;
            break;
        }
    }
    while( Process32Next( hSnap, &ProcessStruct ) );
    CloseHandle( hSnap );
    return -1;
}
triumphost 120 Posting Whiz

Solved by Narue Here... Oh man, Im so happy!!

http://www.daniweb.com/forums/thread349105.html

triumphost 120 Posting Whiz

Wow narue did u write all that just for this post?? I hope u already had that or its just an example cuz thats a lot of code!! Im going to study it and understand it.. I do not fully understand threads but with that, I will now try my best to understand what has been done. I will say the code works perfectly as is.. But I dont just want it to work, I wanna learn why it works and how. So thank you very much...

triumphost 120 Posting Whiz

Basically If the user does not enter a string or character or press any keys after a certain length of time, program will goto or ask again.. or do whatever..

Problem: Not allowing the user to enter input.. Note accepting user input..

#include <windows.h>
#include <stdio.h>
#include <iostream>
using namespace std;

string pword;

int main()
{
printf("You have 5 seconds to Enter the Password: ");
static HANDLE stdinHandle;
// Get the IO handles
// getc(stdin);  //If I take out the // from infront of getc(stdin); user can type but it doesnt accept it..
stdinHandle = GetStdHandle(STD_INPUT_HANDLE);

while (1)
{
DWORD rc = WaitForSingleObject(stdinHandle, 5000);
if( rc == WAIT_TIMEOUT )
{
//printf("Timeout...");
return 0;
}
else if( rc == WAIT_OBJECT_0 )
{
INPUT_RECORD r[512];
DWORD read;
ReadConsoleInput(stdinHandle, r, 512, &read);
}
else if( rc == WAIT_FAILED )
{
 printf("Error:%d.", GetLastError());
}
else
{
 cin>>pword;
 if(pword == "correct")
 {
          cout<<"Nicely done!";
 }
}
}

return 0;
}
triumphost 120 Posting Whiz

:S been 11 hrs and no one replied.. I guess I'll go by the title of this thread

"run a cmd code in mfc app"

cmd commands would be as useful as using system();
so for the cmd command: taskkill /F /IM notepad.exe
you would write in c++ system("task kill /F /IM notepad.exe");

As for the game your trying to start, I would say right cick the exe and press properties.. in the target field I guess u can enter +port 27015 or whatever.. At least thats how it works for most games.. in c++ im not sure how you would go about that.. other than the system(); call

triumphost 120 Posting Whiz

hmm cant figure it out.. Right now this is what I got..
Problems: Program waits an infinite amount of time for the user to enter a password.. and if process not running, timer doesnt pause.. instead it resets..

might look like a lot to read through but most of it is basically declarations.. program starts at line 113, ends at line 167

#define REPEAT do{
#define UNTIL( condition ) }while(!(condition));

#pragma comment(lib, "advapi32.lib")
#include <windows.h>
#include <tlhelp32.h>
#include <iostream>
#include <conio.h>
#include <string.h>
#include <time.h>	// class needs this inclusion

using namespace std;


//////////////////////////////////////////
// class declaration:


class timer {
	public:
		timer();
		void           start();
		void           stop();
		void           reset();
		bool           isRunning();
		unsigned long  getTime();
		bool           isOver(unsigned long seconds);
	private:
		bool           resetted;
		bool           running;
		unsigned long  beg;
		unsigned long  end;
};


//////////////////////////////////////////
// class implementation:


timer::timer() {
	resetted = true;
	running = false;
	beg = 0;
	end = 0;
}


void timer::start() {
	if(! running) {
		if(resetted)
			beg = (unsigned long) clock();
		else
			beg -= end - (unsigned long) clock();
		running = true;
		resetted = false;
	}
}


void timer::stop() {
	if(running) {
		end = (unsigned long) clock();
		running = false;
	}
}


void timer::reset() {
	bool wereRunning = running;
	if(wereRunning)
		stop();
	resetted = true;
	beg = 0;
	end = 0;
	if(wereRunning)
		start();
}


bool timer::isRunning() {
	return running;
}


unsigned long timer::getTime() {
	if(running)
		return ((unsigned long) clock() - beg) / CLOCKS_PER_SEC;
	else
		return (end - beg) / CLOCKS_PER_SEC;
}


bool timer::isOver(unsigned long seconds) {
	return seconds >= …
triumphost 120 Posting Whiz

12ft 3in and also to com out to 12.25

for that you would need a double.. pass the inches into a double type variable..

12 ft, 3in are both integers and hold no decimal places. if you do double x = inches/12 you should get the .xxxx u wanted. Just figure out the numbers to enter thats all. and implement

triumphost 120 Posting Whiz

Meh it works except... If u enter "pluto" instead of "Pluto" (capital letter P).. then it gives u an error and asks u to re-enter the planet name.. Other than that, it works as it should.. Another thing: If I enter a decimal, it wont work as the weight is not of type double.

triumphost 120 Posting Whiz

Uhh Try putting a location in the program like C:/Users/fdnsdnlgds/data.in

as for why its not grabbing the data... I dont know.. I usually use getline();
Used to have these problems.. try checking this thread:

http://www.daniweb.com/forums/thread283874.html

triumphost 120 Posting Whiz

^^OMG GOOD IDEA!! kk I got it to constantly check every few seconds if the process is running..

The only problem now is my password problem..

Any Idea how I can do the following:

cout<<"enter password: ";
cin>> x;

if after 10 seconds the user hasnt entered a password, terminate?

Is that possible??

triumphost 120 Posting Whiz

The ultimate goal is to control the overall uptime of a process.. Just an example:

User plays a game for 5 hrs straight.. decides to take a break and plays for 7 hrs straight after the break..

The program is to check total playtime (does not include the break).
the break is where the timer should pause.. If the uptime exceeds a certain amount (example: 20hrs) then stop the process and make sure it does not run until computer restarts.

Thats just an example though but I guess its pretty relevant to what I want..

Basically I was going to make the user enter a password.. the process must never start unless the password is right.. then after a certain amount of time (pause at breaks).. stop process until password entered again. If process started before password entered then exit process.. Ill implement all that later..

Just need to time the total uptime of a process

triumphost 120 Posting Whiz

Hi everyone, I made a program that will check if a process is running.. it is supposed to detect if a process is running and start a timer. If the process has been ended, the timer is paused.. when the process is restarted, the timer continues from where it last was. Until it reaches example 5 minutes.. or until the timer count reaches 1 hr.. etc..

The code I have is as follow:

#pragma comment(lib, "advapi32.lib")
#include "stdafx.h"
#include <iostream>
#include <windows.h>
#include <tlhelp32.h>
#include <stdio.h>
#include <stdlib.h> 

using namespace std;


DWORD CountProcesses(CHAR *pProcessName) 
{
    DWORD dwCount = 0;
    HANDLE hSnap = NULL;
    PROCESSENTRY32 proc32;

    if((hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)) == INVALID_HANDLE_VALUE)
        return -1;
    proc32.dwSize=sizeof(PROCESSENTRY32);
    while((Process32Next(hSnap, &proc32)) == TRUE)
        if(stricmp(proc32.szExeFile,pProcessName) == 0)
            ++dwCount;
    CloseHandle(hSnap); 
    return dwCount;
}

int main(void)
{
    DWORD dwReturn;
    char cProcess[80] = "hl.exe";		         //process to be checked..

    dwReturn = CountProcesses(cProcess);
    if(dwReturn != -1){
        printf("There are %d %s processes running\n",dwReturn, cProcess);   //check if process is running..
	}
    else{
        printf("CreateToolhelp32Snapshot failed\n");
	}


	if(dwReturn != -1){
		system("taskkill /F /IM hl.exe");		//Stop program from running..
          //would love to change this  something like system("taskkill /F /IM"<<cProcess<<"");
	}

	system("Pause");
    return 0;
}

And the timer I found on the internet, I edited and and added a repeat function but Im not sure how to implement it.. Or is there a far better way of checking how long it was running?

#define REPEAT do{
#define UNTIL( condition ) }while(!(condition));

#include <iostream.h>
#include <conio.h>
#include <windows.h>
#include <time.h>	// class needs this inclusion …
triumphost 120 Posting Whiz

Well.... U havent shown any effort :S

This is just a start but it is not the program:

#include <windows.h>
#include <string.h>
#include <math.h>
#include <cmath>
#include <iostream>

using namespace std;

int weight;
string Planet;

int main()
{
   cout<<"Please Enter The weight of an object: "
   cin>> weight;
   cout<<"\n\nPlease enter the Planet name: ";
   cin>> Planet;

   switch(Planet)
   {
    case: ........
          break;
    case: ........
          break;
    default: cout<<"that planet name is wrong or does not exist\n";
          break;
   }
return 0;
}

Of course u can use if-else statements.. such as if(.....){do something} else if (..){do something else} else{do something}

thats just a start.. but I cannot help any further till you show code or effort.

P.S. Your going to want to put a repeat function in there like a do while condition..
Another thing could be done like:

#define REPEAT do{
#define UNTIL( condition ) }while(!(condition));

then in your code you would write:
int i=0;
REPEAT
code here to make the program repeat until the user exits..
Until(i = 20);

etc..