no createwindow 2nd time around

my listbox works over and over (clicking OK) until I add the menu. When I add the menu, I get a listbox window the first call, then no more window. the "SetMenu(htextBox,NULL);" will allow the window to be re-displayed but with a screwed up menu.

I have tried:
DestroyWindow(htextBox);
PostMessage(htextBox, WM_CLOSE, 0, 0);
DestroyMenu(htextboxMenu);
different ways to add a menu.

What am I missing to get the listbox with menu to reappear?


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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
void fill_listbox(HWND hWnd)
	{
//PostMessage(WM_NULL);
		if (file_selected == false)
		{
			int msgboxID = MessageBox(NULL,("No File Selected "),("Error Window"),MB_OK);
			return ;
		}
			
			String ^ a = gcnew String("");
			htextBox = CreateWindow(
				("listbox"),
				NULL,
				WS_SYSMENU | WS_VISIBLE | WS_VSCROLL,
				150,
				100,
				300,
				670,
				hWnd,
				htextboxMenu,//IDC_LISTBOX,
				GetModuleHandle(NULL),//hInstance,
				NULL);
		
				SendMessage(htextBox, LB_RESETCONTENT, 0, 0);
				//AppendMenu(htextboxMenu, MF_POPUP ,501,"CUT"); 
				//AppendMenu(htextboxMenu, MF_POPUP ,502,"COPY"); 
				//AppendMenu(htextboxMenu, MF_POPUP ,503,"PASTE");
				//AppendMenu(htextboxMenu, MF_POPUP ,504,"SEARCH/REPLACE"); 
				//AppendMenu(htextboxMenu, MF_POPUP ,504,"UNDO"); 
				//AppendMenu(htextboxMenu, MF_STRING, 222, "E&xit");
				//AppendMenu(htextboxMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&File");
				if (!htextBox)
				{
				DWORD dw = GetLastError(); 

					printf("error creating window %i \n",dw);
				}
		//GetLastError(void);
	MENUITEMINFO mii;
	memset(&mii, 0, sizeof(MENUITEMINFO));

	mii.cbSize	= (UINT)		sizeof(MENUITEMINFO);
	mii.fMask = MIIM_STRING | MIIM_STATE | MIIM_STRING;
	mii.fType = MIIM_STRING;
	mii.fState	= (UINT)		MFS_DEFAULT | MFS_ENABLED;
	mii.dwTypeData	= (LPTSTR)		TEXT("File");
	mii.cch		= (UINT)		4;
	InsertMenuItem(htextboxMenu, 0, TRUE, (LPCMENUITEMINFO) &mii);

	mii.cbSize	= (UINT)		sizeof(MENUITEMINFO);
mii.fMask = MIIM_STRING | MIIM_STATE | MIIM_STRING;
	mii.fType = MIIM_STRING;
	mii.fState	= (UINT)		MFS_ENABLED;
	mii.dwTypeData	= (LPTSTR)		TEXT("Edit");
	mii.cch		= (UINT)		4;
	InsertMenuItem(htextboxMenu, 1, TRUE, (LPCMENUITEMINFO) &mii);

	mii.cbSize	= (UINT)		sizeof(MENUITEMINFO);
mii.fMask = MIIM_STRING | MIIM_STATE | MIIM_STRING;
	mii.fType = MIIM_STRING;
	mii.fState	= (UINT)		MFS_ENABLED;
	mii.dwTypeData	= (LPTSTR)		TEXT("Vitttttew");
	mii.cch		= (UINT)		4;
	InsertMenuItem(htextboxMenu, 2, TRUE, (LPCMENUITEMINFO) &mii);
	
	SetMenu(htextBox, htextboxMenu);
	DrawMenuBar(htextBox);
				long begin,end;
				int size;
				std::string lineBuffer;
				std::string temp_string;
				temp_string = "";
				std::ifstream inputFile(ofn.lpstrFile);
			int file_index = 0;
		if(inputFile.good())
			{
			  while(std::getline(inputFile,lineBuffer))
				  {	
					SendMessage(htextBox, LB_ADDSTRING,0,(LPARAM)lineBuffer.c_str());
					file_index++;
				  }
			}//end if

				inputFile.clear();
				inputFile.close();



										int msgboxID = MessageBox(NULL,("RUN this program ?"),("Run Window"),MB_ICONQUESTION | MB_OKCANCEL | MB_DEFBUTTON2);

										switch (msgboxID)
											{
	 								case IDOK://
										
										SendMessage(htextBox, LB_RESETCONTENT, 0, 0);
										//DestroyMenu(htextboxMenu);		
												//SetForegroundWindow(htextBox);
												PostMessage(htextBox, WM_CLOSE, 0, 0);
												SetMenu(htextBox,NULL);										
												//DestroyWindow(htextBox);
												a = gcnew String (ofn.lpstrFile);
												parse_main_success = parse_main(a);
											if (parse_main_success == 1)
												{
													part_is_ready = true;
													redraw_permitted = false;
												}
											else
											{
													MessageBox(hWnd, ("END OF PROGRAM (M30) NOT FOUND"), ("PROGRAM ERROR"), MB_ICONERROR);
											}
												ignore_mouse = true;
												SendMessage(htextBox, LB_RESETCONTENT, 0, 0);
												DestroyWindow(htextBox);								
												redraw_permitted = false;

												break;

											case IDCANCEL:
												//PostQuitMessage(0);
												SendMessage(htextBox, LB_RESETCONTENT, 0, 0);
												DestroyWindow(htextBox);

												selection_canceled = false;		
												ignore_mouse = true;
												redraw_permitted = true;
												//DestroyWindow(hlistBox);
																					
										
												break;
/*											case IDCONTINUE:
												ignore_mouse = true;
												DestroyWindow(htextBox);
												redraw_permitted = false;
												break;								*/																	
											}// end switch (msgboxID)
											ignore_mouse = true;
											PostMessage(htextBox, WM_CLOSE, 0, 0);
	}//end fill_listbox 
