Click to See Complete Forum and Search --> : Message Handle


Cooker
December 19th, 2004, 11:04 PM
Hi,
I write the message handle such as:

LRESULT CALLBACK WndProc (HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{

switch (Message){
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, Message, wParam, lParam);
}
return 0;

}

I rewrite the function by using HANDLE_MSG macro such as:

LRESULT CALLBACK WndProc (HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{

switch (Message){
HANDLE_MSG(hwnd, WM_CREATE, MainWindow_OnCreate) ;
HANDLE_MSG(hwnd, WM_DESTROY, MainWindow_OnDestroy) ;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
default:
return MainWindow_DefProc (hwnd, Message, wParam, lParam) ;
}

}
/****************************
MsgHand: WM_CREATE
***************************/
BOOL MainWindow_OnCreate(HWND hwnd, LPCREATESTRUCT lpCreateStruct)
{
return TRUE;
}

/****************************
MsgHand: WM_DESTROY
***************************/
void MainWindow_OnDestroy(HWND hwnd)
{
PostQuitMessage(0) ;
return ;
}

But when I will execute the program again after I have alread closed the window,
the message tell me :

INK : fatal error LNK1168: cannot open Debug/Player.exe for writing
Error executing link.exe.

I confirm that I have closed the windows.
But why I can't execute the program again?
Could someone tell me ? Thank you! :)

Paul Rice
December 19th, 2004, 11:19 PM
Hi,
I write the message handle such as:

LRESULT CALLBACK WndProc (HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{

switch (Message){
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, Message, wParam, lParam);
}
return 0;

}

I rewrite the function by using HANDLE_MSG macro such as:

LRESULT CALLBACK WndProc (HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{

switch (Message){
HANDLE_MSG(hwnd, WM_CREATE, MainWindow_OnCreate) ;
HANDLE_MSG(hwnd, WM_DESTROY, MainWindow_OnDestroy) ;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
default:
return MainWindow_DefProc (hwnd, Message, wParam, lParam) ;
}

}
/****************************
MsgHand: WM_CREATE
***************************/
BOOL MainWindow_OnCreate(HWND hwnd, LPCREATESTRUCT lpCreateStruct)
{
return TRUE;
}

/****************************
MsgHand: WM_DESTROY
***************************/
void MainWindow_OnDestroy(HWND hwnd)
{
PostQuitMessage(0) ;
return ;
}

But when I will execute the program again after I have alread closed the window,
the message tell me :

INK : fatal error LNK1168: cannot open Debug/Player.exe for writing
Error executing link.exe.

I confirm that I have closed the windows.
But why I can't execute the program again?
Could someone tell me ? Thank you! :)

I get : "warning C4013: 'HANDLE_MSG' undefined; assuming extern returning int". Otherwise, it seems to run fine. The window is grey. The title is "Video Player". It starts and closes without problem. It looks good.

Krzemo
December 19th, 2004, 11:42 PM
Im not sure, but IMHO U shold call PostQuitMessage(0); in WM_CLOSE too because I suspect that DestroyWindow(hwnd) cause that WM_DESTROY will not be sended.


If the program is running (without the window opened), U cannot overwrite it (by linking exe).

Best regards,
Krzemo.

PS:
Paul:
warning C4013: 'HANDLE_MSG' undefined; assuming extern returning int 'HANDLE_MSG' is defined in WindowsX.h

Andreas Masur
December 20th, 2004, 04:22 AM
But when I will execute the program again after I have alread closed the window,
the message tell me :

INK : fatal error LNK1168: cannot open Debug/Player.exe for writing
Error executing link.exe.

I confirm that I have closed the windows.
But why I can't execute the program again?
Could someone tell me ? Thank you! :)
I am not sure whether I understand the problem and what the above has to do with it...however, usuallz you get the above is the .exe is still running for example...

Cooker
December 20th, 2004, 04:34 AM
I am not sure whether I understand the problem and what the above has to do with it...however, usuallz you get the above is the .exe is still running for example...
Right, The program is still running in OS.
But I can't see the window.

NoHero
December 20th, 2004, 09:53 AM
If you create a window with CreateWindow(Ex) or a dialog with CreateDialog, this window is initially shown invisible. You need to call ShowWindow() to make it visible. I can't see in your postings if have such a call. But maybe this is the mistake.

wshcdr
December 22nd, 2004, 01:04 AM
INK : fatal error LNK1168: cannot open Debug/Player.exe for writing
Error executing link.exe.


//////////////////////////////
'Cos the thread message loop still running.
though , the the Window of the app is invisible.

NoHero
December 22nd, 2004, 02:00 AM
INK : fatal error LNK1168: cannot open Debug/Player.exe for writing
Error executing link.exe.


//////////////////////////////
'Cos the thread message loop still running.
though , the the Window of the app is invisible.

THen shutdown your app by using the TaskManager, and use PostQuitMessage() to close the application and to exit the main loop.