•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 402,505 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,767 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
An introduction to the Win32 GUI. The code creates a simple window that you can play with. Many parameters can be changed if you like! The unusual thing about windows apps is that rather than directly handling inputs (ie the position of the mouse / what control has focus ect...) you process window messages. Whenever something happens, it sends a message to the window making a message queue. DispatchMessage() calls WindowProcedure (which if you look is assigned to be the default message handler for the class name ("WindowsApp") of which the window belongs. The good thing is that as all messages are of the same structure it is easy to get information about what happened (lParam/wParam) and take the correct action (switch statement). Enjoy!
#include <windows.h> /* Windows header */ LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); char szClassName[ ] = "WindowsApp"; /* Class ID */ int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) { HWND hwnd; MSG messages; WNDCLASSEX wincl; wincl.hInstance = hThisInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; /* See end of code */ wincl.style = CS_DBLCLKS; wincl.cbSize = sizeof (WNDCLASSEX); wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION); wincl.hCursor = LoadCursor (NULL, IDC_ARROW); wincl.lpszMenuName = NULL; wincl.cbClsExtra = 0; wincl.cbWndExtra = 0; wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND; /* Default windows background colour */ if (!RegisterClassEx (&wincl)) return 0; hwnd = CreateWindowEx ( 0, szClassName, /* Classname */ "Windows App", /* Title Text */ WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, /* Default x... */ CW_USEDEFAULT, /* ...and default y position of window */ 640, /* The programs width... */ 480, /* ...and height in pixels */ HWND_DESKTOP, NULL, hThisInstance, NULL ); /* Make the window visible on the screen */ ShowWindow (hwnd, nFunsterStil); while (GetMessage (&messages, NULL, 0, 0)) { TranslateMessage(&messages); DispatchMessage(&messages); } /* Return: wParam from a quit message usually = 0 */ return messages.wParam; } LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { /* Called when window processes a message */ switch (message) { case WM_DESTROY: /* Destoy message: called if you press the "x" in the top right corner */ PostQuitMessage (0); /* Send a message to quit */ break; default: return DefWindowProc (hwnd, message, wParam, lParam); } return 0; }
Comments (Newest First)
bumsfeld | Posting Shark | Aug 8th, 2005
•
•
•
•
I think FunsterStil is Danish for WindowStyle.
Dae | Newbie Poster | Jun 12th, 2005
•
•
•
•
nFunsterStil is just a local variable name they used down at 'ShowWindow (hwnd, nFunsterStil);', meaning upon calling the fuction you could use that as an arguement spot... but the name itself doesnt mean anything apprently.
Good way for them to tell who is using their code though, just search google for that variable name they've come up with and put as a temple on their program.
Good way for them to tell who is using their code though, just search google for that variable name they've come up with and put as a temple on their program.
1o0oBhP | Posting Pro in Training | Mar 5th, 2005
Tight_Coder_Ex | Junior Poster | Feb 7th, 2005
•
•
•
•
I am curious as to which compiler you used to create the executable. In know with VC++, not typecasting WindowProcedure will cause and error.
Secondly, why MS$ has done this I'll never know, but not adding 1 to the desired background color will yeild the wrong color. I must use HBRUSH (COLOR_BACKGROUND + 1) with VC++.
Maybe the headers you use have the background colors adjusted already.
Secondly, why MS$ has done this I'll never know, but not adding 1 to the desired background color will yeild the wrong color. I must use HBRUSH (COLOR_BACKGROUND + 1) with VC++.
Maybe the headers you use have the background colors adjusted already.
1o0oBhP | Posting Pro in Training | Dec 20th, 2004
vegaseat | Kickbutt Moderator | Dec 20th, 2004
•
•
•
•
nFunsterStil? The folks at Dev C++ use it too! Wonder what that means?
Post Comment
•
•
•
•
DaniWeb Marketplace (Sponsored Links)