GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 09-Mar-2010, 09:30
x51 x51 is offline
New Member
 
Join Date: Mar 2010
Posts: 3
x51 is an unknown quantity at this point
Question

How to check if pen drive is connected?


Hello

I write console application in C and i want this application to detect if pen drive is inserted in to usb. I have read forums and i think that i have to create window and this window will recive information from system and then i can check WM_DEVICECHANGE (i`m not 100% sure if it is right solution). Detecting pen drive is not a main task of this application, so i have to do it i new theard. My problem now is that if i create window in new theard, nothing happens - window doesn`t show up although the i used ShowWindow() function. I would be very grateful for any help.

regards
x51
  #2  
Old 09-Mar-2010, 17:12
Mexican Bob's Avatar
Mexican Bob Mexican Bob is offline
Regular Member
 
Join Date: Mar 2008
Location: Chicxulub, Yucatán
Posts: 350
Mexican Bob is a jewel in the roughMexican Bob is a jewel in the roughMexican Bob is a jewel in the roughMexican Bob is a jewel in the rough

Re: How to check if pen drive is connected?


Quote:
Originally Posted by x51
My problem now is that if i create window in new theard [sic], nothing happens - window doesn`t show up although the i used ShowWindow() function. I would be very grateful for any help.

Without CODE this post is completely meaningless...

FYI: I, when used as a pronoun, is ALWAYS capitalized.


Mxb
  #3  
Old 10-Mar-2010, 06:48
x51 x51 is offline
New Member
 
Join Date: Mar 2010
Posts: 3
x51 is an unknown quantity at this point

Re: How to check if pen drive is connected?


Quote:
Originally Posted by Mexican Bob
Without CODE this post is completely meaningless...

FYI: I, when used as a pronoun, is ALWAYS capitalized.


Mxb

English is not my native language and I don`t ask you for grammar advice, and i don`t know for what you need code, my question now (if you didn`t understand it) is how to create window in new thread of console aplication
  #4  
Old 10-Mar-2010, 15:44
Mexican Bob's Avatar
Mexican Bob Mexican Bob is offline
Regular Member
 
Join Date: Mar 2008
Location: Chicxulub, Yucatán
Posts: 350
Mexican Bob is a jewel in the roughMexican Bob is a jewel in the roughMexican Bob is a jewel in the roughMexican Bob is a jewel in the rough

Re: How to check if pen drive is connected?


Quote:
Originally Posted by x51
English is not my native language and I don`t ask you for grammar advice

I donated my grammar FYI (for your information) for free!

Quote:
Originally Posted by x51
and i don`t know for what you need code,

...because we can't tell you what you're doing wrong from just your narrative of it.

Quote:
Originally Posted by x51
my question now (if you didn`t understand it) is how to create window in new thread of console aplication

New thread or the same thread, it doesn't matter:

CPP / C++ / C Code:
#define _WIN32_WINNT 0x0500

#include <windows.h>

LRESULT CALLBACK MainWndProc(HWND hwnd, UINT wMsg,WPARAM wParam, LPARAM lParam)
{
    switch(wMsg)
    {
    case WM_CREATE:
        return 0;
    default:
        break;
    }
    return DefWindowProc(hwnd, wMsg, wParam, lParam);
}

BOOL init_window(HWND hwnd)
{
    HWND        hwndConsole;
    HINSTANCE   hinst;
    DWORD       dwStyle;
    WNDCLASS    wc;

    memset(&wc, 0, sizeof(wc));

    hwndConsole             =   GetConsoleWindow();
    hinst                   =   (HINSTANCE)GetWindowLong(hwndConsole, GWL_HINSTANCE);

    wc.lpszClassName        =   TEXT("A:WINDOW");
    wc.hInstance            =   hinst;
    wc.lpfnWndProc          =   (WNDPROC)MainWndProc;
    wc.hCursor              =   LoadCursor(hinst, TEXT("HAND"));
    wc.hIcon                =   LoadIcon(hinst, IDI_APPLICATION);
    wc.lpszMenuName         =   NULL;
    wc.hbrBackground        =   (HBRUSH)GetStockObject(WHITE_BRUSH);
    wc.style                =   CS_HREDRAW | CS_VREDRAW;
    wc.cbClsExtra           =   0;
    wc.cbWndExtra           =   0;       

    if(RegisterClass(&wc))
    {
        dwStyle = WS_OVERLAPPEDWINDOW;

        hwnd = CreateWindow(TEXT("A:WINDOW"),             // Class name
                            TEXT("A Window"),             // Title
                            dwStyle,                      // Style bits
                            0,                            // x - default
                            0,                            // y - default
                            640,                          // cx - default
                            480,                          // cy - default
                            NULL,                         // Parent
                            NULL,                         // Class menu
                            hinst,                        // Creator
                            NULL);                        // Params

        if(hwnd != NULL)
        {
            ShowWindow(hwnd, SW_SHOWNORMAL);
            return TRUE;
        }
    }
    return FALSE;
}

int main()
{
    MSG  msg;
    HWND hwnd = NULL;

    MessageBox(NULL, TEXT("Text"), TEXT("Caption"), MB_OKCANCEL | MB_ICONEXCLAMATION);
    if(init_window(hwnd))
    {
        while(GetMessage(&msg, hwnd, 0, 0))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    return 0;
}


...one could add a WM_CLOSE handler that "PostQuitMessage(0)" and cleanly exit the CMD window, but if I did everything for you, what would you learn?


MxB
  #5  
Old 11-Mar-2010, 14:27
x51 x51 is offline
New Member
 
Join Date: Mar 2010
Posts: 3
x51 is an unknown quantity at this point

Re: How to check if pen drive is connected?


Thank You very much :] btw. Adamek will crash Areola
  #6  
Old 11-Mar-2010, 16:25
Mexican Bob's Avatar
Mexican Bob Mexican Bob is offline
Regular Member
 
Join Date: Mar 2008
Location: Chicxulub, Yucatán
Posts: 350
Mexican Bob is a jewel in the roughMexican Bob is a jewel in the roughMexican Bob is a jewel in the roughMexican Bob is a jewel in the rough

Re: How to check if pen drive is connected?


Quote:
Originally Posted by x51
Adamek will crash Areola

I bet I could kick both their butts put together in C or C++! ...with one hand tied behind my back!

...Areola is going in for a semicolon to put an end to that forceful statement while Adamek is still looking for Any Key...that's it folks, lights out Mexican Bob has finished it for the both of them with a :sh up-arrow-twice-enter...it's all over!

MxB
 
 

Recent GIDBlogNot selected for officer school by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Probing for TCP connections kterry C Programming Language 3 14-Feb-2008 11:32
How to make the program know that a external drive is connected? AnaXyd .NET Forum 0 07-Jul-2007 04:44
Buying a SATA Drive and Using it as my Master OS Drive dw84uk Computer Hardware Forum 1 27-Nov-2006 19:20
Need help understand function prototypes! Blstretch C++ Forum 20 25-Oct-2005 14:14

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 19:04.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.