Winapi fuktioniert nicht unter xp
-
hallo erstmal,
ich denke mal ich habe ausversehen etwas eingebaut was erst ab vista funktioniert aber leider nicht finden
können vielleicht eure adleraugen etwas eher erkennen?
ich weis es ist noch grauenhaft das ich alles in einer datei habe, aber ich experimentier noch stark herum.#include <windows.h> #include <stdio.h> #include <iostream> #include <string> #include <sstream> #include <fstream> #include <objbase.h> using namespace std; #define ID_BUTTONSTART 101 #define ID_SPLITBUTTONSTART 201 #define ID_RADIOBUTTONSTART 301 #define ID_CHECKBOXSTART 401 #define BUTTON_START 10 #define BUTTON_NAME 9 #define RADIO_NAME 9 #define CHECKBOX_NAME 9 #define MAX_BUTTONS 4 #define MAX_CHECKBOX 2 #define MAX_RADIOBUTTON 3 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); void CreateMenubar(HWND); void OpenDialog(HWND); void LoadFile(LPSTR); HWND hButtonBar[MAX_BUTTONS]; int HIGH=0 , WIDTH=0; const int MAX_CHARS_PER_LINE = 512; const int MAX_TOKENS_PER_LINE = 30; const char* const DELIMITER = ";"; ifstream fin; int W_HIGH = 350; int W_WIDTH = 400; string text1 = "Eins"; string text2 = "Zwei"; string text3 = "Drei"; string text4 = "Vier"; int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static TCHAR const szAppName[] = TEXT("Test"); HWND hWnd, hCheckboxBar[MAX_CHECKBOX],hRadioBar[MAX_RADIOBUTTON]; MSG msg; WNDCLASSEX wndclassex; WNDCLASSW wc = {0}; HINSTANCE hInst; RECT rcClient; char button_name[100][BUTTON_NAME]; char checkbox_name[100][CHECKBOX_NAME]; char radio_name[100][RADIO_NAME]; int m=0; memset(button_name, NULL, sizeof button_name); memset(checkbox_name, NULL, sizeof checkbox_name); memset(radio_name, NULL, sizeof radio_name); // program parameter wndclassex.cbSize = sizeof (WNDCLASSEX); wndclassex.style = CS_HREDRAW | CS_VREDRAW; wndclassex.lpfnWndProc = &WndProc; wndclassex.cbClsExtra = 0; wndclassex.cbWndExtra = 0; wndclassex.hInstance = hInstance; wndclassex.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndclassex.hCursor = LoadCursor(NULL, IDC_ARROW); wndclassex.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wndclassex.lpszMenuName = NULL; wndclassex.lpszClassName = szAppName; wndclassex.hIconSm = wndclassex.hIcon; // message: can't register the Process if (!RegisterClassEx(&wndclassex)){ MessageBox(NULL, TEXT("RegisterClassEx fehlgeschlagen!"), szAppName, MB_OK | MB_ICONERROR); return -1; } //Creating the Window hWnd = CreateWindowEx( WS_EX_ACCEPTFILES, // extendet window style szAppName, // name of window class TEXT("DDS - Daon Data Systems GmbH"), // window title WS_TILEDWINDOW| WS_TABSTOP, // window style CW_USEDEFAULT, // x-position of the window CW_USEDEFAULT,// y-position of the window W_WIDTH, // window width W_HIGH, // window high NULL, // upper windows NULL, // menu hInstance, // program ID NULL); // additional parameters //creating Checkbox GetClientRect(hWnd, &rcClient); int nButtonWidth = rcClient.right /10; int nButtonHeight = rcClient.bottom /10; int b=0; fin.open("GUI.txt"); // open a file // read each line of the file while (!fin.eof()) { // parse the line into blank-delimited tokens int n = 0; // a for-loop index // array to store memory addresses of the tokens in buf const char* token[MAX_TOKENS_PER_LINE] = {0}; // initialize to 0 // read an entire line into memory char buf[MAX_CHARS_PER_LINE]; fin.getline(buf, MAX_CHARS_PER_LINE); // parse the line token[0] = strtok(buf, DELIMITER); // first token if (token[0]) // zero if line is blank { for (n = 1; n < MAX_TOKENS_PER_LINE; n++){ token[n] = strtok(0, DELIMITER); // subsequent tokens if (!token[n]) break; // no more tokens } } // process (print) the tokens for (int i = 0; i < n ; i++){ // n = #of tokens if(strcmp (token[i], "ANZ_BUTTONS") == 0){ W_WIDTH = int(token[i]); } if(strcmp (token[i], "ANZ_CHKBOX") == 0){ W_WIDTH = int(token[i]); } if(strcmp (token[i], "Anz_RADIO") == 0){ W_WIDTH = int(token[i]); } if(strcmp (token[i], "MENU") == 0){ i++; strcpy(button_name[m], token[i]); m++; } else if(strcmp (token[i], "END_BUT") == 0){ m=0; } else if(strcmp (token[i], "RADIO")== 0){ i++; strcpy(radio_name[m],token[i]); m++; } else if(strcmp (token[i], "END_RAD") == 0){ m=0; } else if(strcmp (token[i], "CHKBOX")== 0){ i++; strcpy(checkbox_name[m],token[i]); m++; } else if(strcmp (token[i], "END_CHK") == 0){ m=0; } } } for (int i = 0; i < MAX_BUTTONS; i++){ char szButtonName[25]; sprintf_s(szButtonName, button_name[i]); hButtonBar[i] = CreateWindowEx(0, "BUTTON", szButtonName, WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|WS_TABSTOP, 15, 20+i*29, 130, 25, hWnd, (HMENU) ID_BUTTONSTART + i, hInstance, NULL); } for (int i = 0; i < MAX_CHECKBOX; i++){ char szButtonName[25]; sprintf_s(szButtonName, checkbox_name[i]); hCheckboxBar[i] = CreateWindowEx(0, "BUTTON", szButtonName, BS_AUTOCHECKBOX | WS_CHILD| WS_VISIBLE| BS_PUSHBUTTON|WS_TABSTOP, 150, 20+i*25, 130, 25, hWnd, (HMENU) ID_CHECKBOXSTART + i, hInstance, NULL); } for (int i = 0; i < MAX_RADIOBUTTON; i++){ char szButtonName[25]; sprintf_s(szButtonName, radio_name[i]); hRadioBar[i] = CreateWindowEx(0, "BUTTON", szButtonName, BS_AUTORADIOBUTTON | WS_CHILD| WS_VISIBLE|WS_TABSTOP, 280, 20+i*25, 130, 25, hWnd, (HMENU) ID_RADIOBUTTONSTART + i, hInstance, NULL); } ShowWindow(hWnd, iCmdShow); for (;;) //loop to share the messages { int ret = GetMessage(&msg, NULL, 0, 0); if (ret == -1) return -1; else if (ret == 0) break; TranslateMessage(&msg); DispatchMessage(&msg); UpdateWindow(hWnd); } UnregisterClass(szAppName, hInstance); return (int)msg.wParam; } // Main massageloop LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; static HWND hwndButton, hwndEdit, combo_hwnd; HINSTANCE hInstance; switch (message) { case WM_PAINT: hdc = BeginPaint(hWnd, &ps); TextOut(hdc, 10, 0, TEXT("Bitte wählen sie das Menu aus"), 29); //Edit Window hwndEdit = CreateWindowEx (1, "edit", "Eingabe hier", WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL, 10,210, 150, 25, hWnd, (HMENU)10,(HINSTANCE) GetWindowLong (hWnd, GWL_HINSTANCE), NULL); //combobox combo_hwnd = CreateWindowEx(0x0,"ComboBox","", CBS_SIMPLE | CBS_DROPDOWN | CBS_DROPDOWNLIST | WS_VSCROLL | CBS_HASSTRINGS | WS_CHILD | WS_VISIBLE, 180,210,150,25,hWnd,(HMENU)11,(HINSTANCE) GetWindowLong (hWnd, GWL_HINSTANCE),0); EndPaint(hWnd, &ps); SendMessage(combo_hwnd,CB_ADDSTRING,0,(long)text1.c_str()); SendMessage(combo_hwnd,CB_ADDSTRING,0,(long)text2.c_str()); SendMessage(combo_hwnd,CB_ADDSTRING,0,(long)text3.c_str()); SendMessage(combo_hwnd,CB_ADDSTRING,0,(long)text4.c_str()); return 0; case WM_CREATE : CreateMenubar(hWnd); //Savebutton hwndButton = CreateWindowEx (0,"BUTTON","Speichern",BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD, 70,250,100,20,hWnd, (HMENU)1,((LPCREATESTRUCT) lParam)->hInstance, NULL); return 0 ; //Set Backroundcolour case WM_CTLCOLORSTATIC: { HDC hdcStatic = (HDC) wParam; SetTextColor(hdcStatic, RGB(255,255,255)); SetBkColor(hdcStatic, RGB(0,0,0)); CreateSolidBrush(RGB(0,0,0)); return 0; } case WM_COMMAND: //Open if (wParam==0) { OpenDialog(hWnd); } //Save else if((wParam) == 1){ // SaveFile(hWnd); ofstream myfile; myfile.open ("Sicherung.txt"); myfile << "Checkbox"; myfile.close(); MessageBox(hWnd,"Speichervorgang erfolgreich abgeschlossen", "Speichervorgang", MB_OK |MB_ICONINFORMATION); } else if((wParam) == ID_BUTTONSTART){ SetWindowPos(hWnd,0,0,0,400,400,SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE); } else if((wParam) == ID_BUTTONSTART+1){ SetWindowPos(hWnd,0,0,0,500,500,SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE); } else if((wParam) == ID_BUTTONSTART+2){ SetWindowPos(hWnd,0,0,0,300,300,SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE); } else if((wParam) == ID_BUTTONSTART+3){ SetWindowPos(hWnd,0,0,0,200,200,SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE); } //Info else if (wParam==2) { MessageBox(hWnd, "test", MB_OK); } //Close window else if (wParam==3) { DestroyWindow(hWnd); PostQuitMessage(0); } return 0; //Closing the window case WM_CLOSE: DestroyWindow(hWnd); //Kill the process case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hWnd, message, wParam, lParam); } //Creating Menu void CreateMenubar(HWND hwnd) { HMENU hMenubar; HMENU hMenu; hMenubar = CreateMenu(); hMenu = CreateMenu(); AppendMenu(hMenubar, MF_POPUP, (UINT_PTR)hMenu, TEXT("&Menu")); AppendMenu(hMenu, MF_STRING, 0, TEXT("&Öffnen")); AppendMenu(hMenu, MF_STRING, 1, TEXT("&Speichern")); AppendMenu(hMenu, MF_STRING, 2, TEXT("&Info")); AppendMenu(hMenu, MF_STRING, 3, TEXT("&Beenden")); SetMenu(hwnd, hMenubar); } //Open File function void OpenDialog(HWND hwnd) { OPENFILENAME ofn; TCHAR szFile[MAX_PATH]; ZeroMemory(&ofn, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.lpstrFile = szFile; ofn.lpstrFile[0] = '\0'; ofn.hwndOwner = hwnd; ofn.nMaxFile = sizeof(szFile); ofn.lpstrFilter = TEXT("All files(*.*)\0*.*\0"); ofn.nFilterIndex = 1; ofn.lpstrInitialDir = NULL; ofn.lpstrFileTitle = NULL; ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; if(GetOpenFileName(&ofn)) LoadFile(ofn.lpstrFile); } //Save File void SaveFile(HWND hWnd){ ofstream myfile; myfile.open ("Sicherung.txt"); myfile << "Checkbox"; myfile.close(); MessageBox(hWnd,"Speichervorgang erfolgreich abgeschlossen", "Speichervorgang", MB_OK |MB_ICONINFORMATION); } //Load File void LoadFile(LPSTR file){ HANDLE hFile; DWORD dwSize; DWORD dw; LPBYTE lpBuffer = NULL; hFile = CreateFile(file, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); dwSize = GetFileSize(hFile, NULL); lpBuffer = (LPBYTE) HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, dwSize + 1); ReadFile(hFile, (LPWSTR)lpBuffer, dwSize, &dw, NULL); CloseHandle(hFile); lpBuffer[dwSize] = 0; HeapFree(GetProcessHeap(), 0, lpBuffer); }
-
Definiere das Makro _WIN32_WINNT als 0x0502. Näheres dazu hier: http://msdn.microsoft.com/en-us/library/windows/desktop/aa383745.aspx
-
hat leider nicht geholfen
auf xp rechnern kommt dennoch die message das es keine gültige win32 anwendung ist
-
Welche Platform (Win32, x64) ist beim Kompilieren ausgewählt? Wenn du x64 ausgewählt hast, das Betriebssystem aber "Win32" ist, ist das u.a. ein Grund, der zu der Fehlermeldung führt.
Ansonsten gib uns mal mehr Infos (Compiler-Version, Einstellungen/Switches), denn an WinAPI liegt es nicht.
-
Welche VS-Version hast Du?
Hast Du als x86 (Win32) kompiliert?
-
Also ich benutze visual studio 2012
als plattform hab ich win32 ausgewähltaber etwas muss auch mit dem code nicht stimmen... wenn ich es unter win xp compiliere öffnet sich das programm noch nicht mal
-
1. Du hast VS2012
2. Damit kannst Du nicht unter XP kompilieren; VS2012 wird nicht unter XP unterstützt.
3. Per Default laufen die Programme von VS2012 nicht mehr unter XP, da XP von MS nicht mehr supported wird
4. Es gibt ein "Update 1", welches diese Unterstützung wieder bringt, dafür musst Du aber explzit dies in den Projekteinstellungen angeben:VS2012 Update 1: http://www.microsoft.com/visualstudio/deu/downloads#d-visual-studio-2012-update
XP-Support: Project|Properties|General|Platform Toolset: Visual Studio 2012 - Windows XP (v110_xp)
-
sorry ich hab sehr lückenhaft geantwortet ohne es zu merken
ich arbeite unter windows 7 und windows xp habe ich auf meinem notebook
auf windows 7 habe ich vs12 und auf dem notebook vs10also die einstellungen hab ich schon gemacht da ich schon ein bischen mit dem ganzen herumexperimentiert habe
ich lad mal ein screenshot des bereiches mal hoch (vielleicht stimmt ja was anderes nicht)
-
Wenn Du nicht statisch gelinkt hast, musst Du natürlich auch noch die vc-Runtime auf XP installieren.
Siehe:C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\redist\1033\vcredist_x86.exe
-
leider hat sich dadurch auch nichts geändert
hab ich wirklch nicht ausversehn etwas verwendet was erst ab vista verfügbar war?
nach mehrfachen durchgehn scheint mir das am plausibelsten aber ich finde es nirgends
ich denk mal ich probier jetzt einfach mehrere compiler aus und schau mal was die sagen
-
Wenn das Programm nicht voller Unzulänglichkeiten wäre würde es wohl laufen
Nach einigen Anpassungen lässt es sich kompilieren und starten.
Da die gui.txt nicht vorhanden ist, kommt er schonmal aus der While-Schleife nicht raus.
Das wiederum bedeutet, das keine Fenster erzeugt werden ...
Hier ein paar Vorschläge
if (fin.is_open()) { // while (!fin.eof()) while ( fin.good() ) { ...
Für den Fall, das die Datei nicht da ist sollte es defaultwerte geben, da sonst
alle Buttons leer bleibenUNICODE Unterstützung wäre eigentlich üblich z.B.
#include <tchar.h> void LoadFile(LPCTSTR file); const TCHAR* const DELIMITER = _T(";"); basic_ifstream<TCHAR> fin; // ifstream fin;
oder auch hier:
if(_tcscmp(token[i], _T("RADIO"))== 0){ // generic strcmp i++; _tcscpy(radio_name[m], token[i]); // generic strcpy m++; }
Und dann wäre da noch:
// char szButtonName[25]; // sprintf_s(szButtonName, checkbox_name[i]); hCheckboxBar[i] = CreateWindowEx(0, _T("BUTTON"), checkbox_name[i], // szButtonName,
sowie:
ofn.lpstrFilter = TEXT("All files(*.*)\0*.*\0\0"); // terminated by two NULL characters
-
MessageBox benötigt 4 Parameter:
MessageBox(hWnd, _T("test"), _T("Info"), MB_OK);
-
Es gibt da einen Windows-Bug, der dafür sorgt, dass 32-Bit-Code, der auf einem 64-Bit-Windows läuft und in einer Message wie WM_CREATE wegen z.B. einer Nullpointer-Dereferenzierung crashen sollte nicht crasht, sondern einfach nur ein return macht. Das sorgt dafür, dass Code unter Win7 zu laufen scheint und unter WinXP abstürzt.
Beispiel und Fix.
-
nwp3 schrieb:
Es gibt da einen Windows-Bug
Das ist kein Bug, sondern, so Blöd es auch klingt, ein Feature.
-
Hier Dokumentiert: WindowProc callback function (Windows)
-
nwp3 schrieb:
Es gibt da einen Windows-Bug, der dafür sorgt, dass 32-Bit-Code, der auf einem 64-Bit-Windows läuft und in einer Message wie WM_CREATE wegen z.B. einer Nullpointer-Dereferenzierung crashen sollte nicht crasht, sondern einfach nur ein return macht. Das sorgt dafür, dass Code unter Win7 zu laufen scheint und unter WinXP abstürzt.
Beispiel und Fix.Das hat aber mit diesem Quelltext und dem Problem des Threadstarters nichts konkret zu tun, oder wo könnte hier so eine Stelle sein ?
-
Also habe jetzt einiges abgeändert aber es funktioniert leider immer noch nicht unter windows xp
habe auch zusätzlich das problem das ich keine buttons ausblenden kannif((wParam) == ID_BUTTONSTART){ SetWindowPos(hWnd,0,0,0,400,400,SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE); ShowWindow( hButtonBar[ID_BUTTONSTART+3], SW_HIDE );
Ich wollte auch fragen ob jemand interesse hätte mit mir das programm zu beenden da ich auch einige grundlegende fragen über c++ habe da ich noch am anfang bin. Dem Nachhilfelehrer würde ich dann 20€ die stunde dann per paypal als gegenleistung überweisen.
hier nochmal der restlich code und weil ich es letztes mal vergessen habe die gui datei
HIGH;1 WIDTH;1 ANZ_BUTTONS;5 ANZ_CHKBOX;2 Anz_RADIO;3 Unterordner MENU;Kasse 1 MENU;Kasse 2 MENU;Kasse 3 MENU;Kasse 4 MENU1: BUTTON;Button1 BUTTON;Button2 BUTTON;Button3 BUTTON;Button4 BUTTON;Button5 END CHKBOX;Sicher? CHKBOX;CHKBOX 12 END RADIO;Eins RADIO;Zwei RADIO;oder Drei END DROPDOWN;EINS DROPDOWN;Zwei DROPDOWN;Drei DROPDOWN;Vier DROPDOWN;Fünf DROPDOWN;Sechs END
/* This program is programmed by Bahram Salimi for the Daon Data Systems GmbH. The program is created to choose the Cash register. */ #include <tchar.h> #include <windows.h> #include <stdio.h> #include <iostream> #include <string> #include <sstream> #include <fstream> #include <objbase.h> using namespace std; #define _WIN32_WINNT 0x0502 #define ID_BUTTONSTART 101 #define ID_SPLITBUTTONSTART 201 #define ID_RADIOBUTTONSTART 301 #define ID_CHECKBOXSTART 401 #define BUTTON_START 10 #define BUTTON_NAME 9 #define RADIO_NAME 9 #define CHECKBOX_NAME 9 #define MAX_BUTTONS 4 #define MAX_CHECKBOX 2 #define MAX_RADIOBUTTON 3 #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' " "version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); void CreateMenubar(HWND); void OpenDialog(HWND); void LoadFile(LPSTR); HWND hButtonBar[MAX_BUTTONS]; int HIGH=0 , WIDTH=0; const int MAX_CHARS_PER_LINE = 512; const int MAX_TOKENS_PER_LINE = 30; const TCHAR* const DELIMITER = _T(";"); basic_ifstream<TCHAR> fin; int W_HIGH = 350; int W_WIDTH = 400; string text1 = "Eins"; string text2 = "Zwei"; string text3 = "Drei"; string text4 = "Vier"; int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static TCHAR const szAppName[] = TEXT("Daon Data Systems GmbH"); HWND hWnd, hCheckboxBar[MAX_CHECKBOX],hRadioBar[MAX_RADIOBUTTON]; MSG msg; WNDCLASSEX wndclassex; WNDCLASSW wc = {0}; HINSTANCE hInst; RECT rcClient; char button_name[100][BUTTON_NAME]; char checkbox_name[100][CHECKBOX_NAME]; char radio_name[100][RADIO_NAME]; int m=0; memset(button_name, NULL, sizeof button_name); memset(checkbox_name, NULL, sizeof checkbox_name); memset(radio_name, NULL, sizeof radio_name); // program parameter wndclassex.cbSize = sizeof (WNDCLASSEX); wndclassex.style = CS_HREDRAW | CS_VREDRAW; wndclassex.lpfnWndProc = &WndProc; wndclassex.cbClsExtra = 0; wndclassex.cbWndExtra = 0; wndclassex.hInstance = hInstance; wndclassex.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndclassex.hCursor = LoadCursor(NULL, IDC_ARROW); wndclassex.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wndclassex.lpszMenuName = NULL; wndclassex.lpszClassName = szAppName; wndclassex.hIconSm = wndclassex.hIcon; // message: can't register the Process if (!RegisterClassEx(&wndclassex)){ MessageBox(NULL, TEXT(_T("RegisterClassEx fehlgeschlagen!")), szAppName, MB_OK | MB_ICONERROR); return -1; } //Creating the Window hWnd = CreateWindowEx( WS_EX_ACCEPTFILES, // extendet window style szAppName, // name of window class TEXT("DDS - Daon Data Systems GmbH"), // window title WS_TILEDWINDOW| WS_TABSTOP, // window style CW_USEDEFAULT, // x-position of the window CW_USEDEFAULT,// y-position of the window W_WIDTH, // window width W_HIGH, // window high NULL, // upper windows NULL, // menu hInstance, // program ID NULL); // additional parameters //creating Checkbox GetClientRect(hWnd, &rcClient); int nButtonWidth = rcClient.right /10; int nButtonHeight = rcClient.bottom /10; int b=0; fin.open("GUI.txt"); // open a file // read each line of the file while (!fin.eof()) { // parse the line into blank-delimited tokens int n = 0; // a for-loop index // array to store memory addresses of the tokens in buf const char* token[MAX_TOKENS_PER_LINE] = {0}; // initialize to 0 // read an entire line into memory char buf[MAX_CHARS_PER_LINE]; fin.getline(buf, MAX_CHARS_PER_LINE); // parse the line token[0] = strtok(buf, DELIMITER); // first token if (token[0]) // zero if line is blank { for (n = 1; n < MAX_TOKENS_PER_LINE; n++){ token[n] = strtok(0, DELIMITER); // subsequent tokens if (!token[n]) break; // no more tokens } } // process (print) the tokens for (int i = 0; i < n ; i++){ // n = #of tokens if(strcmp (token[i], "ANZ_BUTTONS") == 0){ W_WIDTH = int(token[i]); } else if(_tcscmp(token[i], "ANZ_CHKBOX") == 0){ W_WIDTH = int(token[i]); } else if(_tcscmp(token[i], "Anz_RADIO") == 0){ W_WIDTH = int(token[i]); } else if(_tcscmp(token[i], "MENU") == 0){ i++; _tcscpy(button_name[m], token[i]); m++; } else if(_tcscmp(token[i], _T("RADIO"))== 0){ i++; _tcscpy(radio_name[m], token[i]); m++; } /* else if(strcmp (token[i], "DROPDOWN")== 0){ i++; string cmbx[i] SendMessage(combo_hwnd,CB_ADDSTRING,0,(long)text1.c_str()); m++; } */ else if(_tcscmp(token[i], "CHKBOX")== 0){ i++; _tcscpy(checkbox_name[m],token[i]); m++; } else if(_tcscmp(token[i], "END") == 0){ m=0; } } } int Button = NULL; int Chkbox = NULL; int Radio = NULL; for (int i = 0; i < MAX_BUTTONS; i++){ char szButtonName[25]; sprintf_s(szButtonName, button_name[i]); Button= ID_BUTTONSTART+i; hButtonBar[i] = CreateWindowEx(0, _T("BUTTON"), szButtonName, WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|WS_TABSTOP, 15, 20+i*29, 130, 25, hWnd, (HMENU) Button, hInstance, NULL); } for (int i = 0; i < MAX_CHECKBOX; i++){ char szButtonName[25]; sprintf_s(szButtonName, checkbox_name[i]); Chkbox= ID_CHECKBOXSTART+i; hCheckboxBar[i] = CreateWindowEx(0, _T("BUTTON"), szButtonName, BS_AUTOCHECKBOX | WS_CHILD| WS_VISIBLE| BS_PUSHBUTTON|WS_TABSTOP, 150, 20+i*25, 130, 25, hWnd, (HMENU) ID_CHECKBOXSTART + i, hInstance, NULL); } for (int i = 0; i < MAX_RADIOBUTTON; i++){ char szButtonName[25]; sprintf_s(szButtonName, radio_name[i]); Radio= ID_RADIOBUTTONSTART+i; hRadioBar[i] = CreateWindowEx(0, _T("BUTTON"), szButtonName, BS_AUTORADIOBUTTON | WS_CHILD| WS_VISIBLE|WS_TABSTOP, 280, 20+i*25, 130, 25, hWnd, (HMENU) ID_RADIOBUTTONSTART + i, hInstance, NULL); } ShowWindow(hWnd, iCmdShow); for (;;) //loop to share the messages { int ret = GetMessage(&msg, NULL, 0, 0); if (ret == -1) return -1; else if (ret == 0) break; TranslateMessage(&msg); DispatchMessage(&msg); UpdateWindow(hWnd); } UnregisterClass(szAppName, hInstance); return (int)msg.wParam; } // Main massageloop LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; HWND hwndButton, hwndEdit, combo_hwnd; HINSTANCE hInstance; switch (message) { case WM_PAINT: hdc = BeginPaint(hWnd, &ps); TextOut(hdc, 10, 0, TEXT("Bitte wählen sie das Menu aus"), 29); //Edit Window hwndEdit = CreateWindowEx (1, "edit", "Eingabe hier", WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL, 10,210, 150, 25, hWnd, (HMENU)10,(HINSTANCE) GetWindowLong (hWnd, GWL_HINSTANCE), NULL); //combobox combo_hwnd = CreateWindowEx(0x0,"ComboBox","Test", CBS_SIMPLE | CBS_DROPDOWN | CBS_DROPDOWNLIST | WS_VSCROLL | CBS_HASSTRINGS | WS_CHILD | WS_VISIBLE, 180,210,150,25,hWnd,(HMENU)11,(HINSTANCE) GetWindowLong (hWnd, GWL_HINSTANCE),0); EndPaint(hWnd, &ps); SendMessage(combo_hwnd,CB_ADDSTRING,0,(long)text1.c_str()); SendMessage(combo_hwnd,CB_ADDSTRING,0,(long)text2.c_str()); SendMessage(combo_hwnd,CB_ADDSTRING,0,(long)text3.c_str()); SendMessage(combo_hwnd,CB_ADDSTRING,0,(long)text4.c_str()); return 0; case WM_CREATE : CreateMenubar(hWnd); //Savebutton hwndButton = CreateWindowEx (0,"BUTTON","Speichern",BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD, 70,250,100,20,hWnd, (HMENU)1,((LPCREATESTRUCT) lParam)->hInstance, NULL); return 0 ; //Set Backroundcolour case WM_CTLCOLORSTATIC: { HDC hdcStatic = (HDC) wParam; SetTextColor(hdcStatic, RGB(255,255,255)); SetBkColor(hdcStatic, RGB(0,0,0)); CreateSolidBrush(RGB(0,0,0)); return 0; } case WM_COMMAND: //Open if (wParam==0) { OpenDialog(hWnd); } //Save if((wParam) == 1){ ofstream myfile; myfile.open ("Sicherung.txt"); myfile << "Checkbox"; myfile.close(); MessageBox(hWnd,_T("Speichervorgang erfolgreich abgeschlossen"), _T("Speichervorgang"), MB_OK |MB_ICONINFORMATION); } if((wParam) == ID_BUTTONSTART){ SetWindowPos(hWnd,0,0,0,400,400,SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE); ShowWindow( hButtonBar[ID_BUTTONSTART+3], SW_HIDE ); } if((wParam) == ID_BUTTONSTART+1){ SetWindowPos(hWnd,0,0,0,500,500,SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE); } if((wParam) == ID_BUTTONSTART+2){ SetWindowPos(hWnd,0,0,0,300,300,SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE); } if((wParam) == ID_BUTTONSTART+3){ SetWindowPos(hWnd,0,0,0,200,200,SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE); } //Info if (wParam==2) { MessageBox(hWnd, _T("Kontakt:\n" "Daniel Daon\n" "DDS - Daon Data Systems GmbH\n" "Senefelderstr. 1K\n" "D-63110 Rodgau\n" "Tel. +49(0)6106-74410\n" "Fax: +49 6106 76210\n" "info@dds-daon.de\n"), _T("Info"), MB_OK); } //Close window else if (wParam==3) { DestroyWindow(hWnd); PostQuitMessage(0); } return 0; //Closing the window case WM_CLOSE: DestroyWindow(hWnd); //Kill the process case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hWnd, message, wParam, lParam); } //Creating Menu void CreateMenubar(HWND hwnd) { HMENU hMenubar; HMENU hMenu; hMenubar = CreateMenu(); hMenu = CreateMenu(); AppendMenu(hMenubar, MF_POPUP, (UINT_PTR)hMenu, TEXT("&Menu")); AppendMenu(hMenu, MF_STRING, 0, TEXT("&Öffnen")); AppendMenu(hMenu, MF_STRING, 1, TEXT("&Speichern")); AppendMenu(hMenu, MF_STRING, 2, TEXT("&Info")); AppendMenu(hMenu, MF_STRING, 3, TEXT("&Beenden")); SetMenu(hwnd, hMenubar); } //Open File function void OpenDialog(HWND hwnd) { OPENFILENAME ofn; TCHAR szFile[MAX_PATH]; ZeroMemory(&ofn, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.lpstrFile = szFile; ofn.lpstrFile[0] = '\0'; ofn.hwndOwner = hwnd; ofn.nMaxFile = sizeof(szFile); ofn.lpstrFilter = TEXT("All files(*.*)\0*.*\0\0"); // terminated by two NULL characters ofn.nFilterIndex = 1; ofn.lpstrInitialDir = NULL; ofn.lpstrFileTitle = NULL; ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; if(GetOpenFileName(&ofn)) LoadFile(ofn.lpstrFile); } //Save File void SaveFile(HWND hWnd){ ofstream myfile; myfile.open ("Sicherung.txt"); myfile << "Checkbox"; myfile.close(); MessageBox(hWnd,_T("Speichervorgang erfolgreich abgeschlossen"), _T("Speichervorgang"), MB_OK |MB_ICONINFORMATION); } //Load File void LoadFile(LPSTR file){ HANDLE hFile; DWORD dwSize; DWORD dw; LPBYTE lpBuffer = NULL; hFile = CreateFile(file, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); dwSize = GetFileSize(hFile, NULL); lpBuffer = (LPBYTE) HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, dwSize + 1); ReadFile(hFile, (LPWSTR)lpBuffer, dwSize, &dw, NULL); CloseHandle(hFile); lpBuffer[dwSize] = 0; HeapFree(GetProcessHeap(), 0, lpBuffer); }
-
Es geht immer noch eine Menge schief im Quelltext.
Das Hauptproblem dürfte sein, das die #define-Anweisungen erst kommen wenn die
#include Anweisungen sich bereits ausgewirkt haben.Statt char sollte natürlich überall TCHAR stehen und
MessageBox(NULL, TEXT(_T("RegisterClassEx fehlgeschlagen!")), szAppName, MB_OK | MB_ICONERROR);
wird bei mir erst garnicht kompiliert.
Die Liste der Mängel ist noch deutlich länger als ich hier kommentieren möchte, aber das sollte man eigentlich auch selbst erkennen können.
Ich würde zudem vorschlagen mit VS2010 (mit SP1) ein neues leeres Projekt mit Defaultwerten anzulegen und den Quelltext dann auf einer leeren Seite einfügen.
Dann muss man natürlich statt
char TCHAR
strcmp _tcscmp
strtok _tcstok
u.s.w.verwenden, was der Compiler aber dann auch sagt.
Die Tipps meines ersten Posts sind auch nicht an allen Stellen umgesetzt worden.
-
Wie ich bereits am 04.01. angemerkt habe läuft das ganze auch unter XP wenn man es wie von mir vorgeschlagen anpasst.
Habe die gui.txt zum (ausgebesserten) Quelltext vom 4.1. dazukopiert und
auf einigen Buttons ist jetzt auch Text zu sehen.