triumphost 120 Posting Whiz

Umm I do not see any code for your worker.. it doesn't seem to have any work to do :S

Your program itself seems to be doing the work and then you call backgroundworker() which isn't shown here..
Backgroundworker is a thread.. where you give it work to do while the program does something else.. then the program gathers the work while the thread sleeps..
When the thread is done working, there is a command to tell the program it is finished and then it *joins* and sleeps.

Calling RunWorkerAsync when the work is already being done will result in *InvalidOperationException*

This Code would definitely get around that problem.. But it only allows you to run whatever is in the backgroundWorker_DoWork Function..

private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
    backgroundWorker1->DoWork();
    //Program does other stuff here while backgrounder worker does other stuff.

}

private: System::Void backgroundWorker1_DoWork(System::Object^  sender, System::ComponentModel::DoWorkEventArgs^  e) {
                               //Does calculations and all the work here.                                 
                                 Thread::Sleep(1000);  //Thread must sleep or else u may find a huge increase in CPU usage.
			 }

For Running Worker Asynchronously, you definitely have to do something like this:
http://msdn.microsoft.com/en-us/library/waw3xexc.aspx

What happens is that they call runworkerasync() and it does the work specified.. then it reports when its completed or if its cancelled and then the thread sleeps or is given more work to do. RunWorkerAsync can be given more work where as DoWork() just does work that is already pre-defined.. thats the only differences.

triumphost 120 Posting Whiz

Hi garu525, did you find a solution to your problem?

I am having the exact same problem with VS 2010 on Vista and NVIDIA graphics HW (Quadro PCI-E, using latest driver 7.14.10.9687).
Menus get blurred and it looks like it's slowing down VS 2010.
Changing resolution to 1024x1280 or going to Safe mode helps, but I don't want to do that...

I am very thankful for any help. I have googled all day, looks like Microsoft cannot help either (which I find very strange).

I believe your currently running Windows 7 basic theme.. Go control panel -> appearance and personalization -> Change theme... choose an aero theme.. (You can always change your wallpaper later)..


Right click My Computer -> Properties -> Advanced System Settings(in the side bar) -> Advanced Tab -> Settings (The Performance one)... Now put a check mark in "Let windows choose whats best for my computer".. save the settings, exit all and then open vs2010 and see..

If the problem is still there, go get a different driver or update your graphics driver..

triumphost 120 Posting Whiz

:o What a question.. You can use Windows Forms (.Net).. Try it. start a new project, give it a name.. choose WindowsForm Application.. it will set up a default looking form where you can drag and drop controls..

Copy your code to whatever you want it to do.. basically you double click the control and put the code that that control is supposed to do. Remember though your program is probably a console program so your going to need to revise some of the code..

Then there is Windows 32 API programming.. which I see as a bit harder when it comes to making GUI's due to me having a hard time figuring out where to place the buttons on the main form and you'd need to know the co-ordinates of where you want the button position to be, etc.. But if you do learn this, it will be very easy for you and does not require the .Net framework at all.. which is a Plus for most users (people wont have to download .Net framework to run your program)

triumphost 120 Posting Whiz
timeCount(testCPPFind, 1E2, "testCPPFind");
timeCount(testCPPFind2, 1E2, "testCPPFind2");
timeCount(testCFind, 1E7, "testCFind");             <--- Why not 1E2?? Its different from the other two functions before it..

Could also be that CFind does less work.. Not sure

triumphost 120 Posting Whiz
triumphost 120 Posting Whiz

Maybe your vs2008 x32 is messed up like my vs2010 x32 option.. even though it says x32 it keeps compiling in x64 for some stupid reason.. and reinstalling didnt help me.. If you want I can compile it and see.

triumphost 120 Posting Whiz

TBH, I dont know what "This application has failed to start because the application configuration is incorrect" has to do with statically linking the project.. I can tell you that this happens to me a shitload of times.. especially when using VS2010 x64 omg.. must be the worst compiler. Usually when I get that error, I get an option to press details and stuff and when pressed it shows kernel32.dll and some weird AMDx64 crap... Just compile it as x86 or x32.. sometimes in the VS2010 x64 compiler, even when you choose x32, it still doesnt work.

Solution:
Compile it with VS2008 and choose x32 next to the debug/release option.. It will work for sure. Well at least that worked for me.

triumphost 120 Posting Whiz
From Windows.h
PlaySound("C:/SOUNDS/NAME.WAV", NULL, SND_ASYNC);

#pragma comment(lib, "winmm")
PlaySound(TEXT("IOWNU.wav"), NULL, SND_FILENAME);
wave.cc
#include <iostream>
#include <limits>
#include <string>
#include <windows.h>

