Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <stdio.h>
- #include <dirent.h>
- HINSTANCE Instanz;
- int PASCAL WinMain(HINSTANCE, HINSTANCE, LPSTR , int );
- LRESULT CALLBACK Fensterfunktion (HWND, UINT, WPARAM, LPARAM);
- BOOL CALLBACK Open_File(HWND, UINT, WPARAM, LPARAM);
- int WINAPI WinMain (HINSTANCE dieseInstanz, HINSTANCE vorherigeInstanz, LPSTR Kommando, int Fenstertyp){
- MSG Meldung;
- HWND Hauptfenster;
- Instanz = dieseInstanz;
- if(!vorherigeInstanz){
- WNDCLASSEX wc;
- wc.style = CS_HREDRAW | CS_VREDRAW;
- wc.lpfnWndProc = Fensterfunktion;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = dieseInstanz;
- wc.hIcon = LoadIcon(NULL,IDI_ASTERISK);
- wc.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
- wc.hCursor = LoadCursor(NULL,IDC_ARROW);
- wc.hbrBackground= (HBRUSH) COLOR_BACKGROUND;
- wc.lpszMenuName = "Auswahl";
- wc.lpszClassName = "Fotoviewer";
- wc.cbSize = sizeof (WNDCLASSEX);
- wc.style = CS_DBLCLKS; // wird fuer Doppelklicks benoetigt
- if(!RegisterClassEx(&wc)) return 255; }
- Hauptfenster = CreateWindowEx( 0,"Fotoviewer",
- "Fotoviewer",
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- NULL,
- NULL,
- dieseInstanz,
- NULL);
- if(!Hauptfenster) return 255;
- ShowWindow(Hauptfenster, Fenstertyp);
- UpdateWindow(Hauptfenster);
- while( GetMessage(&Meldung,0,0,0)){
- TranslateMessage(&Meldung);
- DispatchMessage(&Meldung);
- }
- return Meldung.wParam;
- }
- LRESULT CALLBACK Fensterfunktion(HWND fenster, UINT nachricht, WPARAM parameter1, LPARAM parameter2){
- HDC hdc,MemDCExercising;
- HBITMAP bmpExercising;
- PAINTSTRUCT ps;
- static POINT maus_p;
- switch (nachricht){
- case WM_RBUTTONDBLCLK:
- return 0;
- case WM_LBUTTONDBLCLK:
- return 0;
- case WM_RBUTTONUP:
- return 0;
- case WM_RBUTTONDOWN:
- return 0;
- case WM_MOUSEMOVE:
- return 0;
- case WM_PAINT :
- hdc = BeginPaint(fenster, &ps);
- // Load the bitmap from the resource
- bmpExercising = (HBITMAP)LoadImage( NULL, "sxercising.bmp", IMAGE_BITMAP, 0, 0,
- LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE );
- // Create a memory device compatible with the above DC variable
- MemDCExercising = CreateCompatibleDC(hdc);
- // Select the new bitmap
- SelectObject(MemDCExercising, bmpExercising);
- // Copy the bits from the memory DC into the current dc
- BitBlt(hdc, 10, 10, 450, 400, MemDCExercising, 0, 0, SRCCOPY);
- // Restore the old bitmap
- /* DeleteDC(MemDCExercising);
- DeleteObject(bmpExercising);*/
- EndPaint(fenster,&ps);
- return 0;
- case WM_COMMAND :
- switch (parameter1){
- case 3: //Menueeintrag Beenden
- MessageBox(fenster,"Programm wird beendet", "Beenden",MB_ICONSTOP | MB_OK);
- PostQuitMessage(0);
- return 0;
- case 4:
- DialogBox(Instanz,"Open_File_Dialog",fenster,(DLGPROC)Open_File);
- InvalidateRect(fenster,NULL,TRUE);
- return 0;
- }
- return 0;
- case WM_DESTROY:
- PostQuitMessage(0);
- return 0;
- }
- return DefWindowProc(fenster,nachricht,parameter1,parameter2);
- }
- BOOL CALLBACK Open_File(HWND Dialog, UINT nachricht, WPARAM parameter1, LPARAM parameter2)
- {
- char Puffer[20];
- int tempx, tempy;
- DIR *d;
- static int index[100];
- int i=0;
- int selitem;
- int itemIndex;
- HWND hwndList1;
- TCHAR * textBuffer;
- int textLen;
- switch(nachricht)
- {
- case WM_INITDIALOG:
- HBITMAP testImage;
- testImage = (HBITMAP)LoadImage(NULL, "exercising.bmp", IMAGE_BITMAP, 498, 304, LR_LOADFROMFILE);
- SendMessage(Dialog, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)testImage);
- sprintf(Puffer,"%d", 6);
- SetDlgItemText(Dialog, 1, Puffer);
- sprintf(Puffer,"%d", 7);
- SetDlgItemText(Dialog, 2, Puffer);
- return TRUE;
- case WM_COMMAND:
- switch(parameter1)
- {
- case 123: //öffnen btn
- i=0;
- struct dirent *dir;
- d = opendir(".");
- if (d) {
- while ((dir = readdir(d)) != NULL) {
- index[i]=SendDlgItemMessage(Dialog, 2, LB_ADDSTRING, 0, (LPARAM)dir->d_name); //Listbox Id = 2
- i++;
- }
- closedir(d);
- }
- return TRUE;
- case IDOK: //auswählen btn
- selitem=0;
- hwndList1 = GetDlgItem(Dialog, 2);
- // Get current selection index in listbox
- itemIndex = (int) SendMessage(hwndList1, LB_GETCURSEL, (WPARAM)0, (LPARAM) 0);
- if (itemIndex == LB_ERR)
- {
- // No selection
- return TRUE;
- }
- // Get length of text in listbox
- textLen = (int) SendMessage(hwndList1, LB_GETTEXTLEN, (WPARAM) itemIndex, 0);
- // Allocate buffer to store text (consider +1 for end of string)
- textBuffer = new TCHAR[textLen + 1];
- // Get actual text in buffer
- SendMessage(hwndList1, LB_GETTEXT, (WPARAM) itemIndex, (LPARAM) textBuffer );
- // Show it
- MessageBox(Dialog,textBuffer, "Beenden",MB_ICONSTOP | MB_OK);
- // Free text
- delete [] textBuffer;
- // Avoid dangling references
- textBuffer = NULL;
- /*
- GetDlgItemText(Dialog, 3, Puffer, 10);
- tempx = atoi(Puffer);
- if(tempy < 0 || tempx < 0)
- {
- MessageBox(Dialog, "Geben Sie korrekte Werte ein", "Werte ungültig", MB_OK);
- return TRUE;
- }
- */
- break;
- case IDCANCEL:
- EndDialog(Dialog, 0);
- return TRUE;
- }
- }
- return FALSE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement