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
A

Andrzej Markowski

@Andrzej Markowski
About
Posts
43
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • How to close other processes?
    A Andrzej Markowski

    Posting WM_CLOSE message to the main thread using PostThreadMessage doesn't close your application also. You have to post WM_CLOSE message to all windows on the main thread, as vikrams said. Here's the code how to do this :

    // define callback function like below
    BOOL CALLBACK EnumThreadWndProc(HWND hwnd, LPARAM lParam)
    {
    ::PostMessage(hwnd,WM_CLOSE,0,0);
    return TRUE;
    }
    // call EnumThreadWindows instead of PostThreadMessage
    EnumThreadWindows(rp[option-1].dwThreadId,EnumThreadWndProc,0);

    Regards, Andrzej Markowski

    My Latest ArticlesCCustomBitmapButton: An owner-draw button and a frame for the caption bar, in one class. CCustomTabCtrl: A clone of the Excel tab sheet control.

    C / C++ / MFC tutorial question

  • How to close other processes?
    A Andrzej Markowski

    Very Important!!!! Don't use WM_QUIT message to kill other processes. Instead of WM_QUIT use WM_CLOSE. If you send WM_QUIT the application will not clean up resources and you will have memory leaks. Regards, Andrzej Markowski

    My Latest ArticlesCCustomBitmapButton: An owner-draw button and a frame for the caption bar, in one class. CCustomTabCtrl: A clone of the Excel tab sheet control.

    C / C++ / MFC tutorial question

  • How to close other processes?
    A Andrzej Markowski

    Your program has to save the ThreadId for each new created process. Later the ThreadId is passed as the parameter to the PostThreadMessage function which is called to close the program the user opened. The modified example saves this information in the rp array of RUNNING_PROCESS_INFO structures. The nRPCounter specifies a number of currently running processes and also is the next avaliable index in the rp table. When the process is created a space for the RUNNING_PROCESS_INFO structure is allocated at the and of the array and the nRPCounter is incremented. When the user closes the program the counter is decremented and the structures in the array located below deleted item are moved one item up.

    #include stdio.h
    #include process.h
    #include iostream.h
    #include time.h
    #include windows.h

    typedef struct
    {
    DWORD dwThreadId;
    BYTE bProcessType; // 1 - FreeCell 2 - MineSweeper 3 - Paint
    } RUNNING_PROCESS_INFO;

    #define MAX_PROCESSES 10
    RUNNING_PROCESS_INFO rp[MAX_PROCESSES];
    int nRPCounter = 0; // running processes counter

    int DisplayMainMenu();
    void DisplayStopProcessMenu();
    void process(int option);

    int main(int argc, char* argv[])
    {
    while(DisplayMainMenu()!=5);
    return 0;
    }

    int DisplayMainMenu()
    {
    int option=0;
    system("cls");
    cout << "\n\n\n";
    cout << "\n\t*********************************";
    cout << "\n\t* *";
    cout << "\n\t* MAIN MENU *";
    cout << "\n\t* *";
    cout << "\n\t* 1. FreeCell *";
    cout << "\n\t* 2. MineSweeper *";
    cout << "\n\t* 3. Paint *";
    cout << "\n\t* 4. StopProcess *";
    cout << "\n\t* 5. Quit *";
    cout << "\n\t* *";
    cout << "\n\t*********************************";
    cout << "\n\nPlease type your choice "<< "and press the return key : ";
    cin >> option;

    process(option);
    
    return option;
    

    }

    void DisplayStopProcessMenu()
    {
    int option=0;
    system("cls");
    cout << "\n\n\n";
    cout << "\n\t*********************************";
    cout << "\n\t* *";
    cout << "\n\t* STOP PROCESS MENU *";
    cout << "\n\t* *";
    for(int i=0;i> option;
    if(option>=1 && option<=nRPCounter)
    {
    PostThreadMessage(rp[option-1].dwThreadId,WM_QUIT,0,0);
    nRPCounter--;
    for(int

    C / C++ / MFC tutorial question

  • Where is wrong when I try to get the recordset?
    A Andrzej Markowski

    http://www.codeguru.com/forum/showthread.php?t=314031 Regards, Andrzej Markowski

    My Latest ArticlesCCustomBitmapButton: An owner-draw button and a frame for the caption bar, in one class. CCustomTabCtrl: A clone of the Excel tab sheet control.

    C / C++ / MFC c++ database oracle help question

  • How to close other processes?
    A Andrzej Markowski

    You should declare the arrays (si and pi) as global variables. Also you can't call the DisplayMenu from within the process function (recursion). Here's an example how to fix these problems:

    STARTUPINFO si[3];
    PROCESS_INFORMATION pi[3];

    int DisplayMenu();
    void process(int option);

    void main()
    {
    ZeroMemory( &si[0], sizeof(si[0]) );
    si[0].cb = sizeof(si[0]);
    ZeroMemory( &pi[0], sizeof(pi[0]) );

    ZeroMemory( &si[1], sizeof(si[1]) );
    si[1].cb = sizeof(si[1]);
    ZeroMemory( &pi[1], sizeof(pi[1]) );

    ZeroMemory( &si[2], sizeof(si[2]) );
    si[2].cb = sizeof(si[2]);
    ZeroMemory( &pi[2], sizeof(pi[2]) );

    while(DisplayMenu()!=4)
    return;
    }

    int DisplayMenu()
    {
    int option;
    system("cls");
    cout << "\n\n\n";
    cout << "\n\t*********************************";
    cout << "\n\t* *";
    cout << "\n\t* MENU *";
    cout << "\n\t* *";
    cout << "\n\t* 1. FreeCell *";
    cout << "\n\t* 2. MineSweeper *";
    cout << "\n\t* 3. Paint *";
    cout << "\n\t* 4. Quit *";
    cout << "\n\t* *";
    cout << "\n\t*********************************";

    cout << "\n\nPlease type your choice "
    << "and press the return key : ";

    cin >> option;
    process(option);
    return option;
    }

    void process(int option)
    {
    switch (option)
    {
    case 1 : if(pi[0].hProcess==NULL)CreateProcess( NULL,
    "FreeCell.exe",
    NULL,
    NULL,
    FALSE,
    NULL,
    NULL,
    NULL,
    &si[0],
    &pi[0]);

    break;

    case 2 : if(pi[1].hProcess==NULL)CreateProcess( NULL,
    "winmine.exe",
    NULL,
    NULL,
    FALSE,
    NULL,
    NULL,
    NULL,
    &si[1],
    &pi[1]);

    break;

    case 3 : if(pi[2].hProcess==NULL)CreateProcess( NULL,
    "MsPaint.exe", // Command line.
    NULL,
    NULL,
    FALSE,
    NULL,
    NULL,
    NULL,
    &si[2],
    &pi[2]);

    break;

    case 4 : if(pi[0].hProcess)::PostThreadMessage(pi[0].dwThreadId,WM_QUIT,0,0);
    if(pi[1].hProcess)::PostThreadMessage(pi[1].dwThreadId,WM_QUIT,0,0);
    if(pi[2].hProcess)::PostThreadMessage(pi[2].dwThreadId,WM_QUIT,0,0);
    CloseHandle( pi[0].hProcess );
    CloseHandle( pi[0].hThread );
    CloseHandle( pi[1].hProcess );
    CloseHandle( pi[1].hThread );
    CloseHandle( pi[2].hProcess );
    CloseHandle( pi[2].hThread );
    // CloseHandle( pi[3].hProcess );
    // CloseHandle( pi[3].hThread );

    break;

    default : printf("\a\aOption Not Available\n");
    break;
    }

    return;
    }

    Regards, Andrzej Markowski

    My Latest Articles

    C / C++ / MFC tutorial question

  • How to close other processes?
    A Andrzej Markowski

    Change the code like this: PROCESS_INFORMATION pi[3]; // for each process STARTUPINFO si[3];// init structures ZeroMemory( &si[0], sizeof(STARTUPINFO)); si[0].cb = sizeof(STARTUPINFO); ZeroMemory( &pi[0], sizeof(PROCESS_INFORMATION)); ZeroMemory( &si[1], sizeof(STARTUPINFO)); si[1].cb = sizeof(STARTUPINFO); ZeroMemory( &pi[1], sizeof(PROCESS_INFORMATION)); ZeroMemory( &si[2], sizeof(STARTUPINFO)); si[2].cb = sizeof(STARTUPINFO); ZeroMemory( &pi[2], sizeof(PROCESS_INFORMATION)); Regards, Andrzej Markowski

    My Latest ArticlesCCustomBitmapButton: An owner-draw button and a frame for the caption bar, in one class. CCustomTabCtrl: A clone of the Excel tab sheet control.

    C / C++ / MFC tutorial question

  • How to close other processes?
    A Andrzej Markowski

    Send WM_QUIT message to each running application.

    PROCESS_INFORMATION pi[3]; // for each process
    STARTUPINFO si[3];
    // init structures
    ZeroMemory( &si[0], sizeof(si[0]) );
    si.cb = sizeof(si[0]);
    ZeroMemory( &pi[0], sizeof(pi[0]) );

    ZeroMemory( &si[1], sizeof(si[1]) );
    si.cb = sizeof(si[1]);
    ZeroMemory( &pi[1], sizeof(pi[1]) );

    ZeroMemory( &si[2], sizeof(si[2]) );
    si.cb = sizeof(si[2]);
    ZeroMemory( &pi[2], sizeof(pi[2]) );

    // start appications
    if(pi[0].hProcess==NULL)
    CreateProcess( NULL, "C://FreeCell.exe",NULL,NULL,FALSE,NULL,NULL,NULL,&si[0],&pi[0]));
    if(pi[1].hProcess==NULL)
    CreateProcess( NULL, "winmine.exe",NULL,NULL,FALSE,NULL,NULL,NULL,&si[1],&pi[1]);
    if(pi[2].hProcess==NULL)
    CreateProcess( NULL, "MsPaint.exe",NULL,NULL,FALSE, NULL,NULL,NULL,&si[2],&pi[2]);

    // shutdown applications
    if(pi[0].hProcess)
    ::PostThreadMessage(pi[0].dwThreadId,WM_QUIT,0,0);
    if(pi[1].hProcess)
    ::PostThreadMessage(pi[1].dwThreadId,WM_QUIT,0,0);
    if(pi[2].hProcess)
    ::PostThreadMessage(pi[2].dwThreadId,WM_QUIT,0,0);

    CloseHandle( pi[0].hProcess );
    CloseHandle( pi[0].hThread );
    CloseHandle( pi[1].hProcess );
    CloseHandle( pi[1].hThread );
    CloseHandle( pi[2].hProcess );
    CloseHandle( pi[2].hThread );

    Regards, Andrzej Markowski

    My Latest ArticlesCCustomBitmapButton: An owner-draw button and a frame for the caption bar, in one class. CCustomTabCtrl: A clone of the Excel tab sheet control.

    C / C++ / MFC tutorial question

  • printf in C
    A Andrzej Markowski

    Or use %c in the format string printf(" Error is %.2f %c",val,'%'); Regards, Andrzej Markowski

    My Latest ArticlesCCustomBitmapButton: An owner-draw button and a frame for the caption bar, in one class. CCustomTabCtrl: A clone of the Excel tab sheet control.

    C / C++ / MFC help question

  • Problem occurred ...please help
    A Andrzej Markowski

    You could use CString to convert from UNICODE to char string like this: m_lbParties.AddString(CString(bstrParty)) or use WideCharToMultiByte function. You must also create list box before you call AddString. Regards, Andrzej Markowski

    My Latest ArticlesCCustomBitmapButton: An owner-draw button and a frame for the caption bar, in one class. CCustomTabCtrl: A clone of the Excel tab sheet control.

    C / C++ / MFC help question

  • Disable Move
    A Andrzej Markowski

    Congratulations!!! Good question. I wasted two hours of my life today doing this s..t for you. Below is a solution of the problem:

    BOOL CYourDlg::PreTranslateMessage(MSG* pMsg)
    {
    if((pMsg->message==WM_NCLBUTTONDOWN && SendMessage(WM_NCHITTEST,0,pMsg->lParam)==HTSYSMENU) ||
    (pMsg->message==WM_NCRBUTTONDOWN && SendMessage(WM_NCHITTEST,0,pMsg->lParam)==HTCAPTION))
    {
    CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
    if(GetStyle()&WS_THICKFRAME)
    pSysMenu->EnableMenuItem(SC_SIZE,MF_BYCOMMAND|MF_ENABLED);
    else
    pSysMenu->EnableMenuItem(SC_SIZE,MF_BYCOMMAND|MF_GRAYED);
    if(GetStyle()&WS_MINIMIZEBOX||GetStyle()&WS_MAXIMIZEBOX)
    {
    if(GetStyle()&WS_MINIMIZEBOX)
    {
    if(IsIconic())
    {
    pSysMenu->EnableMenuItem(SC_MINIMIZE,MF_BYCOMMAND|MF_GRAYED);
    pSysMenu->EnableMenuItem(SC_RESTORE,MF_BYCOMMAND|MF_ENABLED);
    }
    else
    {
    pSysMenu->EnableMenuItem(SC_MINIMIZE,MF_BYCOMMAND|MF_ENABLED);
    pSysMenu->EnableMenuItem(SC_RESTORE,MF_BYCOMMAND|MF_GRAYED);
    }
    }
    else
    pSysMenu->EnableMenuItem(SC_MINIMIZE,MF_BYCOMMAND|MF_GRAYED);
    if(GetStyle()&WS_MAXIMIZEBOX)
    {
    if(IsZoomed())
    {
    pSysMenu->EnableMenuItem(SC_MAXIMIZE,MF_BYCOMMAND|MF_GRAYED);
    pSysMenu->EnableMenuItem(SC_RESTORE,MF_BYCOMMAND|MF_ENABLED);
    }
    else
    {
    pSysMenu->EnableMenuItem(SC_MAXIMIZE,MF_BYCOMMAND|MF_ENABLED);
    pSysMenu->EnableMenuItem(SC_RESTORE,MF_BYCOMMAND|MF_GRAYED);
    }
    }
    else
    pSysMenu->EnableMenuItem(SC_MAXIMIZE,MF_BYCOMMAND|MF_GRAYED);
    }

    pSysMenu->EnableMenuItem(SC_MOVE,MF_BYCOMMAND|MF_GRAYED); // gray MOVE item
    int nRet = pSysMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON|TPM_RETURNCMD, LOWORD(pMsg->lParam), HIWORD(pMsg->lParam), this);
    PostMessage(WM_SYSCOMMAND,nRet,pMsg->lParam);
    return 1;
    }
    }
    return CDialog::PreTranslateMessage(pMsg);
    }

    Regards, Andrzej Markowski

    My Latest ArticlesCCustomBitmapButton: An owner-draw button and a frame for the caption bar, in one class. CCustomTabCtrl: A clone of the Excel tab sheet control.

    C / C++ / MFC help

  • question about comparison of DWORD; WPARAM
    A Andrzej Markowski

    To extract information from the return value of CHotKeyCtrl.GetHotKey() use HIWORD and LOWORD macros. wVirtualKeyCode=LOWORD(GetHotKey()); wModifiers=HIWORD(GetHotKey()); To create WPARAM use MAKEWPARAM macro: MAKEWPARAM(wVirtualKeyCode,wModifiers) To compare DWORD to WPARAM use: if(wParam==(WPARAM)dwValue) Regards, Andrzej Markowski

    My Latest ArticlesCCustomBitmapButton: An owner-draw button and a frame for the caption bar, in one class. CCustomTabCtrl: A clone of the Excel tab sheet control.

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

  • UNICODE option in VC6 projects?
    A Andrzej Markowski

    First add two new unicode configurations (for debug and release) to the project (Build->Configurations->Add). Next add the following definition /D "_UNICODE" in preprocessor definitions of your unicode projects (Project->Settings->Preprocessor definitions). Regards, Andrzej Markowski

    My Latest ArticlesCCustomBitmapButton: An owner-draw button and a frame for the caption bar, in one class. CCustomTabCtrl: A clone of the Excel tab sheet control.

    C / C++ / MFC c++ csharp dotnet com question

  • ASM instruction /opcode: normalize a double value
    A Andrzej Markowski

    The real numbers are always stored in normalized form. The high-order bit of the mantissa is always 1 and it is not stored in the real*4 and real*8 formats. More info: MSDN Library Visual Studio 6.0 - "IEEE Floating-Point Representation and Microsoft Languages". Regards, Andrzej Markowski

    My Latest ArticlesCCustomBitmapButton: An owner-draw button and a frame for the caption bar, in one class. CCustomTabCtrl: A clone of the Excel tab sheet control.

    C / C++ / MFC c++ html com design business

  • Dialog app - menu
    A Andrzej Markowski

    This is a working example:

    CMenu m_menu; // declared in CYourDlg header file
    //
    // Load the menu and assign to the dialog
    BOOL CYourDlg::OnInitDialog()
    {
    ...
    m_menu.LoadMenu(IDR_MENU1);
    SetMenu(&m_menu);
    ...
    }
    // on menu command (ID_XXX) message-handler function
    void CYourDlg::OnMenuXXXCommand()
    {
    CMenu * menu = GetMenu();
    if(menu)
    {
    // check/uncheck the menu item
    CMenu* pPopup = menu->GetSubMenu(0);
    if(pPopup->GetMenuState(ID_XXX,MF_BYCOMMAND)&MF_CHECKED)
    pPopup->CheckMenuItem(ID_XXX, MF_BYCOMMAND | MF_UNCHECKED);
    else
    pPopup->CheckMenuItem(ID_XXX, MF_BYCOMMAND | MF_CHECKED);
    // do something
    }
    // on some button click message-handler function
    void CYourDlg::OnButtonClick()
    {
    // show/hide the menu
    if(GetMenu())
    SetMenu(NULL);
    else
    SetMenu(&m_menu);
    }

    Regards, Andrzej Markowski

    My Latest ArticlesCCustomBitmapButton: An owner-draw button and a frame for the caption bar, in one class. CCustomTabCtrl: A clone of the Excel tab sheet control.

    C / C++ / MFC question

  • EN_CHANGE
    A Andrzej Markowski

    This is a working code:

    LRESULT CALLBACK wndproc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
    {
    switch (message)
    {
    case WM_COMMAND:
    // (HWND) lParam - handle of control
    // LOWORD(wParam) - item, control, or accelerator identifier
    // HIWORD(wParam) - notification code

    if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
    {
    EndDialog(hDlg, LOWORD(wParam));
    return TRUE;
    }
    else if(LOWORD(wParam) == IDC_EDIT1)
    {
    switch(HIWORD(wParam))
    {
    case EN_CHANGE:
    MessageBox(NULL,"EN_CHANGE","Edit Notify",MB_OK);
    return TRUE;
    case EN_UPDATE:
    MessageBox(NULL,"EN_UPDATE","Edit Notify",MB_OK);
    return TRUE;
    }
    }
    break;
    }
    return FALSE;
    }

    ____________________ A.M.

    C / C++ / MFC help c++ delphi json

  • Printing bitmap
    A Andrzej Markowski

    You should use the DIB (device independant bitmap) and the StretchDIBits function to print your bitmap. More info here: http://www.codeguru.com/forum/showthread.php?t=234177 ____________________ A.M.

    C / C++ / MFC graphics help

  • Printing help!
    A Andrzej Markowski

    If you use the DDB (device dependant bitmap) and the BitBlt function to print your bitmap you will find the answer here: http://www.codeguru.com/forum/showthread.php?t=234177 ____________________ A.M.

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

  • MFC GetDlgItemText
    A Andrzej Markowski

    A few sugestions: #1 Make shure you call SetCurSel() in OnInitDialog of the property page, otherwise the string will be empty. #2 Make shure if id of your combobox is equal IDC_COMBO1 and is not assigned to another control #3 If the combobox is placed on the property page, use this: pPropertySheet->GetPage(PageNo)->GetDlgWindowText(IDC_COMBO1,s). ***** A.M.

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

  • Using btimap resource from dll
    A Andrzej Markowski

    Do the following steps:

    CBitmap bmpYourBitmap; // your bitmap
    CDC *pDC; // device context for painting
    //
    // 1. Create a memory device context:
    CDC memDC;
    memDC.CreateCompatibleDC(pDC);
    //
    // 2. Select your bitmap into memDC:
    CBitmap *pOldBmp = memDc.SelectObject(&bmpYourBitmap);
    //
    // 3. Get the size of bmpYourBitmap:
    BITMAP bm;
    bmpYouBitmap.GetBitmap(&bm);
    //
    // 4. Paint the bitmap:
    pDC->BitBlt(0,0,bm.bmWidth,bm.bmHeight,&memDC,0,0,SRCCOPY);
    memDc.SelectObject(pOldBmp);

    C / C++ / MFC question graphics learning

  • Deleting objects using abstract base class pointers
    A Andrzej Markowski

    I can't find any relation between the base class virtual/non virtual destructor and delete operator. Could you explain your message?

    C / C++ / MFC help css data-structures debugging tutorial
  • Login

  • Don't have an account? Register

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