Need hel with tabs

Pages: 12
Scroll all the way down to the bottom.
Last edited on
You can't pass a std::string to GetWindowText(). Just create a temporary something like this:

1
2
3
char tmp[MAX_PATH+1] = {0};
GetDlgItemText(hwndDlg,Save,tmp,MAX_PATH); // this is your text control hence where you want to grab the text from if I'm reading your post right
...


I tried that, and it worked but its not saving my text. I did this:

main.cpp:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "resource.h"
#include <fstream>
#include <string>

using namespace std;

HINSTANCE hInst;

BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{


    switch(uMsg)
    {
        case WM_INITDIALOG:
            /*
             * TODO: Add code to initialize the dialog.
             */
            return TRUE;

        case WM_CLOSE:

            EndDialog(hwndDlg, 0);
            return TRUE;

        case WM_COMMAND:

            switch(LOWORD(wParam))
            {
                case Save:
                    ofstream file("save.txt");

                    file << MAX_PATH;
            }

            char tmp[MAX_PATH+1] = {0};
            GetDlgItemText(hwndDlg, Save, tmp, MAX_PATH);

    }

    return FALSE;
}


int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
    hInst = hInstance;

    // The user interface is a modal dialog box
    return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DialogProc);
}



Now, in the file << part, i have put tmp, MAX_PATH and Save, and it didnt save any of my text. I would get the number 1 or 260 or Save in my file.txt file when i opened it. I was thinking about using flush but i dont want random text in my program file output. what is going wrong with this?
MAX_PATH is an integer value defined in windows headers, and it doesn't contain the text. The text is in tmp array.
This should work:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
case WM_COMMAND:

            switch(LOWORD(wParam))
            {
                case Save:
                    ofstream file("save.txt");

                    char tmp[MAX_PATH+1] = {0};
                    GetDlgItemText(hwndDlg, Save, tmp, MAX_PATH);      
            
                    file << tmp;

                    file.close(); // don't forget to close the file
                    break;
            }
    }
Last edited on
I tried that, and when i open up my file.txt, the only word in there is Save. ???
Oh, my bad. Save is an ID of a button, right?
Since you have defined text in resource.h, yous should assign it to your EDITTEXT control
EDITTEXT text, 0, 0, 300, 150, ES_MULTILINE | ES_WANTRETURN | ES_AUTOHSCROLL | ES_AUTOVSCROLL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
case WM_COMMAND:

            switch(LOWORD(wParam))
            {
                case Save:
                    ofstream file("save.txt");

                    char tmp[MAX_PATH+1] = {0};
                    GetDlgItemText(hwndDlg, text, tmp, MAX_PATH);  
            
                    file << tmp;

                    file.close(); // don't forget to close the file
                    break;
            }
    }
when i do that my text box disappears???? I have tried something like this in the past and had some pretty wacky results. Once a line was drawn through my text field, and another time the box had no border, im not sure why but naming the EDITTEXT control screws it up.
textbox->text?
textbox.text?
??????????
The problem is that i cant name this line:

EDITTEXT 3, 0, 0, 300, 150, ES_MULTILINE | ES_WANTRETURN | ES_AUTOHSCROLL | ES_AUTOVSCROLL

so im confused as to how i would be able to get the text from the textbox?
Sorry I didn't read your post thoroughly enough the first time. Looks like you are assigning an id of 3 to your text box so try:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
case WM_COMMAND:

            switch(LOWORD(wParam))
            {
                case Save:
                    ofstream file("save.txt");

                    char tmp[MAX_PATH+1] = {0};
                    GetDlgItemText(hwndDlg, 3, tmp, MAX_PATH);  
            
                    file << tmp;

                    file.close(); // don't forget to close the file
                    break;
            }
    }
i forgot all about that ID, i forgot and thought it was part of placement or size :P but yeah it works fine now. I'll have to remember the ID number next time. Thanks for the help.

oh and Is there any way to make the window unsizeable?
Last edited on
Yes. For example you could use following style:
DS_SETFONT | DS_FIXEDSYS | WS_MINIMIZEBOX | WS_CAPTION | WS_SYSMENU

Read MSDN for each style description.
None of those made it so the window cant be re-sized, and i did read MSDN just now and i didnt see anything about making the window Un-resizeable. this is the page i read, maybe its on a different page?

http://msdn.microsoft.com/en-us/library/windows/desktop/ms632600(v=vs.85).aspx

What i want to do is make it so the boarder around the window cant be grabbed and re-sized.
Last edited on
The styles I give you are from a working program, did you delete whatever styles you have before ? You MUST use only these styles, not leave others too.

