f10 key

This is a discussion on f10 key within the Windows Programming forums, part of the Platform Specific Boards category; Hi i am new in windows programming i create one window and when i call MessageBox(.....) or GetOpenFileName(....),my window go ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Location
    Portugal
    Posts
    25

    Talking 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
    Last edited by joseCarlos; 11-08-2010 at 05:54 PM.

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,625
    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.
    Devoted my life to programming...

  3. #3
    Registered User
    Join Date
    Oct 2009
    Location
    Portugal
    Posts
    25
    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
    Last edited by joseCarlos; 11-09-2010 at 08:13 AM.

  4. #4
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,625
    If i don't see relevant code, i cannot possibly know what's going wrong...
    Devoted my life to programming...

  5. #5
    Registered User
    Join Date
    Oct 2009
    Location
    Portugal
    Posts
    25
    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?

  6. #6
    Registered User
    Join Date
    Oct 2009
    Location
    Portugal
    Posts
    25
    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();
    }
    Last edited by joseCarlos; 11-10-2010 at 08:56 PM.

  7. #7
    Registered User
    Join Date
    Oct 2009
    Location
    Portugal
    Posts
    25
    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????

  8. #8
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    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.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 11-23-2007, 12:48 PM
  2. Virtual keys
    By Arkanos in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2005, 09:00 AM
  3. Directional Keys - Useing in Console
    By RoD in forum C++ Programming
    Replies: 38
    Last Post: 10-06-2002, 04:42 PM
  4. FAQ: Directional Keys - Useing in Console
    By RoD in forum FAQ Board
    Replies: 38
    Last Post: 10-06-2002, 04:42 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21