Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    zhaoyun333's Avatar
    Join Date
    Apr 2009
    Gender
    male
    Posts
    396
    Reputation
    11
    Thanks
    1,125

    Win32 Api Class [In Devolopment]

    Hey MPGH C++ Coders!

    I know Win32 API is really hard to get the hang of so I have been working a project that uses a class for the win32 api. What is win32 api? It is the stuff you use to make on of those fancy windows not those black console screens. Here is some exemplar code of how you will be able to use the class:

    Code:
    #include "menu.h"
    #include <stdio.h>
    
    int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, 
    				   LPSTR lpCmdLine, int nCmdShow){
    
    Menu testMenu(200,200,300,500,"rofl");
    testMenu.AddButton(25,25,200,25,"button");
    testMenu.Show(1);
    
    while(testMenu.Run()){
            if(testMenu.GetButton()==0)
    MessageBox(NULL,"buttonclicked","buttonclicked",MB_OK);
    }
    return 0;
    }
    [IMG]https://i344.photobucke*****m/albums/p349/zhaoyun3/test.jpg[/IMG]
    Last edited by zhaoyun333; 11-14-2009 at 06:59 AM.
    There are five possible operations for any army. If you can fight, fight; if you cannot fight, defend; if you cannot defend, flee; if you cannot flee, surrender; if you cannot surrender, die." - Sima Yi

  2. The Following 2 Users Say Thank You to zhaoyun333 For This Useful Post:

    Hell_Demon (11-14-2009),why06 (11-15-2009)

  3. #2
    Liz's Avatar
    Join Date
    Feb 2009
    Gender
    female
    Location
    179° 56′ 39.4″, +0° 2′ 46.2″, 7,940 ± 420 parsecs
    Posts
    37,181
    Reputation
    5621
    Thanks
    20,746
    My Mood
    Tired
    oh hai Zhaoyun, havent seen u in 4ever.

    If anyone claims to be me via any other source outside of MPGH private or visitor messages, IT'S NOT ME!
    They are trying to trick or scam you. Report them immediately and PM me here for verification.
    "Don’t confuse my personality with my attitude. My personality is who I am. My attitude depends on who you are." — Frank Ocean
    Moderator: 5/2009-10/2009 | GMod: 10/2009-10/2010 | Staff Administrator: 10/2010-Present
    I
    do not do requests via PM. Post in the appropriate section.
     
    Stupid/Pointless Private messages = SPAM, SPAM = BAN.

  4. #3
    zhaoyun333's Avatar
    Join Date
    Apr 2009
    Gender
    male
    Posts
    396
    Reputation
    11
    Thanks
    1,125
    yeah i know ive been elsewhere
    There are five possible operations for any army. If you can fight, fight; if you cannot fight, defend; if you cannot defend, flee; if you cannot flee, surrender; if you cannot surrender, die." - Sima Yi

  5. #4
    monkey32's_backup's Avatar
    Join Date
    Oct 2009
    Gender
    male
    Posts
    58
    Reputation
    10
    Thanks
    3
    ;D Could be helpful.

  6. #5
    zhaoyun333's Avatar
    Join Date
    Apr 2009
    Gender
    male
    Posts
    396
    Reputation
    11
    Thanks
    1,125
    Im sorry...COULD BE? Normally this code would take 200 lines.
    There are five possible operations for any army. If you can fight, fight; if you cannot fight, defend; if you cannot defend, flee; if you cannot flee, surrender; if you cannot surrender, die." - Sima Yi

  7. #6
    XGelite's Avatar
    Join Date
    Mar 2009
    Gender
    male
    Location
    Enter text here
    Posts
    1,344
    Reputation
    12
    Thanks
    276
    Quote Originally Posted by zhaoyun333 View Post
    Im sorry...COULD BE? Normally this code would take 200 lines.
    that 200 lines way is not the normal way anymore -.- ... its old way ; )

  8. #7
    zhaoyun333's Avatar
    Join Date
    Apr 2009
    Gender
    male
    Posts
    396
    Reputation
    11
    Thanks
    1,125
    So whats the new way?
    There are five possible operations for any army. If you can fight, fight; if you cannot fight, defend; if you cannot defend, flee; if you cannot flee, surrender; if you cannot surrender, die." - Sima Yi

  9. #8
    Matrix_NEO006's Avatar
    Join Date
    Feb 2008
    Gender
    male
    Posts
    240
    Reputation
    12
    Thanks
    33
    My Mood
    Lonely
    not my code
    Code:
    #include <windows.h>
    #include <stdlib.h>
    #include <string.h>
    #include <tchar.h>
    
    // Global variables
    
    // The main window class name.
    static TCHAR szWindowClass[] = _T("win32app");
    
    // The string that appears in the application's title bar.
    static TCHAR szTitle[] = _T("Win32 Guided Tour Application");
    
    HINSTANCE hInst;
    
    // Forward declarations of functions included in this code module:
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    
    int WINAPI WinMain(HINSTANCE hInstance,
                       HINSTANCE hPrevInstance,
                       LPSTR lpCmdLine,
                       int nCmdShow)
    {
        WNDCLASSEX wcex;
    
        wcex.cbSize = sizeof(WNDCLASSEX);
        wcex.style          = CS_HREDRAW | CS_VREDRAW;
        wcex.lpfnWndProc    = WndProc;
        wcex.cbClsExtra     = 0;
        wcex.cbWndExtra     = 0;
        wcex.hInstance      = hInstance;
        wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
        wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
        wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+3);
        wcex.lpszMenuName   = NULL;
        wcex.lpszClassName  = szWindowClass;
        wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
    
        if (!RegisterClassEx(&wcex))
        {
            MessageBox(NULL,
                _T("Call to RegisterClassEx failed!"),
                _T("Win32 Guided Tour"),
                NULL);
    
            return 1;
        }
    
        hInst = hInstance; // Store instance handle in our global variable
    
        // The parameters to CreateWindow explained:
        // szWindowClass: the name of the application
        // szTitle: the text that appears in the title bar
        // WS_OVERLAPPEDWINDOW: the type of window to create
        // CW_USEDEFAULT, CW_USEDEFAULT: initial position (x, y)
        // 500, 100: initial size (width, length)
        // NULL: the parent of this window
        // NULL: this application dows not have a menu bar
        // hInstance: the first parameter from WinMain
        // NULL: not used in this application
        HWND hWnd = CreateWindow(
            szWindowClass,
            szTitle,
            WS_OVERLAPPEDWINDOW,
            CW_USEDEFAULT, CW_USEDEFAULT,
            800, 600,
            NULL,
            NULL,
            hInstance,
            NULL
        );
    
        if (!hWnd)
        {
            MessageBox(NULL,
                _T("Call to CreateWindow failed!"),
                _T("Win32 Guided Tour"),
                NULL);
    
            return 1;
        }
    
        // The parameters to ShowWindow explained:
        // hWnd: the value returned from CreateWindow
        // nCmdShow: the fourth parameter from WinMain
        ShowWindow(hWnd,
            nCmdShow);
        UpdateWindow(hWnd);
    
        // Main message loop:
        MSG msg;
        while (GetMessage(&msg, NULL, 0, 0))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    
        return (int) msg.wParam;
    }
    
    //
    //  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
    //
    //  PURPOSE:  Processes messages for the main window.
    //
    //  WM_PAINT    - Paint the main window
    //  WM_DESTROY  - post a quit message and return
    //
    //
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        PAINTSTRUCT ps;
        HDC hdc;
        TCHAR greeting[] = _T("Hello, World!");
    
        switch (message)
        {
        case WM_PAINT:
            hdc = BeginPaint(hWnd, &ps);
    
            // Here your application is laid out.
            // For this introduction, we just print out "Hello, World!"
            // in the top left corner.
            TextOut(hdc,
                5, 5,
                greeting, _***len(greeting));
            // End application-specific layout section.
    
            EndPaint(hWnd, &ps);
            break;
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
            break;
        }
    
        return 0;
    }

  10. #9
    zeco's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    Canada
    Posts
    683
    Reputation
    12
    Thanks
    78
    My Mood
    Cynical
    Yep that's only 140 lines =D

    Either-way, this API isn't something i'm likely to use cause i like the the hard way better.

  11. #10
    zhaoyun333's Avatar
    Join Date
    Apr 2009
    Gender
    male
    Posts
    396
    Reputation
    11
    Thanks
    1,125
    Quote Originally Posted by zeco View Post
    Yep that's only 140 lines =D

    Either-way, this API isn't something i'm likely to use cause i like the the hard way better.
    Buuuuuuuuut its sooooo much easier
    There are five possible operations for any army. If you can fight, fight; if you cannot fight, defend; if you cannot defend, flee; if you cannot flee, surrender; if you cannot surrender, die." - Sima Yi

  12. #11
    zeco's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    Canada
    Posts
    683
    Reputation
    12
    Thanks
    78
    My Mood
    Cynical
    Quote Originally Posted by zhaoyun333 View Post
    Buuuuuuuuut its sooooo much easier
    Yeah but the easy way isn't as fun or rewarding >_> . Plus what if i want do something outside the scope of your API <_< Then i would be left high and dry

  13. #12
    XGelite's Avatar
    Join Date
    Mar 2009
    Gender
    male
    Location
    Enter text here
    Posts
    1,344
    Reputation
    12
    Thanks
    276
    or why cant you just use VC++ and just make all the windows and buttons and stuff by drag in and dropping like you do in VB. its a whole lot easier -.- why waist time coding that stuff when you could be spending the time on the program itself? unless your doing d3d then thers no point...
    but im learning d3d right now and you have to do it the long/hard way -.- ... so i guess there is a point..lol :P

  14. #13
    zhaoyun333's Avatar
    Join Date
    Apr 2009
    Gender
    male
    Posts
    396
    Reputation
    11
    Thanks
    1,125
    i have the express edition so I cant rly use it, besides i like actually coding it not like the VB stuff
    There are five possible operations for any army. If you can fight, fight; if you cannot fight, defend; if you cannot defend, flee; if you cannot flee, surrender; if you cannot surrender, die." - Sima Yi

  15. #14
    zeco's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    Canada
    Posts
    683
    Reputation
    12
    Thanks
    78
    My Mood
    Cynical
    Actually for writing gui's in windows you could use other API's like QT. It comes with a designer that allows you to do the drag and drop stuff. Though i ended up having to do most of the work anyway. I've only ever written on GUI actually. Well besides when i started learning win32 but what i wrote is too useless to be called a gui.

  16. #15
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Well, I'm not sure exactly what your wrapper does, but It might be nice to use, for somethings, or for people who want to create Windows in C++, but don't yet know the API...

    You know what would be real nice? If you wrapped up the WinMain for them, in your class so they wouldn't have to worry about it.

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

Page 1 of 2 12 LastLast

Similar Threads

  1. Fail API wrapper class, I need criticism..
    By Void in forum C++/C Programming
    Replies: 12
    Last Post: 08-05-2010, 07:39 AM
  2. Guild Wars New Classes
    By Chronologix in forum General Gaming
    Replies: 24
    Last Post: 07-23-2006, 08:46 AM
  3. Heavy Weapons Class mine bug. I had no idea.
    By NukeAssault in forum General Gaming
    Replies: 2
    Last Post: 07-20-2006, 06:54 AM
  4. Not a valid win32 application
    By terence in forum General Game Hacking
    Replies: 1
    Last Post: 02-03-2006, 06:52 AM
  5. [Tutorial]Change class without respawn
    By vir2000 in forum Game Hacking Tutorials
    Replies: 0
    Last Post: 01-04-2006, 01:47 PM

Tags for this Thread