A few questions about C++ ( Noob questsion ) menu

User Tag List

Results 1 to 7 of 7
  1. #1
    Krillere's Avatar Contributor
    Reputation
    112
    Join Date
    Nov 2007
    Posts
    668
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A few questions about C++ ( Noob questsion )

    Hello. Im new to C++ and i have a few problems with some code. Im using Visual Studio 2008.

    1. I want to SendMessage to send keys to a window, but i cant seem to get the Window Handle to work. Heres the code im using atm.

    Code:
    #include <windows.h>
    
    int main () {
        HWND hWnd;
       hWnd = FindWindow(NULL, "Lommeregner");
    
        SendMessage(hWnd, WM_KEYDOWN, VK_NUMPAD1, 0);
        SendMessage(hWnd, WM_KEYUP, VK_NUMPAD1, 0);
    }
    I dont know whats wrong, i've been Googling and Googling but havent found anything.

    2. I'm using a ComboBox, normally i would read it like this:
    Code:
    if(ComboBox2->SelectedItem->ToString() == "1") {
    
    }
    else if () and so on.
    but i dont know what to write if they didnt choose anything.
    Code:
    if(ComboBox2->SelectedItem->ToString() == "") {}
    Doesnt work.

    3. Threading in C# is easy, but how in the name of god do i use Threading in C++? I googled it and i found out that i need to import some kind of home made libary or something because Threading is not pre-installed in C++ or something like that. Any help would be awesome!

    Hope you understand theese questions.. Thanks!

    - Krillere

    A few questions about C++ ( Noob questsion )
  2. #2
    Krillere's Avatar Contributor
    Reputation
    112
    Join Date
    Nov 2007
    Posts
    668
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for all the nice feedback. No wait!

  3. #3
    Xarg0's Avatar Member
    Reputation
    61
    Join Date
    Jan 2008
    Posts
    389
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Regarding your first question I'd advise you to check the apis return values and if they failed you should check the error code.

    How to solve your second problem depends on the ComboBox Class, if ToString() returns a cstring you'll have to use strcmp() to find out if it equals the string you're looking for, if it's the string class from the c++ libs it should've overloaded the == operator.

    About your third question, you can use the windows threading api functions or MFC Classes to work with threads, the boost c++ library also provides a threading lib.
    I hacked 127.0.0.1

  4. #4
    meb111's Avatar Member
    Reputation
    1
    Join Date
    Sep 2008
    Posts
    8
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Krillere View Post
    1. I want to SendMessage to send keys to a window, but i cant seem to get the Window Handle to work. Heres the code im using atm.

    Code:
    #include <windows.h>
    
    int main () {
        HWND hWnd;
       hWnd = FindWindow(NULL, "Lommeregner");
    
        SendMessage(hWnd, WM_KEYDOWN, VK_NUMPAD1, 0);
        SendMessage(hWnd, WM_KEYUP, VK_NUMPAD1, 0);
    }
    Okay I Think your problem is that you are using a string instead of an LPCWSTR.... So, to fix this when you are initializing you hWnd, put:

    Code:
    HWND hWnd;
    hWnd = FindWindow(NULL, _T("Lommeregner"));
    the _T() function converts char array to LPCWSTR. I hope this helps!

  5. #5
    Powerking89670's Avatar Member
    Reputation
    3
    Join Date
    Jun 2009
    Posts
    7
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could also use Qt's QThread class to do your threading. It's nice and easy, and cross platform too.

    http://www.qtsoftware.com/products/

    EX
    Code:
    #include <QThread>
    
    class MyClass : public QThread
    {
    
    private:
        virutal void run();
    
    };
    
    void MyClass::run()
    {
       //my threaded code
    }
    
    int main(int argc, char* argv[])
    {
       MyClass threadA = new MyClass();
       threadA.start();
       MyClass threadB = new MyClass();
       threadB.start();
     
       while(//I decide to put something here)
       {
          //do something useful.
       }
    }
    Last edited by Powerking89670; 06-18-2009 at 11:32 PM.

  6. #6
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1358
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by meb111 View Post
    Okay I Think your problem is that you are using a string instead of an LPCWSTR.... So, to fix this when you are initializing you hWnd, put:

    Code:
    HWND hWnd;
    hWnd = FindWindow(NULL, _T("Lommeregner"));
    the _T() function converts char array to LPCWSTR. I hope this helps!

    Incorrect.

    The _T() macro (which is an alias for the TEXT() macro) expands to widen a string if building for unicode, or leave it as is otherwise. It's used so you can correctly support both character set compiler flags.

    It simply inserts a 'L' if Unicode is enabled, or does nothing otherwise.

  7. #7
    Krillere's Avatar Contributor
    Reputation
    112
    Join Date
    Nov 2007
    Posts
    668
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yay. Finally a way to use threading! I found out how to use the Window Handle thing. I just use Dev-C++ instead of VS, that solved it ^^

Similar Threads

  1. A few Questions about Botting Diablo 3 and such. (Bit of a noob)
    By FireFrostArcane in forum Diablo 3 Bots Questions & Requests
    Replies: 0
    Last Post: 11-08-2012, 09:15 PM
  2. question about a noob (me)
    By billcat in forum World of Warcraft General
    Replies: 2
    Last Post: 02-23-2008, 05:31 AM
  3. A few questions about model editing
    By Kelindel in forum WoW ME Questions and Requests
    Replies: 2
    Last Post: 01-01-2007, 11:23 PM
  4. A few questions about model editing
    By Kelindel in forum World of Warcraft General
    Replies: 0
    Last Post: 01-01-2007, 08:57 PM
  5. A few questions about WoW
    By colm in forum World of Warcraft General
    Replies: 2
    Last Post: 08-23-2006, 12:04 PM
All times are GMT -5. The time now is 01:28 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search