void play_wave_resource( std::string resname, bool is_loop ) {
  HANDLE hfound, hsound;
  LPVOID data;

  hfound = FindResource( NULL, resname.c_str(), "WAVE" );
  if (hfound != 0) {

    hsound = LoadResource( NULL, (HRSRC)hfound );
    if (hsound != 0) {
      data = LockResource( hsound );

      if (data != NULL) sndPlaySound(
        (char *)data,
        SND_ASYNC | SND_MEMORY | (is_loop ? SND_LOOP : 0)
        );

      UnlockResource( hsound );
      }

    }
  FreeResource( hfound );
  }

void stop_wave_sound() {
  sndPlaySound( NULL, 0 );
  }

int main() {
  using namespace std;

  play_wave_resource( "one", true );

  cout << "Press ENTER";
  cin.ignore( numeric_limits<streamsize>::max(), '\n' );

  stop_wave_sound();

  return EXIT_SUCCESS;
  }


res.rc
one WAVE "c:\\WINDOWS\\Media\\notify.wav"


Makefile
	
wave: wave.cc res.o
	g++ -o wave wave.cc res.o -lwinmm

res.o: res.rc
	windres -o res.o res.rc

Search google.. there are tons of examples..

One way that I've done it before was to use a resource and just access the resource OR extract it then play it.. when its done playing you can delete it.. I prefer to extract since for me its easier.. but you can easily just aswell play it directly from the resource.

triumphost 120 Posting Whiz

First off your missing the second */.. Try the below code.

