|
From: Noorez K. <coo...@ho...> - 2003-12-24 21:11:59
|
My windows APP is closing before i see any results! It complies fine but it
just closes
#include <windows.h>
LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsgId, WPARAM wParam, LPARAM
lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
pszCmdLine, int nCmdShow)
{
static char szAppName[] = "hello";
HWND hWnd;
MSG msg;
WNDCLASSEX wndClass;
//register class
wndClass.style = 0;
wndClass.lpfnWndProc = WindowProc;
wndClass. cbClsExtra = 0;
wndClass.hInstance = hInstance;
wndClass.hIcon = LoadIcon( hInstance, szAppName);
wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndClass.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
wndClass.lpszMenuName = NULL;
wndClass.lpszClassName = szAppName;
wndClass.hIconSm = wndClass.hIcon;
if(RegisterClassEx(&wndClass)==0)//register class...
return 0; //quit if it doesn't work
//now create window
hWnd = CreateWindow(szAppName, szAppName, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance,
NULL);
if(hWnd == NULL)
return 0;
ShowWindow(hWnd, nCmdShow);
UpdateWindow( hWnd );
while( GetMessage(&msg, NULL, 0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
//process functions
LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsgId, WPARAM wParam, LPARAM
lParam)
{
static char *pszHello = "Hello, world";
switch(uMsgId)
{
case WM_PAINT:
{
HDC hDC;
PAINTSTRUCT paintStruct;
hDC = BeginPaint( hWnd, &paintStruct);
TextOut(hDC, 0,0, pszHello, lstrlen(pszHello));
EndPaint( hWnd, &paintStruct );
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd,uMsgId,wParam,lParam);
}
return 0;
}
_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE*
http://join.msn.com/?page=features/virus&pgmarket=en-ca&RU=http%3a%2f%2fjoin.msn.com%2f%3fpage%3dmisc%2fspecialoffers%26pgmarket%3den-ca
|
|
From: Noorez K. <coo...@ho...> - 2003-12-24 21:27:03
|
This WinApp closes too fast to see results
#include <windows.h>
LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsgId, WPARAM wParam, LPARAM
lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
pszCmdLine, int nCmdShow)
{
static char szAppName[] = "hello";
HWND hWnd;
MSG msg;
WNDCLASSEX wndClass;
//register class
wndClass.style = 0;
wndClass.lpfnWndProc = WindowProc;
wndClass. cbClsExtra = 0;
wndClass.hInstance = hInstance;
wndClass.hIcon = LoadIcon( hInstance, szAppName);
wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndClass.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
wndClass.lpszMenuName = NULL;
wndClass.lpszClassName = szAppName;
wndClass.hIconSm = wndClass.hIcon;
if(RegisterClassEx(&wndClass)==0)//register class...
return 0; //quit if it doesn't work
//now create window
hWnd = CreateWindow(szAppName, szAppName, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance,
NULL);
if(hWnd == NULL)
return 0;
ShowWindow(hWnd, nCmdShow);
UpdateWindow( hWnd );
while( GetMessage(&msg, NULL, 0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
//process functions
LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsgId, WPARAM wParam, LPARAM
lParam)
{
static char *pszHello = "Hello, world";
switch(uMsgId)
{
case WM_PAINT:
{
HDC hDC;
PAINTSTRUCT paintStruct;
hDC = BeginPaint( hWnd, &paintStruct);
TextOut(hDC, 0,0, pszHello, lstrlen(pszHello));
EndPaint( hWnd, &paintStruct );
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd,uMsgId,wParam,lParam);
}
return 0;
}
_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/photos&pgmarket=en-ca&RU=http%3a%2f%2fjoin.msn.com%2f%3fpage%3dmisc%2fspecialoffers%26pgmarket%3den-ca
|
|
From: Michael C U. <mu...@cb...> - 2003-12-24 23:27:26
|
Hi Noorez,
The problem is in your switch structure. Your callback function doesn't
return a value from WM_PAINT. Replace the break statement at the end of
your case with a "return 0" statement, and I think that might fix your
problem.
Also. note that the braces around the code in your WM_PAINT case are not
necessary. You don't need to use braces to group case statements as all of
hem will execute up until it encounters a break or return.
Try replacing "break" with "return 0;" and also removing the braces from
the WM_PAINT case. That might fix your problem.
On Wed, 24 Dec 2003, Noorez Kassam wrote:
> This WinApp closes too fast to see results
>
> #include <windows.h>
>
>
> LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsgId, WPARAM wParam, LPARAM
> lParam);
>
> int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
> pszCmdLine, int nCmdShow)
> {
> static char szAppName[] = "hello";
> HWND hWnd;
> MSG msg;
> WNDCLASSEX wndClass;
>
> //register class
> wndClass.style = 0;
> wndClass.lpfnWndProc = WindowProc;
> wndClass. cbClsExtra = 0;
> wndClass.hInstance = hInstance;
> wndClass.hIcon = LoadIcon( hInstance, szAppName);
> wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
> wndClass.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
> wndClass.lpszMenuName = NULL;
> wndClass.lpszClassName = szAppName;
> wndClass.hIconSm = wndClass.hIcon;
>
> if(RegisterClassEx(&wndClass)==0)//register class...
> return 0; //quit if it doesn't work
>
> //now create window
> hWnd = CreateWindow(szAppName, szAppName, WS_OVERLAPPEDWINDOW,
> CW_USEDEFAULT, CW_USEDEFAULT,
> CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance,
> NULL);
>
> if(hWnd == NULL)
> return 0;
>
> ShowWindow(hWnd, nCmdShow);
> UpdateWindow( hWnd );
>
> while( GetMessage(&msg, NULL, 0,0))
> {
> TranslateMessage(&msg);
> DispatchMessage(&msg);
> }
> return msg.wParam;
> }
>
>
> //process functions
> LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsgId, WPARAM wParam, LPARAM
> lParam)
> {
> static char *pszHello = "Hello, world";
>
> switch(uMsgId)
> {
> case WM_PAINT:
> {
> HDC hDC;
> PAINTSTRUCT paintStruct;
>
> hDC = BeginPaint( hWnd, &paintStruct);
>
> TextOut(hDC, 0,0, pszHello, lstrlen(pszHello));
>
> EndPaint( hWnd, &paintStruct );
> }
> break;
>
> case WM_DESTROY:
> PostQuitMessage(0);
>
> break;
>
> default:
> return DefWindowProc(hWnd,uMsgId,wParam,lParam);
> }
> return 0;
> }
>
> _________________________________________________________________
> Add photos to your e-mail with MSN 8. Get 2 months FREE*.
> http://join.msn.com/?page=features/photos&pgmarket=en-ca&RU=http%3a%2f%2fjoin.msn.com%2f%3fpage%3dmisc%2fspecialoffers%26pgmarket%3den-ca
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: IBM Linux Tutorials.
> Become an expert in LINUX or just sharpen your skills. Sign up for IBM's
> Free Linux Tutorials. Learn everything from the bash shell to sys admin.
> Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|
|
From: <ce...@te...> - 2003-12-25 17:21:01
|
Not for me. When I don't put the braces, the next case is performed, no matter there is a break; Also. note that the braces around the code in your WM_PAINT case are not >necessary. You don't need to use braces to group case statements as all of >hem will execute up until it encounters a break or return. > > > > |
|
From: Michael C U. <mu...@cb...> - 2003-12-25 17:38:12
|
Hmm.. Can you post a sample? Because you shouldn't need to use braces to brace case statments (note that you DO need to use braces around the entire switch block though). But basically, the break statement should break out of the entire switch block, not just the current case. On Thu, 25 Dec 2003, [ISO-8859-1] Carlos Garc=EDa del Monte wrote: > Not for me. When I don't put the braces, the next case is performed, no > matter there is a break; > > > Also. note that the braces around the code in your WM_PAINT case are not > > >necessary. You don't need to use braces to group case statements as all = of > >hem will execute up until it encounters a break or return. > > > > > > > > > > |
|
From: <or...@vp...> - 2003-12-25 21:01:17
|
Hi!
You left out 2 members of your wndclass structure.
wndClass.cbWndExtra = 0;
wndClass.cbSize = sizeof(WNDCLASSEX);
And about that { } braces inside the case: it is needed because
variables are declared inside the case, and they need to be kept in the
scope of the case statement, and that can only be achieved by creating a
block inside it.
--
Greetings,
Balázs
|
|
From: Michael C U. <mu...@cb...> - 2003-12-26 21:25:20
|
> And about that { } braces inside the case: it is needed because
> variables are declared inside the case, and they need to be kept in the
> scope of the case statement, and that can only be achieved by creating a
> block inside it.
But the variables will go out of scope when the break or return statement
is encountered won't they? Because the entire select block is enclosed in
braces, so they variables will be local to the select block. Once the
select block has exited, the variables should go out of scope shouldn't
they?
So given that, I don't see why the braces are necessary enclosing the
case.
|
|
From: <or...@vp...> - 2003-12-27 00:43:21
|
Michael C Urban wrote:
>>And about that { } braces inside the case: it is needed because
>>variables are declared inside the case, and they need to be kept in the
>>scope of the case statement, and that can only be achieved by creating a
>>block inside it.
>
>
> But the variables will go out of scope when the break or return statement
> is encountered won't they? Because the entire select block is enclosed in
> braces, so they variables will be local to the select block. Once the
> select block has exited, the variables should go out of scope shouldn't
> they?
>
> So given that, I don't see why the braces are necessary enclosing the
> case.
Because then the variables will be inside the CASE, not in the SWITCH,
and they only get allocated, if that specific CASE is selected, not
every time the program enters the SWITCH.
--
Greetings,
Balázs
|
|
From: Michael C U. <mu...@cb...> - 2003-12-27 02:12:09
|
On Sat, 27 Dec 2003, [ISO-8859-1] OROSZI Bal=E1zs wrote: > Because then the variables will be inside the CASE, not in the SWITCH, > and they only get allocated, if that specific CASE is selected, not > every time the program enters the SWITCH. Ah. Ok. I see now. I thought the compiler would just ignore it because if CASE was false, the statements inside that case statement wouldn't even be evaluated. But, yes. I see what happens now. It won't even compile without the braces if they are declarations inside the case. > > -- > Greetings, > Bal=E1zs > > > > ------------------------------------------------------- > This SF.net email is sponsored by: IBM Linux Tutorials. > Become an expert in LINUX or just sharpen your skills. Sign up for IBM's > Free Linux Tutorials. Learn everything from the bash shell to sys admin. > Click now! http://ads.osdn.com/?ad_id=3D1278&alloc_id=3D3371&op=3Dclick > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |