Help making Program Better/More Effecient

This is a discussion on Help making Program Better/More Effecient within the C++ Programming forums, part of the General Programming Boards category; Hello, I am doing this program for my dad, which stores medecines. Can any one help me make a GUI ...

  1. #1
    Registered User
    Join Date
    May 2005
    Location
    Texas
    Posts
    103

    Talking Help making Program Better/More Effecient

    Hello, I am doing this program for my dad, which stores medecines. Can any one help me make a GUI for this Dos program, let's just say I'm not into Windows right now, I'm trying to get a good knowledge out of only using Win32 Console Application.

    Well, if any of you guys find a way how to make things more efficent, please let me know, I would really appreciate it.

    So far this is what i've done.

    Thankyou in ADVANCE!!
    Attached Files Attached Files

  2. #2
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    How about I give you code for a window and you work it out. It seems as if it would almost be easier to rewrite the whole thing than mess with that and change every single DOS bit. Well if you want some code snippets relating to Win32 then let me know because that's my area .
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  3. #3
    Registered User
    Join Date
    May 2005
    Location
    Texas
    Posts
    103
    Well, I don't know, are you talking about MFC?

  4. #4
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    Bleh, don't even say that. I despise MFC, I'm Win32 API all the way.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  5. #5
    Registered User
    Join Date
    May 2005
    Location
    Texas
    Posts
    103
    Ok...then...yet be easy on me...only 14...don't have a complex mind as others...

    thankyou
    Be easy on me...only 14

  6. #6
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    Well don't worry I'm only 16. Ok Ok, here's the basic stripped down code for a window:
    Code:
    LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
    
    int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
    PSTR szCmdLine,int iCmdShow)
    {
         HWND hwnd;
         MSG msg;
         WNDCLASS wc;
         
         wc.style=CS_HREDRAW|CS_VREDRAW;
         wc.cbWndExtra=0;
         wc.cbClsExtra=0;
         wc.hInstance=hInstance;
         wc.lpfnWndProc=WndProc;
         wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
         wc.hCursor=LoadCursor(NULL,IDC_ARROW);
         wc.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
         wc.lpszMenuName=NULL;
         wc.lpszClassName="Window";
         
         if(!RegisterClass(&wc))
         return 0;
         
         hwnd=CreateWindow("Window","Window",WS_POPUPWINDOW|WS_CAPTION|WS_MINIMIZEBOX,(GetSystemMetrics(SM_CXSCREEN)/2)-320,(GetSystemMetrics(SM_CYSCREEN)/2)-240,640,480,NULL,NULL,hInstance,NULL);
         ShowWindow(hwnd,iCmdShow);
         UpdateWindow(hwnd);
         while(GetMessage(&msg,NULL,0,0))
         {
                                         TranslateMessage(&msg);
                                         DispatchMessage(&msg);
         }
         return msg.wParam;
    }
    LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
    {
            switch(msg)
            {
                       case WM_DESTROY:
                            PostQuitMessage(0);
                            return 0;
            }
            return DefWindowProc(hwnd,msg,wParam,lParam);
    }
    All that code will compile with only ONE header included "#include <windows.h>" but I saw that you included that in your code. All that code does is create a fixed window in the center of your screen, or at least the center of most screens. Try cutting and pasting your code into this and reforming it into something that will work with this. You will need to create child windows to display and receive user input from.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  7. #7
    Registered User
    Join Date
    May 2005
    Location
    Texas
    Posts
    103
    Um....I already know the basics of "Windows API" the only reason I didn't my program in this, is because I don't know how to get input from the User, only by buttons, but that doesn't help when you need letters for the medecine names
    Be easy on me...only 14

  8. #8
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    Oooh well that helps narrow it down. Well for that you will need to create an edit child window. As is done here(revised main function):
    Code:
    int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
    PSTR szCmdLine,int iCmdShow)
    {
         HWND hwnd,hEdit;
         MSG msg;
         WNDCLASS wc;
         
         wc.style=CS_HREDRAW|CS_VREDRAW;
         wc.cbWndExtra=0;
         wc.cbClsExtra=0;
         wc.hInstance=hInstance;
         wc.lpfnWndProc=WndProc;
         wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
         wc.hCursor=LoadCursor(NULL,IDC_ARROW);
         wc.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
         wc.lpszMenuName=NULL;
         wc.lpszClassName="Window";
         
         if(!RegisterClass(&wc))
         return 0;
         
         hwnd=CreateWindow("Window","Window",WS_POPUPWINDOW|WS_CAPTION|WS_MINIMIZEBOX,(GetSystemMetrics(SM_CXSCREEN)/2)-320,(GetSystemMetrics(SM_CYSCREEN)/2)-240,640,480,NULL,NULL,hInstance,NULL);
         hEdit=CreateWindow("EDIT","",WS_CHILD|WS_BORDER|WS_VISIBLE,5,375,625,40,hwnd,NULL,hInstance,NULL);
         ShowWindow(hwnd,iCmdShow);
         UpdateWindow(hwnd);
         while(GetMessage(&msg,NULL,0,0))
         {
                                         TranslateMessage(&msg);
                                         DispatchMessage(&msg);
         }
         return msg.wParam;
    }
    Then the NULL paramter after hwnd in the CreateWindow for hEdit is where you would make an ID for it so you can access the messages received and get the data from the Message Loop.

    EDIT:
    Urgh, I gotta do my homework so I might be back on later tonight to help some more. Good luck mate!
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  9. #9
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    Quote Originally Posted by jmd15
    Bleh, don't even say that. I despise MFC, I'm Win32 API all the way.
    strange, your title claims you're a C++ programmer and yet you eschew a relatively clean OO interface for one of the ugliest C interfaces known to man or machine. care to explain?
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

  10. #10
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    You're referring to how I handle Win32 with C-like tendencies? Well I have to admit that I've picked up some C-style from Charles Petzold, but when it comes to other programming than Windows I'm relatively C++. Well as far off topic as that was, were you trying to doubt me due to some deep fault or shortcoming of your own or just for the fun of it? Do you really think that in THIS thread that comment was necessary? Hmm, if you really had a concern couldn't you have just PMmed me so we don't branch-off on this poor kid's topic? As for why I don't like MFC, it is because it's a strew of classes and it's just one giant mess. It isn't as readable as raw Win32 and not as neat. Are you some MFC freak and want to start an argument or something? Well if so, NOT ON THIS THREAD.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  11. #11
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    Bleh, don't even say that. I despise MFC, I'm Win32 API all the way.
    Good. Now use wxWidgets. No need to rewrite your app if your dad wants to switch to *nix!
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  12. #12
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    Quote Originally Posted by jmd15
    You're referring to how I handle Win32 with C-like tendencies? Well I have to admit that I've picked up some C-style from Charles Petzold, but when it comes to other programming than Windows I'm relatively C++. Well as far off topic as that was, were you trying to doubt me due to some deep fault or shortcoming of your own or just for the fun of it? Do you really think that in THIS thread that comment was necessary? Hmm, if you really had a concern couldn't you have just PMmed me so we don't branch-off on this poor kid's topic? As for why I don't like MFC, it is because it's a strew of classes and it's just one giant mess. It isn't as readable as raw Win32 and not as neat. Are you some MFC freak and want to start an argument or something? Well if so, NOT ON THIS THREAD.
    If I PM'd you that wouldn't really help the OP, would it? I'm not an "MFC freak" (although I have used it professionally for several years), but I DESPISE win32 with a passion, and I don't like to see it advocated to beginners.

    As jafet said, use wxWidgets. It's a much better alternative than MFC or win32
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

  13. #13
    Registered User
    Join Date
    May 2005
    Location
    Texas
    Posts
    103
    Well...do you guys can help me on my code...please...I wanna help my dad...
    Be easy on me...only 14

  14. #14
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    Well...do you guys can help me on my code...please...I wanna help my dad...
    Here's your Dad's meds GUI database. You'll have to get an icon for IDI_ICON1. Also, you'll have to finish the EDIT option.
    It doesn't actually update the Listview. So, you'll have to figure that one out. Please test thoroughly before your Dad uses it.

    Code:
    //{{NO_DEPENDENCIES}}
    // Microsoft Visual C++ generated include file.
    // Used by medicine.rc
    //
    #define IDC_DIALOG                      101
    #define IDI_ICON1                       102
    #define IDD_EDIT_DIALOG                 103
    #define IDC_LIST                        1000
    #define IDC_DELSELITEM                  1001
    #define IDC_ADD_NAME                    1002
    #define IDC_ADD_SERIAL                  1003
    #define IDC_ADDITEM                     1004
    #define IDC_SAVE                        1005
    #define IDC_ADDDESCRIPTION              1006
    #define IDC_ADD_DESCRIPTION             1007
    #define IDC_EDIT_NAME                   1008
    #define IDC_EDIT_SERIAL                 1009
    #define IDC_EDIT_DESCRIPTION            1010
    
    // Next default values for new objects
    // 
    #ifdef APSTUDIO_INVOKED
    #ifndef APSTUDIO_READONLY_SYMBOLS
    #define _APS_NEXT_RESOURCE_VALUE        109
    #define _APS_NEXT_COMMAND_VALUE         40006
    #define _APS_NEXT_CONTROL_VALUE         1014
    #define _APS_NEXT_SYMED_VALUE           101
    #endif
    #endif
    Code:
    // Microsoft Visual C++ generated resource script.
    //
    #include "resource.h"
    
    #define APSTUDIO_READONLY_SYMBOLS
    /////////////////////////////////////////////////////////////////////////////
    //
    // Generated from the TEXTINCLUDE 2 resource.
    //
    #include "afxres.h"
    
    /////////////////////////////////////////////////////////////////////////////
    #undef APSTUDIO_READONLY_SYMBOLS
    
    /////////////////////////////////////////////////////////////////////////////
    // English (U.S.) resources
    
    #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
    #ifdef _WIN32
    LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
    #pragma code_page(1252)
    #endif //_WIN32
    
    #ifdef APSTUDIO_INVOKED
    /////////////////////////////////////////////////////////////////////////////
    //
    // TEXTINCLUDE
    //
    
    1 TEXTINCLUDE 
    BEGIN
        "resource.h\0"
    END
    
    2 TEXTINCLUDE 
    BEGIN
        "#include ""afxres.h""\r\n"
        "\0"
    END
    
    3 TEXTINCLUDE 
    BEGIN
        "\r\n"
        "\0"
    END
    
    #endif    // APSTUDIO_INVOKED
    
    
    /////////////////////////////////////////////////////////////////////////////
    //
    // Dialog
    //
    
    IDC_DIALOG DIALOGEX 0, 0, 504, 142
    STYLE DS_SETFONT | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | 
        WS_SYSMENU
    CAPTION "Dad's Medicine database"
    FONT 8, "MS Sans Serif", 0, 0, 0x1
    BEGIN
        CONTROL         "List1",IDC_LIST,"SysListView32",LVS_REPORT | 
                        LVS_EDITLABELS | WS_BORDER | WS_TABSTOP,2,10,271,116
        PUSHBUTTON      "Delete Selected Item (row)",IDC_DELSELITEM,301,23,103,
                        17,0,WS_EX_STATICEDGE
        EDITTEXT        IDC_ADD_NAME,290,88,53,12,ES_AUTOHSCROLL | NOT WS_BORDER,
                        WS_EX_STATICEDGE
        EDITTEXT        IDC_ADD_SERIAL,360,88,53,12,ES_AUTOHSCROLL | NOT 
                        WS_BORDER,WS_EX_STATICEDGE
        PUSHBUTTON      "Add item",IDC_ADDITEM,290,105,44,15,0,WS_EX_STATICEDGE
        PUSHBUTTON      "Save Record(s)",IDC_SAVE,301,50,103,15,0,
                        WS_EX_STATICEDGE
        LTEXT           "Name",IDC_STATIC,292,76,43,8
        LTEXT           "Key/Serial",IDC_STATIC,360,76,43,8
        EDITTEXT        IDC_ADD_DESCRIPTION,428,88,53,12,ES_AUTOHSCROLL | NOT 
                        WS_BORDER,WS_EX_STATICEDGE
        LTEXT           "Description",IDC_STATIC,428,76,43,8
    END
    
    IDD_EDIT_DIALOG DIALOGEX 0, 0, 314, 156
    STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | 
        WS_CAPTION | WS_SYSMENU
    CAPTION "Edit dialog"
    FONT 8, "MS Shell Dlg", 400, 0, 0x1
    BEGIN
        DEFPUSHBUTTON   "Update Record",IDOK,17,123,62,14
        PUSHBUTTON      "Cancel",IDCANCEL,228,122,61,14
        LTEXT           "Name:",IDC_STATIC,27,19,24,8
        LTEXT           "Key/Serial:",IDC_STATIC,26,35,38,8
        LTEXT           "Description:",IDC_STATIC,24,54,43,8
        EDITTEXT        IDC_EDIT_NAME,75,16,214,14,ES_AUTOHSCROLL
        EDITTEXT        IDC_EDIT_SERIAL,75,34,214,14,ES_AUTOHSCROLL
        EDITTEXT        IDC_EDIT_DESCRIPTION,75,52,214,14,ES_AUTOHSCROLL
    END
    
    
    /////////////////////////////////////////////////////////////////////////////
    //
    // DESIGNINFO
    //
    
    #ifdef APSTUDIO_INVOKED
    GUIDELINES DESIGNINFO 
    BEGIN
        IDC_DIALOG, DIALOG
        BEGIN
            RIGHTMARGIN, 501
            BOTTOMMARGIN, 141
        END
    
        IDD_EDIT_DIALOG, DIALOG
        BEGIN
            LEFTMARGIN, 7
            RIGHTMARGIN, 307
            TOPMARGIN, 7
            BOTTOMMARGIN, 149
        END
    END
    #endif    // APSTUDIO_INVOKED
    
    #endif    // English (U.S.) resources
    
    
    /////////////////////////////////////////////////////////////////////////////
    //
    // Icon
    //
    
    // Icon with lowest ID value placed first to ensure application icon
    // remains consistent on all systems.
    IDI_ICON1               ICON                    "icon1.ico"
    
    
    #ifndef APSTUDIO_INVOKED
    /////////////////////////////////////////////////////////////////////////////
    //
    // Generated from the TEXTINCLUDE 3 resource.
    //
    
    
    /////////////////////////////////////////////////////////////////////////////
    #endif    // not APSTUDIO_INVOKED
    Code:
    #include <windows.h>
    #include "resource.h"
    #include <commctrl.h>
    #include <stdio.h>
    #define ENDCOLUMN 2
    #define NAMELENGTH  55
    #define SERIALLENGTH 55
    #define DESCRIPTIONLENGTH 55
    static HWND hList=NULL; 
    LVCOLUMN LvCol; 
    LVITEM LvItem;  
    LV_DISPINFO lvd;
    INT iSelect=0;
    INT iGIndex=0;
    INT iFlag=0;
    HWND hEdit;
    BOOL bEscKey=0;
    CHAR szTempStr[100];
    CHAR tchar;
    CHAR szEditNameText[NAMELENGTH];  
    CHAR szEditSerialText[SERIALLENGTH];
    CHAR szEditDescriptionText[DESCRIPTIONLENGTH];
    MSG msg;
    FILE *f;
    struct rec
    {
        CHAR name[NAMELENGTH], serial[SERIALLENGTH],description[DESCRIPTIONLENGTH];
    };
    HINSTANCE hInst; 
    
    #define WIN32_LEAN_AND_MEAN 
    
    LRESULT ProcessCustomDraw (LPARAM lParam)
    {
        LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam;
    
        switch(lplvcd->nmcd.dwDrawStage) 
        {
            case CDDS_PREPAINT : 
                return CDRF_NOTIFYITEMDRAW;
            case CDDS_ITEMPREPAINT: //Before an item is drawn
                {
                    return CDRF_NOTIFYSUBITEMDRAW;
                }
                break;
        }
        return CDRF_DODEFAULT;
    }
    BOOL CALLBACK Edit(   HWND hDlg, 
        UINT uMessage, 
        WPARAM wParam, 
        LPARAM lParam)
    {
        switch (uMessage)
        {
            case WM_INITDIALOG:
                SetDlgItemText(hDlg, IDC_EDIT_NAME, szEditNameText);
                SetDlgItemText(hDlg, IDC_EDIT_SERIAL, szEditSerialText);
                SetDlgItemText(hDlg, IDC_EDIT_DESCRIPTION, szEditDescriptionText);
                return TRUE;
            case WM_COMMAND:
                switch(wParam)
                {
                    case IDOK:
                        EndDialog(hDlg, IDOK);
                        break;
                    case IDCANCEL:
                        EndDialog(hDlg, IDCANCEL);
                        break;
                }
                return TRUE;
        } 
        return FALSE;
    }
    
    BOOL CALLBACK DialogProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
    { 
        SHFILEINFO shFileInfo;
        struct rec r = {0};
        INT iListViewCount;
        switch(Message)
        {
            case WM_CLOSE:
                {
                    PostQuitMessage(0);
                    EndDialog(hWnd,0); 
                }
                break;
            case WM_NOTIFY:
                {
                    switch(LOWORD(wParam))
                    {
                        case IDC_LIST: 
                            LPNMLISTVIEW pnm = (LPNMLISTVIEW)lParam;
    
                            if(pnm->hdr.hwndFrom == hList &&pnm->hdr.code == NM_CUSTOMDRAW)
                            {
                                SetWindowLong(hWnd, DWL_MSGRESULT, (LONG)ProcessCustomDraw(lParam));
                                return TRUE;
                            }
                            if(((LPNMHDR)lParam)->code == NM_DBLCLK)
                            {
                                INT iSlected=0;
                                iSlected=SendMessage(hList,LVM_GETNEXTITEM,-1,LVNI_FOCUSED);
                                if(iSlected==-1)
                                {
                                    MessageBox(hWnd,"No Items in ListView","Error",MB_OK|MB_ICONINFORMATION);
                                    break;
                                }
                                memset(&LvItem,0,sizeof(LvItem));
                                LvItem.mask=LVIF_TEXT;
                                LvItem.iSubItem=0;
                                LvItem.pszText=szEditNameText;
                                LvItem.cchTextMax=256;
                                LvItem.iItem=iSlected;
                                SendMessage(hList,LVM_GETITEMTEXT, iSlected, (LPARAM)&LvItem);
                                LvItem.iSubItem=1;
                                LvItem.pszText=szEditSerialText;
                                SendMessage(hList,LVM_GETITEMTEXT, iSlected, (LPARAM)&LvItem);
                                LvItem.iSubItem=2;
                                LvItem.pszText=szEditDescriptionText;
                                SendMessage(hList,LVM_GETITEMTEXT, iSlected, (LPARAM)&LvItem);
                                if(DialogBox(hInst,MAKEINTRESOURCE(IDD_EDIT_DIALOG),0,(DLGPROC)Edit) == IDOK)
                                {
                                    MessageBox(NULL, "Here's where we have to update listivew with edited data", "EDIT",MB_OK);                            
                                }
                            }
                            if(((LPNMHDR)lParam)->code == NM_CLICK)
                            {
                                iSelect=SendMessage(hList,LVM_GETNEXTITEM,-1,LVNI_FOCUSED);
                                if(iSelect==-1)
                                {                      
                                    break;
                                }
                                iGIndex=iSelect;
                                iFlag=1;
                            }
                            if(((LPNMHDR)lParam)->code == LVN_BEGINLABELEDIT)
                            {
                                hEdit=ListView_GetEditControl(hList);
                                GetWindowText(hEdit, szTempStr, sizeof(szTempStr));
                            }
                            if(((LPNMHDR)lParam)->code == LVN_ENDLABELEDIT)
                            {
                                INT iIndex;
                                CHAR szText[255]={0};
                                tchar = (TCHAR)msg.wParam;
                                if(tchar == 0x1b)
                                    bEscKey=1;
                                iIndex=SendMessage(hList,LVM_GETNEXTITEM,-1,LVNI_FOCUSED);
                                if(iIndex==-1)
                                    break;
                                LvItem.iSubItem=0;
                                if(bEscKey==0)
                                {
                                    LvItem.pszText=szText; 
                                    GetWindowText(hEdit, szText, sizeof(szText));
                                    SendMessage(hList,LVM_SETITEMTEXT,(WPARAM)iIndex,(LPARAM)&LvItem);
                                }
                                else{
                                    LvItem.pszText=szTempStr;
                                    SendMessage(hList,LVM_SETITEMTEXT,(WPARAM)iIndex,(LPARAM)&LvItem);
                                    bEscKey=0;
                                }
                            }
                            break;
                    }
                }
            case WM_PAINT:
                {
                    return 0;
                }
                break;
            case WM_INITDIALOG:
                {
                    InitCommonControls();
                    hList=GetDlgItem(hWnd,IDC_LIST);                
                    SendMessage(hList,LVM_SETTEXTBKCOLOR, 0,(LPARAM)CLR_NONE);
                    SendMessage(hList,LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_FULLROWSELECT); // Set style
                    SendMessageA(hWnd,WM_SETICON,(WPARAM) 1,(LPARAM) LoadIconA(hInst,MAKEINTRESOURCE(IDI_ICON1)));
                    memset(&LvCol,0,sizeof(LvCol)); 
                    LvCol.mask=LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM; 
                    LvCol.cx=0x28;                                
                    LvCol.pszText="Name";                     
                    LvCol.cx=0x42;
                    SendMessage(hList,LVM_INSERTCOLUMN,0,(LPARAM)&LvCol); 
                    LvCol.pszText="Key/Serial";                          
                    SendMessage(hList,LVM_INSERTCOLUMN,1,(LPARAM)&LvCol); 
                    LvCol.pszText="Description";                       
                    SendMessage(hList,LVM_INSERTCOLUMN,2,(LPARAM)&LvCol); 
                    memset(&LvItem,0,sizeof(LvItem)); 
                    if (SHGetFileInfo((LPCSTR)"medicine.txt", 0,&shFileInfo, sizeof(SHFILEINFO),SHGFI_TYPENAME) != 0)
                    {
                        f = fopen("medicine.txt", "r"); 
                        iGIndex = 0;
                        while(fread(&r, sizeof(r), 1, f) == 1)
                        {
                            LvItem.mask=LVIF_TEXT;   
                            LvItem.cchTextMax = 256; 
                            LvItem.iItem=iGIndex;          
                            LvItem.iSubItem=0;       
                            LvItem.pszText=r.name; 
                            SendMessage(hList,LVM_INSERTITEM,0,(LPARAM)&LvItem); 
                            LvItem.iSubItem=1;
                            LvItem.pszText=r.serial;
                            SendMessage(hList,LVM_SETITEM,0,(LPARAM)&LvItem); 
                            LvItem.iSubItem=2;
                            LvItem.pszText=r.description;
                            SendMessage(hList,LVM_SETITEM,0,(LPARAM)&LvItem); 
                            ++iGIndex;
                        }
                        fclose(f);
                    }
                    ShowWindow(hWnd,SW_NORMAL); 
                    UpdateWindow(hWnd); 
                    while(TRUE)
                    {
                        if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
                        {   
                            if(msg.message==WM_QUIT)
                            {
                                break;
                            }
                            TranslateMessage(&msg);
                            DispatchMessage(&msg);
                        }                   
                    }
                }
                break;
            case WM_COMMAND:
                {
                    switch(LOWORD(wParam)) 
                    {
                        case IDC_SAVE:
                            iListViewCount = ListView_GetItemCount(hList);
                            f=fopen("medicine.txt","w");
                            if (!f)
                                break;
                            for (iGIndex =0;iGIndex <iListViewCount ; iGIndex++)
                            {
                                ListView_GetItemText(hList, iGIndex, 0, r.name, NAMELENGTH-1);
                                ListView_GetItemText(hList, iGIndex, 1, r.serial,SERIALLENGTH-1);
                                ListView_GetItemText(hList, iGIndex, 2, r.description,DESCRIPTIONLENGTH-1);
                                fwrite(&r,sizeof(struct rec),1,f);
                            }
                            break;
                        case IDC_ADDITEM:
                            {
                                INT iItem;
                                CHAR NameText[NAMELENGTH] = {0};
                                CHAR SerialText[SERIALLENGTH] = {0};
                                CHAR DescriptionText[DESCRIPTIONLENGTH] = {0};
                                iItem=SendMessage(hList,LVM_GETITEMCOUNT,0,0);
    
                                GetDlgItemText(hWnd,IDC_ADD_NAME,NameText,NAMELENGTH-1);
    
                                if((lstrlen(NameText))==0)
                                {
                                    MessageBox(hWnd,"Please Enter Some Text for Name","Error",MB_OK|MB_ICONINFORMATION);
                                    break;
                                }
                                GetDlgItemText(hWnd,IDC_ADD_SERIAL,SerialText,SERIALLENGTH-1);
    
                                if((lstrlen(SerialText))==0)
                                {
                                    MessageBox(hWnd,"Please Enter Some Text for Serial","Error",MB_OK|MB_ICONINFORMATION);
                                    break;
                                }
                                GetDlgItemText(hWnd,IDC_ADD_DESCRIPTION,DescriptionText,DESCRIPTIONLENGTH-1);
    
                                if((lstrlen(DescriptionText))==0)
                                {
                                    MessageBox(hWnd,"Please Enter Some Text for Description","Error",MB_OK|MB_ICONINFORMATION);
                                    break;
                                }
                                LvItem.mask= LVIF_TEXT;
                                LvItem.iItem=iItem;            
                                LvItem.iSubItem=0;         
                                LvItem.pszText=NameText;   
                                SendMessage(hList,LVM_INSERTITEM,0,(LPARAM)&LvItem); 
                                LvItem.pszText=SerialText;   
                                LvItem.iSubItem=1;         
                                SendMessage(hList,LVM_SETITEM,0,(LPARAM)&LvItem);
                                LvItem.pszText=DescriptionText;   
                                LvItem.iSubItem=2;         
                                SendMessage(hList,LVM_SETITEM,0,(LPARAM)&LvItem);
                            }
                            break;
                        case IDC_DELSELITEM:
                            if(iFlag)
                                SendMessage(hList,LVM_DELETEITEM,iSelect,0);
                            iFlag=0;
                            break;
                    }
                }
                break;
            default:
                {
                    return FALSE;
                }
        }
        return TRUE;
    }
    
    
    INT WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, INT iCmdShow)
    {
         INITCOMMONCONTROLSEX InitCtrls;
         InitCtrls.dwICC = ICC_LISTVIEW_CLASSES;
          InitCtrls.dwSize = sizeof(INITCOMMONCONTROLSEX);
          BOOL bRet = InitCommonControlsEx(&InitCtrls);
    
        hInst=hInstance;
        DialogBoxParam(hInstance, MAKEINTRESOURCE(IDC_DIALOG), NULL, (DLGPROC)DialogProc,0);
        return 0;
    }

  15. #15
    Registered User
    Join Date
    May 2005
    Location
    Texas
    Posts
    103
    Ah...Thanks Bob!!! I'll plug that right in... thankyou for responding, and thankyou for writing all that...
    Be easy on me...only 14

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Making a program run on startup
    By Poincare in forum C Programming
    Replies: 10
    Last Post: 06-21-2009, 12:50 PM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Making interest rate program in C
    By canadas321 in forum C Programming
    Replies: 6
    Last Post: 06-23-2005, 11:59 AM
  5. I need help with making a program which....
    By Tonyukuk in forum C# Programming
    Replies: 1
    Last Post: 04-16-2003, 10:49 PM

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