Win32 Api Class [In Devolopment]

Posts 115 of 16 · Page 1 of 2
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;
}
oh hai Zhaoyun, havent seen u in 4ever.
yeah i know ive been elsewhere
Im sorry...COULD BE? Normally this code would take 200 lines.
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 ; )
So whats the new way?
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;
}
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.
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
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
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
i have the express edition so I cant rly use it, besides i like actually coding it not like the VB stuff
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.
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.
Posts 115 of 16 · Page 1 of 2
This thread is closed for replies.

Similar Threads

Tags for this Thread

Need help?