#if 0
  if ( operatorMap[ops].first && !operatorMap[ops].second.first )
  {
    /* Example: /path/SINimage.mhd */
    outputFileName = path + ops + name + ext;
#endif
triumphost 120 Posting Whiz

Hmm I dont know any GOOD alternatives to spy++ off the top of my head.. I'd have to search that up.. as for everything working except post message, This can possible be because of the theme. Windows 7 has many different themes + aero + the taskbar properties.
I do know microsoft had some hotfix/patch so that homepremium would have xp emulation but I cant find it :S

Post Message and SendMessage works as long as the program is accepting it. If its being posted to the window itself rather than the message queue then it wont register clicks. The Window itself probably only registers minimize, maximize and close.

Basically to see if post message/send message is working, try sending a message or posting a message like WM_CLOSE or ShowWindow(handle, SW_HIDE) that way you know for sure the handle hasnt change and you know for sure the window is receiving messages. But there is no way that I personally know of to check if the window's message queue is accepting messages. (well without hooking of course)

That being said, send a WM_CLOSE or some message like minimize or something and see what happens.. if it works then the window itself is getting messages. Also are you posting the clicks to a specific location in the window? maybe a specific co-ordinate? or are you fully relying on it to find the pixel then click it? Because pixel's on every computer will be different unless it has a …

triumphost 120 Posting Whiz

Please For god sake someone edit his thread and put code tags... I cant read a thing.. Your problem is the GOTO... You shouldn't use that as the stream is still full and wasn't cleared (side effect of using goto).. Try to make three functions and call them instead.

Again I will say: PLEASE USE CODE TAGS... For this reason, I didn't read through the whole thing just because of code tags.. u hurt my eyes without it.

Anyway. Get rid of the Goto test3 and instead do:

#include .....etc......

void test1();                       //These are all called function-prototypes.. look it up.
void test2();                       //They also don't have to be void.. they can return an int, return true or false.. whatever u need.
void test3();                       //Again Next time PLEASE USE CODE TAGS FOR A FASTER + BETTER RESPONSE!!

int main()
{
   test1();                       //This is how u call the function.. meaning it will do this then it will do test2, then test3..
   test2();
   test3();
   return 0;                      
}

void test1()
{
  //do stuff here
}

void test2()
{
  //do test 2 code here..
}

void test3()
{
  //something here too..
}

Your code is below.. next time use code tags. Note: I didnt change a thing.. I just put it in tags thats all.

#include <iostream>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;

int main()

{

int number, guess;
number = rand () % 5+1;



for(int i=0;i<3;i++)// first level

{
cout <<"Please enter your guess: ";
cin>>guess;

/* …
triumphost 120 Posting Whiz

try and see if you can get the handle right before sending the message and output and error if the handle returns NULL... As far as I know, the window name disappears when you run it in fullscreen mode and that may be the cause of send message failure. I had that problem and instead had to Check constantly if the process was running in a separate thread. You can always do an EnumWindows to find it instead.

SendMessage does work on HomePremium as I have used it before on that OS.. but I believe strongly that its losing the handle when it maximizes (possible handle change?) or it cant find the window name since the title bar disappears.. Try alt+Tab and open spy++ and check.

triumphost 120 Posting Whiz

mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0);
SetCursorPos(x,y);
mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0);

That should drag the item wherever.. as it sends mousedown then moves it, then sends mouse up..

You can always try:

SendMessage(hwndDC,WM_LBUTTONDOWN,UL.x + x,UL.y + y);

That will move the cursor in reference to the client.. Check out the other post that I have replied on.. and u will see where the UL comes from aka Upper Left..

Use GetRect, SetRect, ClipCursor (Not Necessary), then finally u set mouse position relative to either the top left of the client, bottom left, top right, bottom right.. either one will work.. That way the cursor will stay inside the client.. especially if u clip it.. which i must say again, is not necessary. No NEED to clip it.

Example from my antivirus installer:

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


#pragma comment(lib, "advapi32.lib")
#include <windows.h>
#include <tlhelp32.h>
#include <iostream>
#include <conio.h>
#include <string.h>
#include <sstream>
#include <cstdlib>
#include <winable.h>
#include <Scar++.h>

using namespace std;

int main()
{
Scar setup;
HWND avast;
avast = FindWindow(0, "avast! Internet Security");
BlockInput(true);
if (avast != 0)
{
	cout << "Found the Avast Window!" << endl;
	ShowWindow(avast, SW_RESTORE);
	SetForegroundWindow(avast);
	MoveWindow(avast, 0, 0, 500, 500, true);
	Sleep(3000);
	
    RECT rcClient;                 // client area rectangle 
    POINT ptClientUL;              // client upper left corner 
    POINT ptClientLR;              // client lower right corner 

    POINT ptClientUR;              // client upper right corner 
    POINT ptClientLL;              // client lower left corner

SetCursorPos(ptClientUR.x - 50, …
triumphost 120 Posting Whiz

Hmm this is odd that Im the only one answer all your threads as I've ran into the same problems for some reason :S I've also been programming for a game.. A bot really.. that Automates stuff, Finds colours on the screen and clicks it.. etc.. The solution is below of course.

RECT rcClient;
			 GetClientRect(hQuery, &rcClient);
			 POINT ptClientUL;              // client upper left corner 
			 POINT ptClientLR;              // client lower right corner 

			 POINT ptClientUR;              // client upper right corner 
			 POINT ptClientLL;              // client lower left corner

            ptClientUR.x = rcClient.right; 
            ptClientUR.y = rcClient.top;
            ptClientLL.x = rcClient.left - 1; 
            ptClientLL.y = rcClient.bottom - 1;

	    ptClientUL.x = rcClient.left; 
            ptClientUL.y = rcClient.top;
            ptClientLR.x = rcClient.right + 1; 
            ptClientLR.y = rcClient.bottom + 1;
        
            ClientToScreen(hQuery, &ptClientUL); 
            ClientToScreen(hQuery, &ptClientLR);
            ClientToScreen(hQuery, &ptClientUR); 
            ClientToScreen(hQuery, &ptClientLL);
            
            //Clips the cursor to the specified client window..
            SetRect(&rcClient, ptClientUL.x, ptClientUL.y,
            ptClientLR.x, ptClientLR.y);                       //From Upper Left to the Lower right..
			ClipCursor(&rcClient);
			SetCursorPos(ptClientUR.x - 119 , ptClientUR.y + 38);   //Set CursorPos from client size. Should be easy to figure out..
			POINT cursorPos;
			GetCursorPos(&cursorPos);
			int h = (int) cursorPos.x;
			int k = (int) cursorPos.y;
			Sleep(500);
			mouse_event(MOUSEEVENTF_LEFTDOWN, h, k, 0, 0);   //Click the mouse at the position set.. :) U have a messagebox here
			mouse_event(MOUSEEVENTF_LEFTUP, h, k, 0, 0);
			ClipCursor(NULL);
			Sleep(500);
triumphost 120 Posting Whiz
enum {F9_KEYID = 1, F10_KEYID = 2} ;
RegisterHotKey(0, F9_KEYID, MOD_NOREPEAT, VK_F9);   //Please note that for Windows-7/Vista, MOD_NOREPEAT doesnt exist.. use 0x4000 instead
RegisterHotKey(0, F10_KEYID, MOD_NOREPEAT, VK_F10); //I used 0x79 for F10 instead of VK_F10.. they both work but I feel better using the hex

PeekMessage(&msg, 0, 0, 0, 0x0001);
TranslateMessage(&msg);
switch(msg.message)
  {
	case WM_HOTKEY:
	if(msg.wParam == F9_KEYID)
	{
		MessageBox::Show("F9 Pressed");
        }
	else if(msg.wParam == F10_KEYID)
	{
		MessageBox::Show("F10 Pressed");
	}
  }

I had the same problem with the loop aswell and found the peek message aswell... unfortunately no where on google could tell me how to register multiple messages in the same thread.. The solution above though worked quite well!

triumphost 120 Posting Whiz

Background worker is the solution to multithreading without afx and boost..
http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx

triumphost 120 Posting Whiz

wow.. wtf?? I just was about to do this for vectors in calculus and came across this.. and this: http://www.codeproject.com/KB/cs/graphcalc.aspx

But that looks like spanish to me.. Simply dont understand a single thing there..especially as it uses case "String":

triumphost 120 Posting Whiz

first off.. it doesnt only do capitals.. Iunno what ur talking about... its getasynckeystate which gets key presses.

try isupperchar()

triumphost 120 Posting Whiz

You can use System("CLS"); to clear the screen.

And WaltP why would "you" put negative rep for me typing "u" instead of "You". If its a spelling class then fine.. whatever.

WaltP commented: Because U is not proper English and the rules state so -- and "U" bugs me no end! Don't be lazy... ;-) +15
triumphost 120 Posting Whiz

Try something like:

This is just a start for your code and a few fixes like letting them enter the number.. But you should do something like:
Make a MULTI-DIMENSIONAL DYNAMIC ARRAY
These represent tables.. Make it x by x. Print the array to the screen. that way how ever many digits they enter, it will do x across and x down.

PLEASE NOTE: I left the input as Integers.. so it will only output a Number.. you can figure out how to change it and make it multidimensional aswell.

/*This program will ask the user for a positive integer no greater than 15 and
will display a square on the screen using the character "X" with a length the
size of the number entered.*/

#include <iostream>
#include <new>
using namespace std;

int main ()
{
  int i,n;
  int * p;
  cout << "Type A Number: ";
  cin >> number;
  p= new (nothrow) int[number];
  if (p == 0)
    cout << "Error: memory could not be allocated";
  else
  {
    for (n=0; n<i; n++)
    {
      cout<<p[n] + "\n";
    }
    delete[] p;
  }
  return 0;
}

P.S. Your gunna need more than one LOOP.. This should almost work.. u can do the rest.

Example:

int number;
int number2;
int number3;
cout<<"bldfgsgds ";
cin>>number;
//U MUST DO SOME CHECKS HERE TO MAKE SURE IT IS A NUMBER!!!!!!!!!!!
number2 = number;
number3 = number;
number = 1;
do{
   for(number=1;number2;number++)
   {
        cout<<"X";
   }
   cout<<"\n";
   number++;
}while(number < number2);
triumphost 120 Posting Whiz

would you not do:

void setMode(VideoOutPutMode mode)
{
   mode_ = mode;
}

//And then

SetMode(VideoOutputMode::VO_MODE_LOCAL);      //I THINK thats how you call it.
triumphost 120 Posting Whiz

SendMessage(FindWindow("WindowClass", "windowname"), WM_CLOSE, 0);

Or PostMessage which does not wait to return.

triumphost 120 Posting Whiz

I have no idea what might be wrong with your code, to be honest.

Try looking into http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx the Process class. I think you'll find there's quite a bit there that will help you, and you won't have to mix the managed and unmanaged code as much.

Aww damn :( Thanks for being honest though and taking the time to reply.
I looked at your link but its not exactly what I wanted to do. Didnt wanna start a process..

Basically what I tried to do above was find a window by partial title. and ancient dragon told me to Enum all windows..
I tried that and came up with the following below but couldnt find out how to let the user enter the name of the window or how to find out if the window is found.. Below code is compilable and works but I cant let the user choose the name of the window thats y i made the post above to try and alter the following which failed bad and obviously if u dont know how to do what im trying to do then Im badly off..

#pragma once
#pragma comment(lib, "advapi32.lib")
#pragma comment(lib, "user32.lib")

#include <Windows.h>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

namespace Hmm {

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

	delegate bool WindowFinder(HWND hwnd, LPARAM lParam);


	/// <summary>
	/// Summary for …
triumphost 120 Posting Whiz

Depending on what you are actually going to do with the .NET code, you can relax the compilation from /CLR:pure setting to just /CLR (within the project propeties) and see if the two will play along.

The unmanaged code is not called CLR, by the way. The CLR is the runtime for the managed code. I'd probably call the first part Win32 API and/or native code.

Well its just a form and basically All I want to do is take the text from a textbox, pass it to the FindWindowStart and then display a messagebox if its found.

I've been trying this for a couple days now but it seems impossible..

I've just came up with this a few minutes ago but it still fails so badly :(

delegate bool WindowFinder(HWND hwnd, LPARAM lParam);       //MY ATTEMPT AT THE DELEGATE

struct FindWindowData{
    FindWindowData(TCHAR const * windowTitle)               //The Struct
        : WindowTitle(windowTitle)
        , ResultHandle(0)
    {}

    std::basic_string<TCHAR> WindowTitle;
    HWND ResultHandle;
};

	ref class WndFind                                            //The Class
	{
	public:
		[DllImport("user32")]
		static int EnumWindows(WindowFinder^ x, LPARAM lParam);

		static void Main()                                               //THIS IS WHERE IM LOST!
		{
			WndFind^ New = gcnew WndFind;
			WindowFinder^ WndFoundCallBack = gcnew WindowFinder(&WndFind::FoundWnd);
			EnumWindows(WndFoundCallBack, 0);
		}

		static bool FoundWnd(HWND hwnd, LPARAM lParam)                      //THE CALLBACK
		{
		    FindWindowData * p = reinterpret_cast<FindWindowData*>(LongToPtr(lParam));
			if(!p) {
        // Finish enumerating we received an invalid parameter
			return false;
			}

			int length = GetWindowTextLength(hwnd) + 1;
			if(length > 0) {
			std::vector<TCHAR> buffer(std::size_t( length), 0);      
			if(GetWindowText(hwnd, &buffer[0], length)) {
                    // Comparing the string - If you want to …
triumphost 120 Posting Whiz

Well I thought the title explains it? And the two different kinds of code..

I have a the first set of code which works for CONSOLE apps. I want to implement that Code into my .Net application (the second set).

The second set of code is my attempt at doing it but failing. There is no definitive problem other than it wont work because it isn't C++ managed code.

I have tried Delegate Callback but it didnt work and most likely im doing it wrong.

So my question is: How do I implement the first set of code(unmanaged) into the second set(managed)?

triumphost 120 Posting Whiz

*Sigh* six hours straight... not a single person knows how :S

I tried delegate BOOL FindWindowImpl(HWND hWnd, LPARAM lParam);
but I still cant get it to run :S..

triumphost 120 Posting Whiz

I have the following code which finds a window by a partial name given..
I've tested it and it doesnt work in Dev c++ but it definitely works in visual studio 2008.. So I decided to make a form with nothing on it and implement this code to see if it will work.. The code is below and below that is my attempt.

#include <Windows.h>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

struct FindWindowData{
    FindWindowData(TCHAR const * windowTitle)
        : WindowTitle(windowTitle)
        , ResultHandle(0)
    {}

    std::basic_string<TCHAR> WindowTitle;
    HWND ResultHandle;
};

BOOL CALLBACK FindWindowImpl(HWND hWnd, LPARAM lParam){
    FindWindowData * p = reinterpret_cast<FindWindowData*>(LongToPtr(lParam));
    if(!p) {
        // Finish enumerating we received an invalid parameter
        return FALSE;
    }

    int length = GetWindowTextLength(hWnd) + 1;
    if(length > 0) {
        std::vector<TCHAR> buffer(std::size_t( length), 0);      
        if(GetWindowText(hWnd, &buffer[0], length)) {
                    // Comparing the string - If you want to add some features you can do it here
            if(_strnicmp(&buffer[0], p->WindowTitle.c_str(), min(buffer.size(), p->WindowTitle.size())) == 0){
                p->ResultHandle = hWnd;
                // Finish enumerating we found what we need
                return FALSE;
            }
        }
    }
    // Continue enumerating
    return TRUE;
}

// Returns the window handle when found if it returns 0 GetLastError() will return more information
HWND FindWindowStart(TCHAR const * windowTitle){

    if(!windowTitle){
        SetLastError(ERROR_INVALID_PARAMETER);
        return 0;
    }

    FindWindowData data(windowTitle);
    if( !EnumWindows(FindWindowImpl, PtrToLong(&data)) && data.ResultHandle != 0){
        SetLastError(ERROR_SUCCESS);
        return data.ResultHandle;
    }

    // Return ERROR_FILE_NOT_FOUND in GetLastError
    SetLastError(ERROR_FILE_NOT_FOUND);
    return 0;
}

int _tmain(int argc, _TCHAR* argv[])
{
    std::cout << "HWND: " << FindWindowStart(TEXT("foobar "));
    std::cout << "GetLastError() = " << GetLastError() << std::endl;
    return …
triumphost 120 Posting Whiz

any video file like .avi or .swf file etc..

See Here for an AVI player:
http://www.daniweb.com/software-development/cpp/code/216358

triumphost 120 Posting Whiz

Hey if you want a timer, there is no way u can do it like that especially for input.. that is because cin waits indefinitely and no matter what timer u put, it will keep waiting and then return the time after it has received input..

I believe this would be of relevance to you... NARUE has written this very nicely for me in the past! =) I have learned threading because of it.. and that is the only way to put a timer on cin.. Its to have it run in a separate thread and when the thread timesout, so will cin..

Following Code was written by Narue: :)

#include <windows.h>

namespace jsw {
    namespace threading {
        class auto_event {
        public:
            auto_event(): _event(CreateEvent(0, false, false, 0)) {}

            BOOL wait(DWORD timeout = 1) const
            {
                return WaitForSingleObject(_event, timeout) == WAIT_OBJECT_0;
            }

            BOOL set() { return SetEvent(_event); }
        private:
            HANDLE _event;
        };

        class thread {
        public:
            static thread start(
                LPTHREAD_START_ROUTINE fn, LPVOID args = 0, 
                DWORD state = 0, DWORD timeout = 5000)
            {
                return thread(CreateThread(0, 0, fn, args, state, 0), timeout);
            }

            static void sleep(DWORD milliseconds) { Sleep(milliseconds); }
            static void exit(DWORD exitCode) { ExitThread(exitCode); }
        public:
            thread(HANDLE thread, DWORD timeout): _thread(thread), _timeout(timeout) {}
            ~thread() { CloseHandle(_thread); }

            DWORD exit_code() const
            {
                DWORD exitCode = NO_ERROR;

                GetExitCodeThread(_thread, &exitCode);

                return exitCode;
            }

            HANDLE handle() const { return _thread; }
            BOOL is_alive() const { return exit_code() == STILL_ACTIVE; }
            DWORD join() { return WaitForSingleObject(_thread, _timeout); }
            DWORD suspend() { …
triumphost 120 Posting Whiz

Hey thanks.. I just figured it out -__- But u kinda helped me alot.. Iunno why it didnt work earlier when I changed lParam to wParam but it works now with peek message whereas it doesn't work with GetMessage. Anyway THANK YOU!! I will rep u. Especially as you are the only one who helped me :)

Btw it was done like this:

PeekMessage(&msg, 0, 0, 0, 0x0001);
				TranslateMessage(&msg);
				switch(msg.message)
				{
					case WM_HOTKEY:
						if(msg.wParam == F9_KEYID)
						{
							MessageBox::Show("F9 Pressed");
						}
						else if(msg.wParam == F10_KEYID)
						{
							MessageBox::Show("F10 Pressed");
						}
				}
triumphost 120 Posting Whiz

^ Ummm wth? are u trying to get your post count up?? sstream is stringstream... you could easily have searched that up.. and you do know c++ and c are somewhat interchangeable right? U can import and export functions between them... It doesnt matter if it isnt pure/native c++

WaltP commented: please -- U is not a word. You s a word. This is not a chat room. -3
triumphost 120 Posting Whiz

You want something like

if(!isdigit(num1 || num2)){
   cout<<"You entered a character that is not a digit\n";
   Welcomscreen();
}

And for C++.Net you do:

if(!Char::IsDigit(e->KeyChar) && e->KeyChar != 0x08)//The 0x08 is the backspace key.. you might wanna add 0x0D which is the Enter button.
{
	e->Handled = true;
}
triumphost 120 Posting Whiz

Are u allowed to set a de-reference pointer to the value of danikaTotalData and divide that by 3??

triumphost 120 Posting Whiz

This would depend on the kind of video... A flash video? HTML 5?? What Codecs?? AVI? WMV? MP4? What kind.. There is no specific code to play every single type of video that exists..

triumphost 120 Posting Whiz

You are missing a bracket for void EmployeeClass::Addsomethingup()

Add a } at the end of the code above.. should be line 127.

as for this:

cout << "%%%% Total <strong class="<<"highlight"<<">Overtime</strong> Hours......... ="

Not sure why you did that.. You see where it shows highlight as a string? U dont have to put << you can just do:

cout << "%%%% Total <strong class=highlight>Overtime</strong> Hours......... =" << iTotal_OvertimeHours << endl;

This is because that entire part of the line is a string..

You CANNOT do: for (int i = 0; i << "integral"; ++i ) That is the error it is telling you about Const char[9]

You are declaring i as an integer which is equal to 0 and then telling it that while i is less than a string do the following and then increase i for everytime it loops through..

That is impossible. For an integer to be less than a string..

Not exactly sure how many times you want to loop through that procedure but you can do this:

for (int i = 0; i < 10; ++i )  //<--- Notice that now its the correct syntax stating that while I is less than 10, do...

//or u can do

for (int i = 0; i < n; ++i )  //<--- where "n" is an integer that has a value >= 0.
triumphost 120 Posting Whiz

The second argument to RegisterHotKey() is the id of the hot key. If multiple WM_HOTKEY messages are received by the same thread, you need to examine the lParam of the message for the id of the hot key that was pressed.

enum { F9_KEYID = 1, F10_KEYID = 2 } ;
RegisterHotKey( 0, F9_KEYID, MOD_NOREPEAT, VK_F9 ) ;
RegisterHotKey( 0, F10_KEYID, MOD_NOREPEAT, VK_F10 ) ;

MSG msg ;
while( GetMessage( &msg, 0, 0, 0) )
{
    if(msg.message == WM_HOTKEY)
    {
        switch( HIWORD(msg.lParam) )
        {
            case F9_KEYID : MessageBox::Show("F9 was pressed") ; break ;
            case F10_KEYID : MessageBox::Show("F10 was pressed") ; break ;
            default: MessageBox::Show("some other hot key was pressed") ;
        }
    }
    // ...
}

Tip: avoid using magic numbers in your code.

Hmm what do u mean avoid using magic numbers?? do u mean the 0x78 and 0x79??

And I just tried what u posted above, that doesnt work.. it always gives me the default "some other hot key was pressed".

triumphost 120 Posting Whiz

Use the code he told u in the first post. Though i dont see why anyone should call you horrible.

System("taskkill /f /im program.exe");

What I wanna know is why are you trying to hide it??

triumphost 120 Posting Whiz

That is huge!! Try freeing up memory from before? Any memory you allocated before, Use it and then free it! Cuz if it isn't free, sooner or later your gunna get what u have above...

Try allocating a smaller amount of space. Do you really need that much?

triumphost 120 Posting Whiz

Wow... I dont mean to criticize but damn!! u have so many errors.. I suggest reading a tutorial on function-prototypes, classes and functions.. And maybe some syntax's. I tried to compile, I fixed quite a lot but there is no way in hell am I gunna fix all..

First off its bad practice to do #include ... inside the main function.. why would u also put using namespace std inside the main function?

Secondly you cannot declare a function inside of another one.. If you need to do this, do:

void myfunction();  //<--- this is declaring the function as a function-prototype..

int main()     //Secondly I noticed u had int main(); ... you cannot do that. u have to remove the semi-colon.
{
}
void myfunction()
{
//Do stuff here
}

"highlight" is an undeclared variable which you have called before declaring it.

Also your missing the <<higlight<< ... you were missing the << operands...
For this line:

cout << "%%%% Total <strong class="<<highlight<<">Overtime</strong> Hours......... =" << iTotal_OvertimeHours << endl;

numEmployees is also undeclared..
Another << missing from the highlight code.

cout << "<strong class="highlight">Overtime</strong> <strong class="highlight">Pay</strong> Amout......... = " << overtime_extra << endl;

should be

cout << "<strong class="<<highlight<<">Overtime</strong> <strong class="highlight">Pay</strong> Amout......... = " << overtime_extra << endl;

You have a LOT! of brackets missing you did not close the class with a } bracket before the };

Why is your class declared IN main??


anyway this …

Ancient Dragon commented: very helpful +36
triumphost 120 Posting Whiz

U want dynamic memory allocation? OR U can set a pointer to reference the value of the array. Or a pointer to the array.. whatever your choice.


Lets the user choose the size of the array.
http://cplusplus.com/doc/tutorial/dynamic/

triumphost 120 Posting Whiz

Can someone help me with this? I No matter what I do, when I press F9, the message box pops up showing F9, But when I press F10, the message box for F9 pops up.. Is it because MSG msg and MSG msg2 are the same?? How do I fix this, Im not very good at it :S

Basically I want to tell which Global hotkey was pressed.

if (RegisterHotKey(NULL,1,0x4000,0x78))  //F9 Key
		{
			MessageBox::Show("SmartChat -- Registered HotKey: F9");
		}
	 if (RegisterHotKey(NULL,2,0x4000,0x79))  //F10 Key
		{
			MessageBox::Show("Exit -- Registered Hotkey: F10");
		}
				MSG msg = {0};
				MSG msg2 = {0};
				while (GetMessage(&msg, NULL, 0, 0) != 0)
				{
					if(msg.message == WM_HOTKEY)
					{
						MessageBox::Show("F9");
					}
					break;
				}
				while (GetMessage(&msg2, NULL, 0, 0) != 0)
				{
					if(msg.message == WM_HOTKEY)
					{
						MessageBox::Show("F10");
					}
					break;
				}

P.S. I had it working when I put them hotkeys and messages in two separate threads.. that way one thread monitors one key, the next monitors another key.. but it lags me a lot more than when I only had 1 thread. Current program has 4 threads (BackgroundWorkers) and it lags me so bad! So Im trying to reduce it by putting 99% of the code in one thread.

triumphost 120 Posting Whiz

lol wow thats a lot of questions.. Umm I use Visual Studio 2010 x64, I have Visual Studio 2008 aswell.

I dont think CodeBlocks for windows is 64 bit. And other than the VS 2010 and 2008, I dont know of any other 64 bit compilers :S

Yes PostMessage & SendMessage will work as Im using it atm to Send Messages from Threads. So I guarantee those functions will work.

I Have also taken a Program I wrote in 32bit vs2010 and compiled it in Vs2010 x64.. There is one problem though, If your importing specific DLL's, Some people say some of them will give trouble. Other than that, *I* have been successful 100% compiling my programs.

triumphost 120 Posting Whiz

Install a 64 bit compiler on the 32 bit computer, at the top where it shows debug and release, there are options like x32 x86 x64.. choose x64 a for pure 64 bit version of the program

triumphost 120 Posting Whiz

Im just learning classes :( But by sharing object data I will assume u mean something like a global variable.. The value from a textbox can be shared throughout the entire program.. is that what u want/mean?

triumphost 120 Posting Whiz

OMG! Genius! above, I solved it! Got it to constantly check if a window is open, and I got the thread to check for GLOBAL HOTKEYS :)

Works perfectly! U sir need an award!

private: System::Void backgroundWorker1_DoWork(System::Object^ sender, System::ComponentModel::DoWorkEventArgs^ e)
	{ 
		if (RegisterHotKey(NULL,1,MOD_ALT,0x53))  //0x53 is 's'
		{
			MessageBox::Show("Registered HotKey - ALT + S");
		}
		MSG msg = {0};
		while (GetMessage(&msg, NULL, 0, 0) == 1)
		{
			if (msg.message == WM_HOTKEY)
			{
				MessageBox::Show(":)");
			}
			HWND Smart = FindWindowW(0, L"FireFox");
			if (Smart = NULL)
			{
				MessageBox::Show("FireFox Not Running -- Terminating Program");
				Form1::Close();
			}
		}
	}

Also had to do this in Form1_Load: backgroundWorker1->RunWorkerAsync();

triumphost 120 Posting Whiz

Hi All, Im new to threading and forms and really bad at API. Jonsca pointed me to Backgroundworker because my original problem was to constantly check if a window is open. If it is open, terminate my program. I failed at that so I tried Hotkeys.

The problem is:

My background worker doesnt constantly run in the background?? Well it doesnt seem to.
What the form below does is:

Makes a form, Initializes backgroundworker. In the background worker, it is SUPPOSED to constantly check if a Hotkey is pressed. The hotkey is supposed to work systemwide.. so even if the form is not in focus, it should still detect it.

I've tried it with WndProc but with no success and I'm not a pro at API or Threading.

Can someone shed some insight as to what Im doing wrong?

P.S. I removed quite a lot of code to make it faster for someone helping to read through.

#pragma once
#pragma comment(lib, "advapi32.lib")
#pragma comment(lib, "user32.lib")
#include <windows.h>
#include <tlhelp32.h>
#include <iostream>
#include <conio.h>
#include <sstream>
#include <cstdlib>
#include "Query.h"

#using<system.dll>

namespace SmartChat {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
	using namespace System::Security::Permissions;
	using namespace System::Runtime::InteropServices;
	using namespace System::Threading;

	public ref class Form1 : public System::Windows::Forms::Form
	{
	private:
		System::ComponentModel::BackgroundWorker^ backgroundWorker1;

	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
			InitializeBackgoundWorker();
		}

	private:
   // Set up the BackgroundWorker object …
triumphost 120 Posting Whiz

try this:

if(hwnDC != 0)   //<---- Check to see if it is open.
{
   MessageBox(hwnDC, "The game window is still open", MB_OK|MB_ICONIFORMATION);
}

as for checking to see if its closed, u might have to do a check for the process. If the process isnt running, the window is closed. Why? Because sometimes it takes time for the system to realize that a program has stopped.

You can try doing Sleep(10000) and then check to see if its open and see if that helps.. But I dont think Sleeping to check is a good idea because it can always take more time or less time.

triumphost 120 Posting Whiz
MOD_NOREPEAT
0x4000

Changes the hotkey behavior so that the keyboard auto-repeat does not yield multiple hotkey notifications.

    Windows Vista and Windows XP/2000:  This flag is not supported.

Straight from microsoft's site..

As for compiling it for all platforms, I've had this problem in vs 2010.. Try using vs 2008 and select Win32 at the top.

triumphost 120 Posting Whiz

The StringF in Form1_Load() is a local variable, which masks the "global" (really it's a member of the Form1 class) variable. Remove the System::String ^ portion off of the one in Form1_Load and it should be all set.

Wow it worked thanks!! Although I tried that before and got some weird error.. Seems you may just be really good luck!

First post solved today :)


Also do u happen to know how to make my application constantly check if another app is open? Because I tried to add a loop but then my app stops responding. Maybe I added it in the wrong place :S

triumphost 120 Posting Whiz

The code below is from my form.. I declared a string GLOBALLY.. Then upon FormLoad, It inserts values for the string... When I do button click, the string is blank.. Why is it blank? Shouldnt the Values from FormLoad Event be in it? :

public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}
	public:
		System::String^ StringF;     //<-- Tried to declare my string globally..

and then I did:

public: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
		Form1::Visible = false;
		Query ^ F = gcnew Query();   //<-- Form 2 for input.
		F->ShowDialog();
		System::String^ StringF = F->textBox1->Text;  //<-- Set StringF as Value from text box!!!
                MessageBox::Show(StringF);  //<---- Tells me the string has values :)
}

public: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
                   System::String^ AddStr = "FFox - " + StringF;
                   IntPtr ptr2 = System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(AddStr);
				 HWND FFox = FindWindow(0, (LPCSTR)ptr2.ToPointer());
				 if(FFox == NULL)
				 {
					 MessageBox::Show("Cant Find FF :(");
					 MessageBox::Show(StringF);     //<--- Tells me the string is blank!!  WHY?!?!

				 }