Advertisement
Guest User

Untitled

a guest
May 31st, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.02 KB | None | 0 0
  1. #include <windows.h>
  2. #include <stdio.h>
  3.  
  4. #include <dirent.h>
  5.  
  6.  
  7.  
  8.  
  9. HINSTANCE Instanz;
  10. int PASCAL WinMain(HINSTANCE, HINSTANCE, LPSTR , int );
  11. LRESULT CALLBACK Fensterfunktion (HWND, UINT, WPARAM, LPARAM);
  12. BOOL CALLBACK Open_File(HWND, UINT, WPARAM, LPARAM);
  13.  
  14. int WINAPI WinMain (HINSTANCE dieseInstanz, HINSTANCE vorherigeInstanz, LPSTR Kommando, int Fenstertyp){
  15. MSG Meldung;
  16. HWND Hauptfenster;
  17. Instanz = dieseInstanz;
  18. if(!vorherigeInstanz){
  19. WNDCLASSEX wc;
  20. wc.style = CS_HREDRAW | CS_VREDRAW;
  21. wc.lpfnWndProc = Fensterfunktion;
  22. wc.cbClsExtra = 0;
  23. wc.cbWndExtra = 0;
  24. wc.hInstance = dieseInstanz;
  25. wc.hIcon = LoadIcon(NULL,IDI_ASTERISK);
  26. wc.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
  27. wc.hCursor = LoadCursor(NULL,IDC_ARROW);
  28. wc.hbrBackground= (HBRUSH) COLOR_BACKGROUND;
  29. wc.lpszMenuName = "Auswahl";
  30. wc.lpszClassName = "Fotoviewer";
  31. wc.cbSize = sizeof (WNDCLASSEX);
  32. wc.style = CS_DBLCLKS; // wird fuer Doppelklicks benoetigt
  33. if(!RegisterClassEx(&wc)) return 255; }
  34. Hauptfenster = CreateWindowEx( 0,"Fotoviewer",
  35. "Fotoviewer",
  36. WS_OVERLAPPEDWINDOW,
  37. CW_USEDEFAULT,
  38. CW_USEDEFAULT,
  39. CW_USEDEFAULT,
  40. CW_USEDEFAULT,
  41. NULL,
  42. NULL,
  43. dieseInstanz,
  44. NULL);
  45.  
  46. if(!Hauptfenster) return 255;
  47.  
  48. ShowWindow(Hauptfenster, Fenstertyp);
  49. UpdateWindow(Hauptfenster);
  50.  
  51. while( GetMessage(&Meldung,0,0,0)){
  52. TranslateMessage(&Meldung);
  53. DispatchMessage(&Meldung);
  54. }
  55. return Meldung.wParam;
  56. }
  57.  
  58. LRESULT CALLBACK Fensterfunktion(HWND fenster, UINT nachricht, WPARAM parameter1, LPARAM parameter2){
  59. HDC hdc,MemDCExercising;
  60. HBITMAP bmpExercising;
  61. PAINTSTRUCT ps;
  62. static POINT maus_p;
  63. switch (nachricht){
  64. case WM_RBUTTONDBLCLK:
  65.  
  66. return 0;
  67. case WM_LBUTTONDBLCLK:
  68.  
  69. return 0;
  70. case WM_RBUTTONUP:
  71.  
  72. return 0;
  73. case WM_RBUTTONDOWN:
  74.  
  75. return 0;
  76. case WM_MOUSEMOVE:
  77.  
  78.  
  79. return 0;
  80. case WM_PAINT :
  81. hdc = BeginPaint(fenster, &ps);
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88. // Load the bitmap from the resource
  89. bmpExercising = (HBITMAP)LoadImage( NULL, "sxercising.bmp", IMAGE_BITMAP, 0, 0,
  90. LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE );
  91. // Create a memory device compatible with the above DC variable
  92. MemDCExercising = CreateCompatibleDC(hdc);
  93. // Select the new bitmap
  94. SelectObject(MemDCExercising, bmpExercising);
  95.  
  96. // Copy the bits from the memory DC into the current dc
  97. BitBlt(hdc, 10, 10, 450, 400, MemDCExercising, 0, 0, SRCCOPY);
  98.  
  99. // Restore the old bitmap
  100. /* DeleteDC(MemDCExercising);
  101. DeleteObject(bmpExercising);*/
  102. EndPaint(fenster,&ps);
  103. return 0;
  104. case WM_COMMAND :
  105. switch (parameter1){
  106.  
  107. case 3: //Menueeintrag Beenden
  108. MessageBox(fenster,"Programm wird beendet", "Beenden",MB_ICONSTOP | MB_OK);
  109. PostQuitMessage(0);
  110. return 0;
  111.  
  112. case 4:
  113. DialogBox(Instanz,"Open_File_Dialog",fenster,(DLGPROC)Open_File);
  114. InvalidateRect(fenster,NULL,TRUE);
  115. return 0;
  116. }
  117. return 0;
  118. case WM_DESTROY:
  119.  
  120. PostQuitMessage(0);
  121. return 0;
  122. }
  123. return DefWindowProc(fenster,nachricht,parameter1,parameter2);
  124. }
  125.  
  126.  
  127. BOOL CALLBACK Open_File(HWND Dialog, UINT nachricht, WPARAM parameter1, LPARAM parameter2)
  128. {
  129. char Puffer[20];
  130. int tempx, tempy;
  131. DIR *d;
  132. static int index[100];
  133. int i=0;
  134. int selitem;
  135. int itemIndex;
  136. HWND hwndList1;
  137. TCHAR * textBuffer;
  138. int textLen;
  139.  
  140. switch(nachricht)
  141. {
  142. case WM_INITDIALOG:
  143.  
  144.  
  145. HBITMAP testImage;
  146. testImage = (HBITMAP)LoadImage(NULL, "exercising.bmp", IMAGE_BITMAP, 498, 304, LR_LOADFROMFILE);
  147.  
  148. SendMessage(Dialog, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)testImage);
  149.  
  150.  
  151. sprintf(Puffer,"%d", 6);
  152.  
  153. SetDlgItemText(Dialog, 1, Puffer);
  154.  
  155. sprintf(Puffer,"%d", 7);
  156.  
  157. SetDlgItemText(Dialog, 2, Puffer);
  158.  
  159. return TRUE;
  160.  
  161.  
  162. case WM_COMMAND:
  163. switch(parameter1)
  164. {
  165. case 123: //öffnen btn
  166. i=0;
  167. struct dirent *dir;
  168. d = opendir(".");
  169. if (d) {
  170. while ((dir = readdir(d)) != NULL) {
  171. index[i]=SendDlgItemMessage(Dialog, 2, LB_ADDSTRING, 0, (LPARAM)dir->d_name); //Listbox Id = 2
  172. i++;
  173. }
  174. closedir(d);
  175. }
  176. return TRUE;
  177.  
  178. case IDOK: //auswählen btn
  179. selitem=0;
  180.  
  181. hwndList1 = GetDlgItem(Dialog, 2);
  182.  
  183.  
  184. // Get current selection index in listbox
  185. itemIndex = (int) SendMessage(hwndList1, LB_GETCURSEL, (WPARAM)0, (LPARAM) 0);
  186. if (itemIndex == LB_ERR)
  187. {
  188. // No selection
  189. return TRUE;
  190. }
  191.  
  192. // Get length of text in listbox
  193. textLen = (int) SendMessage(hwndList1, LB_GETTEXTLEN, (WPARAM) itemIndex, 0);
  194.  
  195. // Allocate buffer to store text (consider +1 for end of string)
  196. textBuffer = new TCHAR[textLen + 1];
  197.  
  198. // Get actual text in buffer
  199. SendMessage(hwndList1, LB_GETTEXT, (WPARAM) itemIndex, (LPARAM) textBuffer );
  200.  
  201. // Show it
  202.  
  203. MessageBox(Dialog,textBuffer, "Beenden",MB_ICONSTOP | MB_OK);
  204.  
  205. // Free text
  206. delete [] textBuffer;
  207.  
  208. // Avoid dangling references
  209. textBuffer = NULL;
  210.  
  211. /*
  212. GetDlgItemText(Dialog, 3, Puffer, 10);
  213.  
  214. tempx = atoi(Puffer);
  215.  
  216.  
  217. if(tempy < 0 || tempx < 0)
  218. {
  219. MessageBox(Dialog, "Geben Sie korrekte Werte ein", "Werte ungültig", MB_OK);
  220. return TRUE;
  221. }
  222.  
  223. */
  224.  
  225. break;
  226.  
  227.  
  228. case IDCANCEL:
  229. EndDialog(Dialog, 0);
  230. return TRUE;
  231. }
  232.  
  233. }
  234. return FALSE;
  235. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement