Click here to Skip to main content
15,886,791 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: To read a complete string Pin
«_Superman_»12-May-09 22:56
professional«_Superman_»12-May-09 22:56 
GeneralRe: To read a complete string Pin
Pankaj D.Dubey12-May-09 23:04
Pankaj D.Dubey12-May-09 23:04 
QuestionCustomised Browse for folder dialog problem Pin
VC++Maniac12-May-09 18:47
VC++Maniac12-May-09 18:47 
QuestionCut and Drag and Drop File/Folder Path Pin
MsmVc12-May-09 18:19
MsmVc12-May-09 18:19 
AnswerRe: Cut and Drag and Drop File/Folder Path Pin
enhzflep12-May-09 19:46
enhzflep12-May-09 19:46 
GeneralRe: Cut and Drag and Drop File/Folder Path Pin
MsmVc12-May-09 21:06
MsmVc12-May-09 21:06 
GeneralRe: Cut and Drag and Drop File/Folder Path Pin
MsmVc12-May-09 21:53
MsmVc12-May-09 21:53 
GeneralRe: Cut and Drag and Drop File/Folder Path [LONG POST] Pin
enhzflep12-May-09 22:18
enhzflep12-May-09 22:18 
#include <windows.h>
#include <stdio.h>
#include <commctrl.h>

/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
char szClassName[ ] = "CodeBlocksWindowsApp";

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 */

    InitCommonControls();

    /* 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;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           WS_EX_ACCEPTFILES,                   /* accept dropped files */
           szClassName,         /* Classname */
           "Drop a file/files onto me",       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           344,                 /* The programs width */
           175,                 /* 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 */
           );


    /* Make the window visible on the screen */
    ShowWindow (hwnd, nCmdShow);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}


// called after a WM_DROPFILES event to determine the number of files
// that were dropped
UINT getDroppedFilesCount(HANDLE hdrop)
{
 UINT queryIndex = -1;
 char returnBuffer[MAX_PATH] = "";
 int bufferSize = MAX_PATH;
 return DragQueryFile((HDROP)hdrop, queryIndex, returnBuffer, bufferSize);
}

// only retrieves the first filename from a list of
// files that have been dragged-and dropped. We can only
// open 1 project file (AXT) at a time, so to retrieve more
// than 1 name is unneccesary
void getDroppedFileName(HANDLE hdrop, char *DestBuffer)
{
 UINT queryIndex = 0;
 char returnBuffer[MAX_PATH] = "";
 int bufferSize = MAX_PATH;
 DragQueryFile((HDROP)hdrop, queryIndex, returnBuffer, bufferSize);
 strcpy(DestBuffer, returnBuffer);
}


/*  This function is called by the Windows function DispatchMessage()  */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)                  /* handle the messages */
    {
        case WM_DESTROY:
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            break;

        case WM_DROPFILES:
            HANDLE hDrop;
            int numFiles;
            char fileNames[MAX_PATH];
            hDrop = (HANDLE) wParam;
            if (getDroppedFilesCount(hDrop) == 1)
                    getDroppedFileName(hDrop, fileNames);
            else
                sprintf(fileNames, "Multiple files...");
            MessageBox(NULL, fileNames, "You dropped", MB_OK);
            break;

        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}

GeneralRe: Cut and Drag and Drop File/Folder Path [LONG POST] Pin
MsmVc12-May-09 22:22
MsmVc12-May-09 22:22 
QuestionRe: Cut and Drag and Drop File/Folder Path Pin
David Crow13-May-09 3:27
David Crow13-May-09 3:27 
QuestionWin32 web service client over SSL Pin
eight12-May-09 18:00
eight12-May-09 18:00 
AnswerRe: Win32 web service client over SSL Pin
eight12-May-09 22:33
eight12-May-09 22:33 
QuestionOne or many libraries? Pin
Mauro Leggieri12-May-09 14:54
Mauro Leggieri12-May-09 14:54 
AnswerRe: One or many libraries? Pin
«_Superman_»12-May-09 16:31
professional«_Superman_»12-May-09 16:31 
GeneralRe: One or many libraries? Pin
Mauro Leggieri13-May-09 2:37
Mauro Leggieri13-May-09 2:37 
QuestionCreating and Deleting a New Window Pin
BobInNJ12-May-09 12:28
BobInNJ12-May-09 12:28 
AnswerRe: Creating and Deleting a New Window Pin
Mauro Leggieri12-May-09 14:57
Mauro Leggieri12-May-09 14:57 
AnswerRe: Creating and Deleting a New Window Pin
«_Superman_»12-May-09 16:35
professional«_Superman_»12-May-09 16:35 
QuestionMemory Access Violation Pin
Ben Pedersen12-May-09 10:15
Ben Pedersen12-May-09 10:15 
AnswerRe: Memory Access Violation Pin
Nemanja Trifunovic12-May-09 10:53
Nemanja Trifunovic12-May-09 10:53 
GeneralRe: Memory Access Violation Pin
Ben Pedersen12-May-09 11:18
Ben Pedersen12-May-09 11:18 
QuestionPlugin - Dialog Handle Control Pin
Tux`12-May-09 8:28
Tux`12-May-09 8:28 
AnswerRe: Plugin - Dialog Handle Control Pin
Stuart Dootson12-May-09 9:54
professionalStuart Dootson12-May-09 9:54 
GeneralRe: Plugin - Dialog Handle Control Pin
Tux`12-May-09 10:08
Tux`12-May-09 10:08 
QuestionUnable to install platform SDK on Vista Operating System. Pin
pandit8412-May-09 7:16
pandit8412-May-09 7:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.