Thread: new functions in a win32 application

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    That weird Java guy xniinja's Avatar
    Join Date
    Jun 2010
    Posts
    231
    ok, now that button click at the bottom isn't working
    the:

    Code:
    if (HIWORD(wParam) == BN_CLICKED) {}
    sorry i am dragging this on

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Code:
    if (HIWORD(wParam) == BN_CLICKED) {}
    This can not be reached due to the placement of 'break'. It has no 'case' statement (ie case ID_SOME_CONTROL: is missing)


    Also, you have 2 declarations of the listboxes HWND, which may be causing issues (as the one that gets a valid HWND has limited scope.


    You also appear to be doing this the hard way, creating and destroying the controls (instead of just show/hide the controls as required ie ShowWindow(hWndEdit, SW_HIDE) ).

    Normally to do this kind of thing you create another dialog to hold all the edits and Hide/Show this dialog as required (ie draw the dialog in the resource editor, create the dlg once in the apps Create msg, show/hide the whole dlg in response to a command msg, destroy the whole dlg on apps close msg)

    EDIT: Have a look at GetLastError() Is very handy to debug these type of things.
    Last edited by novacain; 07-13-2010 at 08:13 PM.
    "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

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    I read your code again....

    I think you should break your code down into smaller blocks (that do one thing well and can be reused). It would help you see the flow of your code (as it is repeating operations and failing to do other ones) and avoid what appears to be some cut/paste errors.

    Some issues I see...

    You can not have 4 edits with the same ID (they need to be different if on the same dlg).

    Quote Originally Posted by MSDN CreateWindow() hmenu param
    For a child window, hMenu specifies the child-window identifier, an integer value used by a dialog box control to notify its parent about events. The application determines the child-window identifier; it must be unique for all child windows with the same parent window.

    This is what your code does...

    Code:
    		//open pfile2 as C:\\reminder\\data\\backup1.xls
    		//if pfile2 failed to open 
    			//open/create pfile as C:\\reminder\\data\\backup1.xls 
    			//pfile2 == null
    
    		//open pfile as database1234.xls (on a possibly already used pfile)
    		//if database1234.xls failed to open
    			//if C:\\reminder\\data\\backup1.xls failed to open
    				//open pFile as C:reminder\\data\\backup1.xls (which may fail again leaving pfile null)
    				//pfile2 is null
    			//else pfile is null
    		//if database1234.xls opened
    			//close it and open in append mode
    
    		//close both files (up to 5 fopens for no reason....)
    
    		//open both files in append mode (what if you have read only permission or the file is already open or fails again etc? [will data be lost if this happens?])
    		
    		//get entered text from edits
    
    		//write to file
    		//close files
    		//clear edits
    This code could fail; getting no text or crash as text len exceeds buffer size.

    Code:
    len = GetWindowTextLength(hwndEdit) + 1;
    //what happens if len is now bigger than 1000 (what text can hold) or zero (no text entered or error)?
    
    //get the text from edit(1)
    GetWindowText(hwndEdit, text, len);//the 3rd parameter should be the size of the char array (ie 1000)
    
    GetWindowText(hwndEdit2, text2, len);//you are using the same len, from edit(1) for all edits, if it is zero....

    What you want is...
    Code:
    Validate
                Check user has entered text in all req edits
                       validate text if required
                               prompt user for more input if req
                Check files can be opened in append mode
                       warn user and abort if fail
    
    Get input
    
    Write input to file
    
    Clean up
             Close files
             Clear edits
    Last edited by novacain; 07-13-2010 at 11:59 PM.
    "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. Array of functions
    By frktons in forum C Programming
    Replies: 29
    Last Post: 06-30-2010, 09:51 AM
  2. First time Creating Win32 application with UI
    By chiefmonkey in forum Windows Programming
    Replies: 9
    Last Post: 09-23-2009, 11:44 AM
  3. Replies: 6
    Last Post: 05-15-2007, 10:47 PM
  4. Painting with Tex on a Win32 Application
    By webzest in forum C++ Programming
    Replies: 5
    Last Post: 08-16-2004, 03:04 PM
  5. Can I Load A Sound or Music Into My Win32 Application ?
    By SonicWave in forum Windows Programming
    Replies: 8
    Last Post: 09-21-2001, 07:54 AM