I don't know why but whenever i use SetWindowText() in the case statement for my menu, it doesn't work..
heres my code:
//Include our include file
#include "resource.h"
#include "includes.h"
//about dialog window
BOOL CALLBACK dgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_INITDIALOG:
return TRUE;
break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
EndDialog(hwnd, IDOK);
break;
}
default:
return FALSE;
}
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
//create
case WM_CREATE:
//somevariables
HWND edit;
//create our edit control
edit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "",
WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL,
0, 0,
100, 100,
hwnd,
(HMENU)E,
GetModuleHandle(NULL),
NULL);
break;
//resize
case WM_SIZE:
edit = GetDlgItem(hwnd, E);
SetWindowPos(edit, NULL, 0, 0, LOWORD(lParam), HIWORD(lParam), SWP_NOZORDER);
break;
//close
case WM_CLOSE:
PostQuitMessage(0);
break;
//menu
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDM_ABOUT:
DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOG1), hwnd, dgProc);
break;
case IDM_OPEN:
//set ofn to open
win.ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
//open diaolog
GetOpenFileName(&win.ofn);
//load file
LoadTXT(edit, win.fileStr);
break;
case IDM_EXIT3:
PostQuitMessage(0);
}
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR cmd, int show) {
//make the window
win.makeWindow(hInstance, "G - Text");
//show the window
win.showWindow(show);
//Message loop
while(GetMessage(&win.msg, NULL, 0, 0) > 0)
{
TranslateMessage(&win.msg);
DispatchMessage(&win.msg);
}
}
and heres the loadTXT function
//here is some misc functions
//load text file
bool LoadTXT(HWND edit, char* FileName) {
//create file handle
FILE *file;
file = fopen(FileName, "r");
long size;
char *buffer;
//make char buffer
fseek(file, 0, SEEK_END);
size = ftell(file);
//go back to start of file
rewind(file);
//allocate size of array
buffer = (char*)malloc (sizeof(char) * size);
//load text into string
fread(buffer, sizeof(char), size, file);
//put text in text box
SetWindowText(edit, buffer);
}
Any idea why it's not working?