By default (if you don't use any style at all) a dialog window cannot be resized.
Last edited on
Ok i see now, it was that one that was there when the program was created STYLE 0x10CE0804.

I deleted it and it works thanks!! Now, for my final question, how do i create tabbed windows? I want to put different things in different windows, but i havent figured it out. I know of the WC_TABCONTROL word but i dont know how to set it up. I looked on MSDN but it doesnt really show you how it just tells you. I need to see a working example. I have a tab example on my PC but its done wothout Resource controls so its more complicated than i want to get into right now.
Last edited on
Please help
I coded up a quick example of a tab control:

- resource.rc -
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "resource.h"

DLG_MAIN DIALOGEX 10,10,500,300
CAPTION "Tab Control Example"
STYLE WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX
BEGIN
  CONTROL "",TAB_MAIN,"SysTabControl32",WS_CHILD|WS_VISIBLE|TCS_FOCUSNEVER,5,5,490,290
END

TAB_ONE DIALOGEX 10,20,470,260
STYLE WS_VISIBLE|WS_CHILDWINDOW
BEGIN
  CONTROL "This is tab one",MSG_ONE,"Static",WS_CHILD|WS_VISIBLE|SS_CENTERIMAGE|SS_CENTER,0,0,470,260,WS_EX_CLIENTEDGE
END

TAB_TWO DIALOGEX 10,20,470,260
STYLE WS_VISIBLE|WS_CHILDWINDOW
BEGIN
  CONTROL "This is tab two",MSG_TWO,"Static",WS_CHILD|WS_VISIBLE|SS_CENTERIMAGE|SS_CENTER,0,0,470,260,WS_EX_CLIENTEDGE
END


- resource.h -
1
2
3
4
5
6
7
8
#include <windows.h>

#define DLG_MAIN           1000
#define TAB_MAIN           1100
#define TAB_ONE            1101
#define MSG_ONE            1102
#define TAB_TWO            1201
#define MSG_TWO            1202 


- main.cpp -
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#define WIN32_LEAN_AND_MEAN

#include "resource.h"
#include <commctrl.h>

HINSTANCE hInst; // main window instance
HWND hTabControl; // tab control handle
HWND hCurrentTab; // tab dialog handle

BOOL CALLBACK DlgProc(HWND H,UINT M, WPARAM W, LPARAM L)
{
  switch(M)
  {
    case WM_INITDIALOG:
    {
      INITCOMMONCONTROLSEX ix;
      ix.dwSize = sizeof(INITCOMMONCONTROLSEX);
      ix.dwICC = ICC_TAB_CLASSES;
      InitCommonControlsEx(&ix); // have to run this to use tab control
      hTabControl = GetDlgItem(H,TAB_MAIN);
      TCITEM ti;
      ti.mask = TCIF_TEXT; // I'm only having text on the tab
      ti.pszText = "Tab One";
      TabCtrl_InsertItem(hTabControl,0,&ti);
      ti.pszText = "Tab Two";
      TabCtrl_InsertItem(hTabControl,1,&ti);
      TabCtrl_SetCurSel(hTabControl,0);
      hCurrentTab = CreateDialog(hInst,MAKEINTRESOURCE(TAB_ONE),hTabControl,0); // Setting dialog to tab one by default
      return TRUE;
    }
    case WM_CLOSE:
    {
      EndDialog(H,0);
      return TRUE;
    }
    case WM_NOTIFY:
    {
      switch(((LPNMHDR)L)->code)
      {
        case TCN_SELCHANGING: // message sent because someone changed the tab selection (clicked on another tab)
        {
          EndDialog(hCurrentTab,0); // we don't want the current tab, kill it
          if(TabCtrl_GetCurSel(hTabControl) == 0) // current selection was tab 1, so new has to be tab 2 (we only have 2 tabs)
          {
            hCurrentTab = CreateDialog(hInst,MAKEINTRESOURCE(TAB_TWO),hTabControl,0); // create dialog for tab 2
          } else {
            hCurrentTab = CreateDialog(hInst,MAKEINTRESOURCE(TAB_ONE),hTabControl,0); // create dialog for tab 1
          }
          return TRUE;
        }
      }
      return TRUE;
    }
    case WM_COMMAND:
    {
      return TRUE;
    }
  }
  return FALSE;
}


int APIENTRY WinMain(HINSTANCE I, HINSTANCE PI, LPSTR CL, int SC)
{
  hInst = I;
  return DialogBox(I,MAKEINTRESOURCE(DLG_MAIN),0,DlgProc);
}
I get these errors?

I copied it exactly from your post.

C:\Users\Chay Hawk\Desktop\Tabs\main.cpp||In function 'BOOL DlgProc(HWND__*, UINT, WPARAM, LPARAM)':|
C:\Users\Chay Hawk\Desktop\Tabs\main.cpp|15|error: 'INITCOMMONCONTROLSEX' was not declared in this scope|
C:\Users\Chay Hawk\Desktop\Tabs\main.cpp|15|error: expected ';' before 'ix'|
C:\Users\Chay Hawk\Desktop\Tabs\main.cpp|16|error: 'ix' was not declared in this scope|
C:\Users\Chay Hawk\Desktop\Tabs\main.cpp|18|error: 'InitCommonControlsEx' was not declared in this scope|
C:\Users\Chay Hawk\Desktop\Tabs\main.cpp|22|warning: deprecated conversion from string constant to 'CHAR*'|
C:\Users\Chay Hawk\Desktop\Tabs\main.cpp|24|warning: deprecated conversion from string constant to 'CHAR*'|
||=== Build finished: 4 errors, 2 warnings ===|


Im not positive what some of the code means, some things are completley new to me but i'll worry about those when i figure this out.
Last edited on
It means your compiler is not accurately recognizing your version of Windows/IE. In the commctrl.h header it has these checks. Try adding this to the top of the code:

1
2
#define _WIN32_IE 0x0900
#define _WIN32_WINNT 0x0900 


Pages: 12