It looks like you are giving the Listbox and the menu the same ID's.
This is what you have.
1
2
3
4
5
6
7
8
9
10
htextBox = CreateWindow(
  ("listbox"),
  NULL,
  WS_SYSMENU | WS_VISIBLE | WS_VSCROLL,
  150,
  100,
  300,
  670,
  hWnd,
  htextboxMenu,//IDC_LISTBOX,  
//Error here in particular.

Later on you have:
InsertMenuItem(htextboxMenu, 0, TRUE, (LPCMENUITEMINFO) &mii);


maybe what you meant was:
1
2
3
4
5
6
7
8
9
10
htextBox = CreateWindow(
  ("listbox"),
  NULL,
  WS_SYSMENU | WS_VISIBLE | WS_VSCROLL,
  150,
  100,
  300,
  670,
  hWnd,
  (HMENU)IDC_LISTBOX,   //************* 


I assume htextboxMenu is an actual handle to a memu created using CreateMenu somewhere in your code (but not shown in the post)

Can Listboxes have menus anyway??????
Shouldn't you be setting the menu to the Main Window.
It all seems so wrong to me..
Last edited on
the declaration is HMENU htextboxMenu = CreateMenu();
I have added the letters "Menu" to the ID "htextBox" to create a different Id for the menu. Is this causing my problem?
A listbox could not have menus. If you want a right click context menu use CreatePopupMenu(), then add your items to this.
ooops; Thanks to both of you for the wake-up.

I originally used an "EDIT" control, but was disappointed by the time to load a text file. The load time for the "listbox"was almost instant. That is why I tried the listbox. Perhaps I am loading a text file incorrectly. Please excuse my knowledge of C++ and WIN32.
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
	long begin,end;
	int size;
	std::string lineBuffer;
	std::string temp_string;
	temp_string = "";
	std::ifstream inputFile(ofn.lpstrFile);
	begin = inputFile.tellg();
	inputFile.seekg (0, ios::end);
	end = inputFile.tellg();
	inputFile.seekg (0, ios::beg);
	size = end - begin;
	memblock = new char [size];
	inputFile.read (memblock, size);
	inputFile.close();
	int file_index = 0;
 
	for (int counter = 0;	counter < size; counter++)
		{
			temp_string = temp_string +memblock[counter];
				if (memblock[counter]== 10)
				{
					SendMessage (htextBox, EM_REPLACESEL, 0, (LPARAM)temp_string.c_str());//works so so 
					SendMessage (htextBox, EM_REPLACESEL, 0, (LPARAM)"\r\n ");
		
					temp_string = "";
				}
		}

I am using "SendMessage (htextBox, EM_REPLACESEL, 0, (LPARAM)"\r\n ");"
for the linefeeds.
Is there another way to load a text file other than what I have here(one char at a time)?

An actual file is below

%
O0001
(P2 111-040511)
(MATERIAL: MILD STEEL)
(THICK: 0.048in)
(SHEETSIZE: 96 X 48)
G91G28Z0.
G28X0.Y0.
G90G54
G90
G64
G52X66.8462Y1.9157
M98P1106
G90
N48
G52X71.8008Y1.9157
M98P1106
G90
G52X0.Y0.
G01G40
G91G00G28Z0.
G0G28X0.Y0.
M30

O1106
G01G40
(PART: MZ-73256-017 REV 0)
N1
G00X4.7586Y-.092
M98P5050
M98P5051
G90
G01Y-.0184
M98P5051
G90
G01G42D5X4.7546Y0.
G01Y1.437
G03X4.6296Y1.562I-.125J0.
G01X.125
G03X0.Y1.437I0.J-.125
G01Y0.
M23
G04X.1
M22
G01X4.7246
G00 X20.0Y30.0
G01 X22.00
G02 X22.00Y30.0I0.00J20.0
G01 X5.00Y30.0
G02 X10.0Y40.0I-10.0J-5.0
G40
M98P9001
G90
M99
%

Why do you need to insert your own CRLF every time ? Original file does not already contain them ?

You can send full text once to the multiline edit control. Make sure that you have ES_WANTRETURN style.
http://msdn.microsoft.com/en-us/library/windows/desktop/bb775464%28v=vs.85%29.aspx
Topic archived. No new replies allowed.