My first post was closed. Perhaps I wasn't clear.
Code Blocks 10.5
Long time since I've programmed Win32.
New Code::Blocks project wizard created all the sourcecode (main.cpp) for my
Frame based Windows GUI.
However the source code did not include an UpdateWindow call.
I have books from Brain, Petzhold, Schildt, Hansen, Simon etc.
All of them include a call to UpdateWindow after ShowWindow.
Is this intentional?
Cheers
This is NOT really a programming question site; the experts that can give that question a good answer more likely found on another site. If you find out a different answer from the CB default code. Please post in this thread the correct default code for this project type.
Tim S.
Thanks for the reply. I'll respect the posting rules. Since the question was
more about the default code in the project wizard, I felt it might
have seen some feedback in this forum before.
My mistake.
I have all the compiler tools on the planet, but many times those tools
get in the way. I am now using Code::Blocks for my C/C++ environment.
I think it's a winner! Maybe I'll buy a shirt.
Funny thing about programming. You can do something for 25 years,
then all of a sudden, "oh! I can do it that way!"
Here's my 2 cents on a default windows GUI template.
Bret Stern
#include <windows.h>
/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
/* Make the class name into a global variable */
char szClassName[ ] = "CodeBlocksWindowsApp";
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */
/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default colour as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;
/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Code::Blocks Template Windows App", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
544, /* The programs width */
375, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
/* Make the window visible on the screen */
ShowWindow (hwnd, nCmdShow);
/*my 2 cents*/
UpdateWindow(hwnd);
/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}
/* This function is called by the Windows function DispatchMessage() */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
Quote from: sevendogzero on February 10, 2012, 04:25:44 AM
Since the question was
more about the default code in the project wizard, I felt it might
have seen some feedback in this forum before.
The code provided in the wizards is just for convenience and far from being complete / perfect. It must not even make more sense than the typical "hello world". Its there as a starter - so you will
need to do something with it, e.g. enhance it in the way you like by (for example) adding a
UpdateWindow call.