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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Convert CString to UINT

Convert CString to UINT

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rohit dhamija 0
    wrote on last edited by
    #1

    :eek:Hi to everybody, I am developing a HotKey for my application. The RegisterHotKey function has following parameters: RegisterHotKey( HWND hWnd, // handle to window int id, // hot key identifier UINT fsModifiers, // key-modifier options UINT vk // virtual-key code ); I have values of fsModifier and vk in CString data type and I want to use those value in RegisterHotkey I tried using UINT fsModifier = atoi(ModifierKey); //ModifierKey is CString type but it didnot worked . Can some body tell me how to convert CString to UINT ?? Waiting for the reply Rohit

    J L 2 Replies Last reply
    0
    • R rohit dhamija 0

      :eek:Hi to everybody, I am developing a HotKey for my application. The RegisterHotKey function has following parameters: RegisterHotKey( HWND hWnd, // handle to window int id, // hot key identifier UINT fsModifiers, // key-modifier options UINT vk // virtual-key code ); I have values of fsModifier and vk in CString data type and I want to use those value in RegisterHotkey I tried using UINT fsModifier = atoi(ModifierKey); //ModifierKey is CString type but it didnot worked . Can some body tell me how to convert CString to UINT ?? Waiting for the reply Rohit

      J Offline
      J Offline
      John M Drescher
      wrote on last edited by
      #2

      Rohit Divas wrote: but it didnot worked . You have to be more specific about the problem. I will have to guess. Is there a compile error? Try this:

      UINT fsModifier = atoi((LPTSTR)(LPCSTR)ModifierKey);

      John

      R 1 Reply Last reply
      0
      • J John M Drescher

        Rohit Divas wrote: but it didnot worked . You have to be more specific about the problem. I will have to guess. Is there a compile error? Try this:

        UINT fsModifier = atoi((LPTSTR)(LPCSTR)ModifierKey);

        John

        R Offline
        R Offline
        rohit dhamija 0
        wrote on last edited by
        #3

        I mean to say that there were no errors in the program . Still it didnot worked. I debugged the application. The value of fsModifier in UINT fsModifier = atoi(ModifierKey); is coming 0. I tried your way also but the result is the same. Is there any alternative way to convert CString to UINT ? Rohit

        N J 2 Replies Last reply
        0
        • R rohit dhamija 0

          :eek:Hi to everybody, I am developing a HotKey for my application. The RegisterHotKey function has following parameters: RegisterHotKey( HWND hWnd, // handle to window int id, // hot key identifier UINT fsModifiers, // key-modifier options UINT vk // virtual-key code ); I have values of fsModifier and vk in CString data type and I want to use those value in RegisterHotkey I tried using UINT fsModifier = atoi(ModifierKey); //ModifierKey is CString type but it didnot worked . Can some body tell me how to convert CString to UINT ?? Waiting for the reply Rohit

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          I use atoi() fine. Check that there are no leading spaces, that would make it fail. CString::TrimLeft() will do it. Elaine :rose: The tigress is here :-D

          1 Reply Last reply
          0
          • R rohit dhamija 0

            I mean to say that there were no errors in the program . Still it didnot worked. I debugged the application. The value of fsModifier in UINT fsModifier = atoi(ModifierKey); is coming 0. I tried your way also but the result is the same. Is there any alternative way to convert CString to UINT ? Rohit

            N Offline
            N Offline
            nfactorial
            wrote on last edited by
            #5

            What does 'ModifierKey' contain? It does contain and begin with an integer doesn't it? Otherwise atoi will return 0. n!

            1 Reply Last reply
            0
            • R rohit dhamija 0

              I mean to say that there were no errors in the program . Still it didnot worked. I debugged the application. The value of fsModifier in UINT fsModifier = atoi(ModifierKey); is coming 0. I tried your way also but the result is the same. Is there any alternative way to convert CString to UINT ? Rohit

              J Offline
              J Offline
              John M Drescher
              wrote on last edited by
              #6

              There are other ways but this is the best way. Like the other people asked are you sure that the value in the string is an integer? Any errors in the conversion will result in 0. John

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

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