Hell_Demon (11-14-2009),why06 (11-15-2009)
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:
[IMG]https://i344.photobucke*****m/albums/p349/zhaoyun3/test.jpg[/IMG]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; }
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
Hell_Demon (11-14-2009),why06 (11-15-2009)
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 OceanModerator: 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.
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
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
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
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.
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
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
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.
"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