-
f10 key
Hi
i am new in windows programming
i create one window and when i call MessageBox(.....) or GetOpenFileName(....),my window go to inactive
state but the MessageBox dont appears i need to push f10 key to continue
my program, why? there is no errors, can you help me?
that eppening just inside my WndProc procedure,
if i make this call after MessageLoop ther is no problems,mor
this hepening just the first time, after push f10 key, all works good, strange think for me
thanks for your atencion
-
Thou programme acts in mysterious ways. None shall defy it! ...
Now seriously, there may be a lot of factor that make this happen. Inside yout message loop, do you use your windows' handle or the default one, NULL? Do you pass that handle to the MessageBox function or again you use NULL? I don't know what may your problem be, but doesn't hurt to check a few things.
-
Há...Há...Há...Há (laugh)
We all got a mysterious part
well, in thru,that´s a NULL variable,i goto change that
thank´s for their willingness
not apparent.
ther is same problem
Windows Help does not help much
-
If i don't see relevant code, i cannot possibly know what's going wrong...
-
grateful for the kindness, but first
I will learn to work better with my platform,
I think I am not doing well with ressource workshop
I do not like the C + + Builder, my platform is Borland BC45.
Dislikes visual platforms, like writing the code
I am used to studying in DOS, only now I'm moving to
protect mode.can you suggest a better platform?
-
Well .. but here's some code
GetPoint global functions () and SetPoint (), are to read and insert
a pointer in WNDCLASS structur to the Window object created, as I understand, this is necessary
to c + +
thank you for your comment
Code:
void Window::Register(){
WNDCLASS wndclass;
wndclass.style=NULL;
wndclass.lpfnWndProc=::WndProc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=sizeof(Window*);
wndclass.hInstance=TApp::hInstance;
wndclass.hIcon=LoadIcon(TApp::hInstance,"small");
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)CreateSolidBrush(RGB(60,80,110));
wndclass.lpszMenuName="CMDLGAPMENU"; //menu name in ressource
wndclass.lpszClassName=name;
if(!RegisterClass(&wndclass))exit(FALSE);
}
LRESULT Window::WndProc(UINT iMessage,WPARAM wParam,LPARAM lParam){
switch(iMessage){
case WM_COMMAND:
switch(GET_WM_COMMAND_ID(wParam,lParam)){
case CM_EXIT:
DestroyWindow(hwnd);
break;
case CM_U_FILEOPEN:
CMUFileOpen();
return 0L;
case CM_U_HELPABOUT:
MessageBox(hwnd,"Music Score Writer","About Pautas",MB_OK);
return 0L;
default:break;
}
break;
case WM_CREATE:
szName[0]=0;
SoundSize=0;
idTimer=0;
index=0;
wavBuf=new unsigned char[BUFSIZE];
break;
case WM_TIMER:
DrawData();
break;
case WM_PAINT:
break;
case WM_DESTROY:
ReleaseDC(hwnd,dc);
if(idTimer)KillTimer(hwnd,idTimer);
delete wavBuf;
if(szName){
_lclose(hFile);
szName[0]=0;
}
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,iMessage,wParam,lParam);
}
return 0;
}
void Window::CMUFileOpen(){
if(szName){
_lclose(hFile);
szName[0]=0;
}
OPENFILENAME ofnTemp;
DWORD Errval; // Error value
char buf[5]; // Error buffer
char Errstr[50]="GetOpenFileName returned Error #";
char szTemp[] = "Wave Files (*.wav)\0*.wav\0";
ofnTemp.lStructSize = sizeof( OPENFILENAME );
ofnTemp.hwndOwner = hwnd; // An invalid hWnd causes non-modality
ofnTemp.hInstance = 0;
ofnTemp.lpstrFilter = (LPSTR)szTemp; // See previous note concerning string
ofnTemp.lpstrCustomFilter = NULL;
ofnTemp.nMaxCustFilter = 0;
ofnTemp.nFilterIndex = 1;
ofnTemp.lpstrFile = (LPSTR)szName; // Stores the result in this variable
ofnTemp.nMaxFile = sizeof( szName );
ofnTemp.lpstrFileTitle = NULL;
ofnTemp.nMaxFileTitle = 0;
ofnTemp.lpstrInitialDir = NULL;
ofnTemp.lpstrTitle = "OPENFILENAME"; // Title for dialog
ofnTemp.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;
ofnTemp.nFileOffset = 0;
ofnTemp.nFileExtension = 0;
ofnTemp.lpstrDefExt = "*";
ofnTemp.lCustData = 0L;
ofnTemp.lpfnHook = NULL;
ofnTemp.lpTemplateName = NULL;
if(GetOpenFileName( &ofnTemp ) != TRUE){
Errval=CommDlgExtendedError();
if(Errval!=0){ // 0 value means user selected Cancel
sprintf(buf,"%ld",Errval);
strcat(Errstr,buf);
MessageBox(hwnd,Errstr,"WARNING",MB_OK|MB_ICONSTOP);
}
}
if(szName){
if((hFile=_lopen(szName,READ))!=HFILE_ERROR){
_lread(hFile,&wavHdr,sizeof(wavHdr));
if(wavHdr.RIFF!=0x46464952L || // RIFF
wavHdr.wid!=0x45564157L || // WAVE header
wavHdr.fid!=0x20746d66L){ // FMT
_lclose(hFile);szName[0]=0;
MessageBox(hwnd,"Not a valid Wave File","WARNING",MB_OK|MB_ICONSTOP);
}
else {
SoundSize=wavHdr.dlen;
idTimer=SetTimer(hwnd,idTimer,10,NULL);
LoadData();
}
}
}
}
// If data pointers are near pointers
#if defined(__SMALL__) || defined(__MEDIUM__)
inline Window *GetPointer( HWND hWnd )
{
return (Window *) GetWindowWord( hWnd, 0 );
}
inline void SetPointer( HWND hWnd, Window *pWindow )
{
SetWindowWord( hWnd, 0, (WORD) pWindow );
}
// else pointers are far
#elif defined(__LARGE__) || defined(__COMPACT__) || defined(__FLAT__)
inline Window *GetPointer( HWND hWnd )
{
return (Window *) GetWindowLong( hWnd, 0 );
}
inline void SetPointer( HWND hWnd, Window *pWindow )
{
SetWindowLong( hWnd, 0, (LONG) pWindow );
}
#else
#error Choose another memory model!
#endif
LRESULT CALLBACK _export WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam){
Window *pWindow=GetPointer(hWnd);
if(pWindow==0){
if(iMessage==WM_CREATE){
LPCREATESTRUCT lpcs;
lpcs=(LPCREATESTRUCT)lParam;
pWindow=(Window*)lpcs->lpCreateParams;
SetPointer(hWnd,pWindow);
return pWindow->WndProc(iMessage,wParam,lParam);
}
else
return DefWindowProc(hWnd,iMessage,wParam,lParam);
}
else
return pWindow->WndProc(iMessage,wParam,lParam);
}
int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine,
int nCmdShow ){
TApp::hInstance = hInstance;
TApp::hPrevInstance = hPrevInstance;
TApp::nCmdShow = nCmdShow;
if ( ! TApp::hPrevInstance ) {
Window::Register();
}
Window MainWnd;
return TApp::MessageLoop();
}
-
Ok i have same results
i need to put this code in
Code:
Window::WndProc(UINT Message,WPARAM wParam,LPARAM lParam){
HDC hdc;
PAINTSTRUCT ps;
...
...
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
EndPaint(hwnd,&ps);
break;
...
...
}
Is that normal????
-
Any message you do not process must be sent to the OS for processing using DefWindowProc().
In the WM_COMMAND handler you have a default handler that stops DefWindowProc() being called.
Try removing it.