Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
S

Software_Developer

@Software_Developer
About
Posts
221
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • how to create thread on windows?
    S Software_Developer

    Try this:

    #include "stdafx.h"

    #define _MT
    #include
    #include /* _beginthread, _endthread */
    #include
    #include
    #include
    #include

    #pragma comment(lib, "user32.lib")
    #pragma comment(lib, "libcmt.lib")
    #pragma comment(linker, "/NODEFAULTLIB:libcd.lib")

    void ThreadFunction1(void *ch);
    void ThreadFunction2(void *dummy);

    BOOL repeat = TRUE; /* Global repeat flag */

    int main(){
    printf("\nMultithreading with two threads.\n\n");
    printf("Thread Function 2 listens for key strokes. \n");
    printf("Thread Function 1 does all the other work \n");
    printf(" \n");
    CHAR ch = 'A';

    /\* Launch ThreadFunction2 thread to check for terminating keystroke. \*/
    \_beginthread(ThreadFunction2, 0, NULL);
    
    /\* Loop until ThreadFunction2 terminates program. \*/
    while (repeat){
    	/\* On first loops, launch character threads. \*/
    	\_beginthread(ThreadFunction1, 0, (void \*)(ch++));
    
    	/\* Wait one second between loops. \*/
    	Sleep(1000L);
    }
    
    printf("  \\n");
    return 0;
    

    }

    /* ThreadFunction2 - Thread to wait for a keystroke, then end program. */
    void ThreadFunction2(void *dummy){
    _getch();
    repeat = 0; /* _endthread implied */

    }

    /* ThreadFunction2 - Thread to do work */
    void ThreadFunction1(void *ch){

    while (repeat){
    
    	/\* Pause between loops. \*/
    	Sleep(100L);
    
    }
    /\* \_endthread given to terminate \*/
    \_endthread();
    

    }

    C / C++ / MFC c++ visual-studio question csharp com

  • C fread to read 512k binary file
    S Software_Developer

    Hello. Here is another solution.

    //******************************************
    // reading an entire binary file the c++ way

    #include #include using namespace std;

    int main (){

    streampos size;
    char * memblock;
    cout<<" \n\n";

    // open file as binary
    ifstream file ("myfile.bin", ios::in|ios::binary|ios::ate);
    if ( file.is_open() ){

    // get file size
    size = file.tellg();
    
    // alloocate appropiate file size + 1 for '\\0'
    memblock = new char \[size+1\];
    
    // go to begining of file
    file.seekg (0, ios::beg);
    
    // read entire file into ram memory
    file.read (memblock, size);
    file.close();
    
    // display size of file
    cout << "the entire file content of "<< size <<" bytes is in memory  \\n\\n\\n";
    
    // release memory
    delete\[\] memblock;
    

    }
    else cout << "Unable to open file\n\n";

    cout<<"Press ANY key to close.\n\n";
    cin.ignore(); cin.get();
    return 0;
    }

    C / C++ / MFC help question

  • Only Desktop capturing without some active windows or capture only Desktop i.e Desktop Background and Icons
    S Software_Developer

    First. Minimize All running apps. Run the code below.

    #include #include using namespace std;

    int main()
    {
    keybd_event(VK_MENU, 0, 0, 0); //Alt Press
    keybd_event(VK_SNAPSHOT, 0, 0, 0); //PrntScrn Press

    keybd\_event(VK\_SNAPSHOT, 0, KEYEVENTF\_KEYUP, 0); //PrntScrn Release
    keybd\_event(VK\_MENU, 0, KEYEVENTF\_KEYUP, 0); //Alt Release
    

    return 0;
    }

    C / C++ / MFC help

  • how do i make another main.c file where i can call this program and run according to it..?
    S Software_Developer

    In C++, you can only have one main. The standard explicitly says in 3.6.1: A program shall contain a global function called main, hich is the designated start of the program. [...] This function shall not be overloaded. You can have two functions called main. The name is not special in any way and it's not reserved. What's special is the function, and it happens to have that name. The function is global. So if you write a main function in some other namespace, you will have a second main function.

    namespace secondMain
    {
    int main() { return 0; }
    }

    int main()
    {
    secondMain::main();

    }

    The first main function is not special - notice how you have to return explicitly.

    C / C++ / MFC question tools help lounge

  • how can i convert a QString to char* in QT
    S Software_Developer

    http://qt-project.org/faq/answer/how_can_i_convert_a_qstring_to_char_and_vice_versa[^] http://qt-project.org/forums/viewthread/4732[^]

    C / C++ / MFC question

  • Qtimer class in Qt
    S Software_Developer

    QElapsedTimer Class example :

    QElapsedTimer timer;
    timer.start();

    slowOperation1();
    
    qDebug() << "The slow operation took" << timer.elapsed() << "milliseconds";
    

    QElapsedTimer Class documentation : http://qt-project.org/doc/qt-5/qelapsedtimer.html[^]

    C / C++ / MFC question

  • CFormView in CDocktablePane or docking frame CMDIChildWndEx
    S Software_Developer

    CFormView in CDockablePane Codeproject Article: CFormView in CDockablePane [CFormView in CDockablePane^]

    C / C++ / MFC csharp php database visual-studio help

  • CreateProcess() not working
    S Software_Developer

    It works, you just dont have rehash.exe in C.\temp I compiled your code and it and it worked. Output:

    Line, Character counting Program === === by Newbie
    Usage: fileName
    EXE Path:

    Press any key to continue

    C / C++ / MFC help

  • How To Decrease Video Size
    S Software_Developer

    Encode it as an MP4 File. MP4 video files are up to four times smaller than mpeg videos. Tutorial: Encoding an MP4 File : http://msdn.microsoft.com/en-us/library/windows/desktop/ff819476(v=vs.85).aspx[^] Media Foundation Programming Guide : http://msdn.microsoft.com/en-us/library/windows/desktop/ms697062(v=vs.85).aspx[^] video capture sample : http://code.msdn.microsoft.com/windowsdesktop/Media-Foundation-Capture-78504c83[^]

    C / C++ / MFC json help tutorial question

  • Double buffering
    S Software_Developer

    Double buffering articles. Double Buffering With GDI+[^] Flicker Free Drawing In MFC[^] http://www.robertelder.ca/doublebuffering/[^

    C / C++ / MFC graphics performance

  • CFile Error When Writing
    S Software_Developer

    The error should be obvious, the inners of write look like this..

    virtual void Write(
    const void* lpBuf,
    UINT nCount
    );

    Parameters lpBuf - A pointer to the user-supplied buffer that contains the data to be written to the file. nCount - The number of bytes to be transferred from the buffer. For text-mode files, carriage return–linefeed pairs are counted as single characters. Official MSDN example:

    CFile cfile;
    cfile.Open(_T("Write_File.dat"), CFile::modeCreate | CFile::modeReadWrite);

    char pbufWrite[100];

    memset(pbufWrite, 'a', sizeof(pbufWrite));

    cfile.Write(pbufWrite, 100);
    cfile.Flush();

    http://msdn.microsoft.com/en-us/library/esb6sz20.aspx[^]

    C / C++ / MFC help question

  • CFile Error When Writing
    S Software_Developer

    Since the exception is "An unknown error occurred while accessing file ", Do you still get errors with the unicode syntax _T( ) , e.g CFile file (_T ("File.txt"), CFile::modeReadWrite) );

    CFile file;
    CFileException e;
    if (file.Open (_T ("File.txt"), CFile::modeReadWrite, &e)) {
    // It worked!

    }
    else {
    // Open failed. Tell the user why.
    e.ReportError ();
    }

    C / C++ / MFC help question

  • write Series of this program 1+-3+5+-7+9+-11 in c++
    S Software_Developer

    I can only point you in the right direction.

    #include
    using namespace std;

    int main()
    {
    int n=43, sum = 0,neg= 1;

      for(int i = 1; i <= n; i+=2) 
      {
    	 
    	sum += (i\*neg); 
    	cout <<"i="<
    
    C / C++ / MFC c++ help

  • good algorithm to determine if there are overlapping in multiple rectangles
    S Software_Developer

    The Bounding Box method is fairly simple, this technique involves checking whether an object has intercepted (overlapped) an invisible square boundary that is usually placed over, and often remains relative to, a game object.

    int bounding_box_collision(int b1_x, int b1_y, int b1_w, int b1_h, int b2_x, int b2_y, int b2_w, int b2_h)
    {
    if ((b1_x > b2_x + b2_w - 1) || // is b1 on the right side of b2?
    (b1_y > b2_y + b2_h - 1) || // is b1 under b2?
    (b2_x > b1_x + b1_w - 1) || // is b2 on the right side of b1?
    (b2_y > b1_y + b1_h - 1)) // is b2 under b1?
    {
    // no collision
    return 0;
    }

    // collision
    return 1;
    

    }

    http://wiki.allegro.cc/index.php?title=Bounding_Box[^]

    C / C++ / MFC c++ algorithms help question learning

  • How to get cursor position in status bar?
    S Software_Developer

    Try this!

    void CDlgStatusBarDlg::OnMouseMove(UINT nFlags, CPoint point)
    {
    CString s;
    s.Format("X=%d Y=%d",point.x,point.y);
    m_bar.SetPaneText(0,s);
    CDialog::OnMouseMove(nFlags, point);
    }

    Source: [Adding a status bar to an MFC dialog[^]]

    C / C++ / MFC question data-structures help tutorial announcement

  • Low-Level Keyboard Input Detection
    S Software_Developer

    For Windows, here is a global key hook example, prints pressed keycodes to the console. It even works when it's in the background. And this is a Windows discussion board, also ask in Linux, Android and IOS sections for answers..

    #include
    #include

    HHOOK hKeyboardHook;

    __declspec(dllexport) LRESULT CALLBACK KeyboardEvent (int nCode, WPARAM wParam, LPARAM lParam)
    {
    DWORD SHIFT_key=0;
    DWORD CTRL_key=0;
    DWORD ALT_key=0;

    if  ((nCode == HC\_ACTION) &&   ((wParam == WM\_SYSKEYDOWN) ||  (wParam == WM\_KEYDOWN)))      
    {
    	KBDLLHOOKSTRUCT hooked\_key = 	\*((KBDLLHOOKSTRUCT\*)lParam);
    	DWORD dwMsg = 1;
    	dwMsg += hooked\_key.scanCode << 16;
    	dwMsg += hooked\_key.flags << 24;
    	char lpszKeyName\[1024\] = {0};
    	lpszKeyName\[0\] = '\[';
    
    	int i = GetKeyNameText(dwMsg,	(lpszKeyName+1),0xFF) + 1;
    	lpszKeyName\[i\] = '\]';
    
    	int key = hooked\_key.vkCode;
    
    	SHIFT\_key = GetAsyncKeyState(VK\_SHIFT);
    	CTRL\_key = GetAsyncKeyState(VK\_CONTROL);
        ALT\_key = GetAsyncKeyState(VK\_MENU);
    
    	if (key >= 'A' && key <= 'Z')   mmmmmmcjmcfkgkgcgkj.j.g     
    	{
    		 
    		if  (GetAsyncKeyState(VK\_SHIFT)>= 0) key +=32;
    
    		if (CTRL\_key !=0 && key == 'y' )
    		{
               MessageBox(NULL, "CTRL-y was pressed\\nLaunch your app here", "H O T K E Y", MB\_OK); 
               CTRL\_key=0;
    		}
    
    		if (CTRL\_key !=0 && key == 'q' )
    		{
    			MessageBox(NULL, "Shutting down", "H O T K E Y", MB\_OK); 
               PostQuitMessage(0);
    		}
    
    
    
    
    		printf("key = %c\\n", key);
    
    		SHIFT\_key = 0;
    		CTRL\_key = 0;
    		ALT\_key = 0;
    
    	}
    
    	printf("lpszKeyName = %s\\n",  lpszKeyName );
    }
    return CallNextHookEx(hKeyboardHook,	nCode,wParam,lParam);
    

    }

    void MessageLoop()
    {
    MSG message;
    while (GetMessage(&message,NULL,0,0))
    {
    TranslateMessage( &message );
    DispatchMessage( &message );
    }
    }

    DWORD WINAPI my_HotKey(LPVOID lpParm)
    {
    HINSTANCE hInstance = GetModuleHandle(NULL);
    if (!hInstance) hInstance = LoadLibrary((LPCSTR) lpParm);
    if (!hInstance) return 1;

    hKeyboardHook = SetWindowsHookEx ( 	WH\_KEYBOARD\_LL, (HOOKPROC) KeyboardEvent,  	hInstance,  NULL    );
    MessageLoop();
    UnhookWindowsHookEx(hKeyboardHook);
    return 0;
    

    }

    int main(int argc, char** argv)
    {
    HANDLE hThread;
    DWORD dwThread;

    hThread = CreateThread(NULL,NULL,(LPTHREAD\_START\_ROUTINE) 	my\_HotKey, (LPVOID) argv\[0\], NULL, &dwThread);
    
    //ShowWindow(FindWindowA("ConsoleWindowClass", NULL), false);
    
    if (hThread) return WaitForSingleObject(hThread,INFINI
    
    C / C++ / MFC android ios linux hardware question

  • global touch event with sound using mfc
    S Software_Developer

    Try this link [Quickstart: Touch input (Windows Store apps using C#/VB/C++ and XAML)] []

    C / C++ / MFC question c++ help

  • Handling mouse using OS interrupts
    S Software_Developer

    Turbo C++ code. Copy paste this to a file named mouse.h . <-------- start of mouse.h

    include
    #include
    #include
    #include
    #include

    const ress=0xb;

    unsigned hspd,vspd,thv,button,mouse_x,mouse_y;
    int dirx,diry,dir_x,dir_y,trshold;
    unsigned char mousestep;

    void initmouse(void)
    {
    asm{
    mov ax,1h
    int 33h

     }
    

    }

    void hidemouse(void)
    {
    asm{
    mov ax,2h
    int 33h

     }
    

    }

    void getmousepos(void)
    {
    asm{
    mov ax,3h
    int 33h
    mov button,bx
    mov mouse_x,cx
    mov mouse_y,dx
    }
    }

    void getmousedirection(void)
    {
    asm{
    mov ax,ress
    int 33h
    mov trshold,bx
    mov dirx,cx
    mov diry,dx
    }
    }

    void getmousespeed(void)
    {
    asm{
    mov ax,1bh
    int 33h
    mov bx,hspd
    mov cx,vspd
    mov dx,thv
    }
    }

    <-------- end of mouse.h

    C / C++ / MFC help c++ com game-dev

  • Handling mouse using OS interrupts
    S Software_Developer

    OS interrupts are only used in 16-bit MSDOS apps. More [here ] You can try this code for a WIN32 console app.

    #include #include using namespace std;

    int main()
    {
    HANDLE hIn;
    HANDLE hOut;
    COORD KeyWhere;
    COORD MouseWhere;
    COORD EndWhere;
    bool Continue = TRUE;
    int KeyEvents = 0;
    int MouseEvents = 0;
    INPUT_RECORD InRec;
    DWORD NumRead;

    hIn = GetStdHandle(STD\_INPUT\_HANDLE);
    hOut = GetStdHandle(STD\_OUTPUT\_HANDLE);
    
    cout << "Key Events   : " << endl;
    cout << "Mouse Events : " << flush;
    
    KeyWhere.X = 15;
    KeyWhere.Y = 0;
    MouseWhere.X = 15;
    MouseWhere.Y = 1;
    EndWhere.X = 0;
    EndWhere.Y = 3;
    
    while (Continue)
    {
        ReadConsoleInput(hIn,
                         &InRec,
                         1,
                         &NumRead);
    
        switch (InRec.EventType)
        {
        case KEY\_EVENT:
            ++KeyEvents;
            SetConsoleCursorPosition(hOut,
                                     KeyWhere);
            cout << KeyEvents << flush;
            if (InRec.Event.KeyEvent.uChar.AsciiChar == 'x')
            {
                SetConsoleCursorPosition(hOut,
                                         EndWhere);
                cout << "Exiting..." << endl;
                Continue = FALSE;
            }
            break;
    
        case MOUSE\_EVENT:
            ++MouseEvents;
            SetConsoleCursorPosition(hOut,
                                     MouseWhere);
            cout << MouseEvents << flush;
            break;
        }
    }
    
    return 0;
    

    }

    More : [here ]

    C / C++ / MFC help c++ com game-dev

  • how to read character by character from text file in c++?
    S Software_Developer

    Just put the file.get into a while statement.

    #include
    #include
    #include

    using namespace std;

    int main()
    {

    char singlecharacter ;
     
    ifstream file ("vurudi.txt");
    file.is\_open() ;
    
    while(file.get(singlecharacter))
    {
    	cout<
    
    C / C++ / MFC tutorial question c++
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups