kod sie troche zmienil
main.cpp
#include <iostream>
#include <fstream>
#include <dirent.h>
#include <string>
#include <windows.h>
#include <Windowsx.h>
#include "main.h"
using namespace std;
bool is_file(string file){
FILE* plik = fopen(file.c_str(), "r");
if(plik)
return true;
return false;
}
string* ListFiles(string* maineTab, string* maineTab2, string src){
struct dirent* pozycja=0;
string fileName;
int nb = 0;
while(maineTab[nb] != "")
nb++;
DIR* folder = opendir(src.c_str());
while(pozycja=readdir(folder)){
fileName=(*pozycja).d_name;
if(fileName != "." && fileName != ".."){
string tmpname = src + "/" + fileName;
if(is_file(tmpname)){
if((fileName.find(".avi")==(fileName.length()-4)) || (fileName.find(".rmvb")==(fileName.length()-5))){
maineTab[nb] = tmpname;
maineTab2[nb] = fileName;
nb++;
}
}else{
ListFiles(maineTab, maineTab2, tmpname);
}
}
}
return maineTab;
}
string* DirScan(string* tabswsk, string* Tab4names, string DirName){
cout << "nazwa katalogu to: " << DirName << "\n";
DIR* katalog = opendir(DirName.c_str());
if(katalog){
ListFiles(tabswsk, Tab4names, DirName);
}else{
if(is_file(DirName)){
cout << "to jest plik \n";
}else{
cout << "Taki plik lub katalog nie istnieje \n";
}
}
delete(katalog);
}
string ArrayOfFiles[500]; // Glowna tablica z lista plikow
string ArrayOfFiles_names[500]; // Glowna tablica z lista plikow
string* W_ArrayOfFiles = ArrayOfFiles; // wskaznik do tablicy z lista plikow
string* W_ArrayOfFiles_names = ArrayOfFiles_names; // wskaznik do tablicy z lista plikow
/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK DlgProc( HWND, UINT, WPARAM, LPARAM );
/* Make the class name into a global variable */
char szClassName[ ] = "CodeBlocksWindowsApp";
DWORD dlugosc;
// Przyciski
HWND g_hPrzycisk;
HWND selectMove;
HWND hText;
HWND h_odtwarzacz;
HWND hListBox;
HWND hSileSelect;
int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow){
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */
/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default colour as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Code::Blocks Template Windows App", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
840, /* The programs width */
680, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
if( hwnd == NULL ){
MessageBox( NULL, "Okno odmówiło przyjścia na świat!", "Ale kicha...", MB_ICONEXCLAMATION );
return 1;
}
g_hPrzycisk = CreateWindowEx(WS_EX_CLIENTEDGE, "BUTTON", "OK", WS_CHILD | WS_VISIBLE,20, 40, 150, 30, hwnd, NULL, hThisInstance, NULL );
selectMove = CreateWindowEx(WS_EX_CLIENTEDGE, "BUTTON", "Otworz ten film", WS_CHILD | WS_VISIBLE,20, 500, 150, 30, hwnd, NULL, hThisInstance, NULL );
hText = CreateWindowEx( WS_EX_CLIENTEDGE, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 20, 10, 250, 26, hwnd, NULL, hThisInstance, NULL );
h_odtwarzacz = CreateWindowEx( WS_EX_CLIENTEDGE, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 350, 10, 250, 26, hwnd, NULL, hThisInstance, NULL );
hListBox = CreateWindowEx( WS_EX_CLIENTEDGE, "LISTBOX", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | ES_AUTOVSCROLL, 20, 100, 700, 400, hwnd, NULL, hThisInstance, NULL );
//
hSileSelect = CreateWindowEx( 0, "BUTTON", "...", WS_CHILD | WS_VISIBLE, 280, 10, 30, 26, hwnd, NULL, hThisInstance, NULL );
SetWindowText(hText, "d:/filmy" );
SetWindowText(h_odtwarzacz, "D:/ins/mplayerc.exe" );
ShowWindow (hwnd, nCmdShow);
while (GetMessage (&messages, NULL, 0, 0)){
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
/* This function is called by the Windows function DispatchMessage() */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
switch (message){
case WM_COMMAND:{
if(( HWND ) lParam == g_hPrzycisk ){
cout << wParam << " -- " << lParam;
dlugosc = GetWindowTextLength( hText );
LPSTR Bufor =( LPSTR ) GlobalAlloc( GPTR, dlugosc + 1 );
GetWindowText( hText, Bufor, dlugosc + 1 );
//MessageBox( hwnd, Bufor, "Ha!", MB_ICONINFORMATION );
DirScan(W_ArrayOfFiles, W_ArrayOfFiles_names, Bufor);
int indexofmove = 0;
while(ArrayOfFiles_names[indexofmove] != ""){
string ole_ole = ArrayOfFiles_names[indexofmove];
SendMessage( hListBox, LB_ADDSTRING, 0,( LPARAM ) ole_ole.c_str() );
indexofmove++;
}
}else if(( HWND ) lParam == selectMove){
int numer = ListBox_GetCurSel( hListBox );
cout << numer << " -- \n " ;
//MessageBox( hwnd, numer, "Ha!", MB_ICONINFORMATION );
dlugosc = GetWindowTextLength( h_odtwarzacz );
LPSTR Player =( LPSTR ) GlobalAlloc( GPTR, dlugosc + 1 );
GetWindowText( h_odtwarzacz, Player, dlugosc + 1 );
string PlayerSTR = Player;
if(is_file(PlayerSTR)){
if(numer > -1){
string dd = ArrayOfFiles[numer];
string p = "\""+PlayerSTR+" \""+dd+"\"\"";
system(p.c_str());
}
}else{
MessageBox( hwnd, "Nie moge znalesc odtwarzacza", "Error!", MB_ICONINFORMATION );
}
}else if(( HWND ) lParam == hSileSelect){
OPENFILENAME ofn;
char sNazwaPliku[ MAX_PATH ] = "";
ZeroMemory( & ofn, sizeof( ofn ) );
ofn.lStructSize = sizeof( ofn );
ofn.lpstrFilter = "Pliki tekstowe (*.txt)\0*.txt\0Wszystkie pliki\0*.*\0";
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFile = sNazwaPliku;
ofn.lpstrDefExt = "txt";
ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
if(GetOpenFileName(&ofn)){
cout << "gitara \n";
}else{
cout << "instrument przeciwny do gitary \n";
}
}
}
break;
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
BOOL CALLBACK DlgProc( HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam ){
switch( Msg ){
case WM_COMMAND:{
// reakcja na przyciski
switch( LOWORD( wParam ) ){
case IDOK: EndDialog( hwnd, IDOK ); break;
case IDCANCEL: EndDialog( hwnd, IDCANCEL ); break;
}
}
break;
default: return FALSE;
}
return TRUE;
}
main.rc
#include <windows.h>
#include "main.h"
IDD_MOJDIALOG DIALOG DISCARDABLE 20, 20, 200, 66
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Mój własny dialog"
FONT 8, "MS Sans Serif"
{
DEFPUSHBUTTON "&Fajnie!", IDOK, 124, 18, 50, 14
PUSHBUTTON "&Anuluj", IDCANCEL, 124, 35, 50, 14
LTEXT "To jest okno dialogowe", IDC_LABEL, 16, 18, 80, 33
}
i main.h
#define IDD_MOJDIALOG 200
#define IDC_LABEL 201