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#
  4. Receives a question mark when trying to see active window open in my program

Receives a question mark when trying to see active window open in my program

Scheduled Pinned Locked Moved C#
helpquestiontutorial
2 Posts 2 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.
  • G Offline
    G Offline
    goldsoft
    wrote on last edited by
    #1

    hi I built Software that grabbing weight and throw into open window where the cursor is. Everything worked out well - I only have one problem annoying Receives a question mark **(?)** when I open **Word**. and Then the software hangs not recognize the window properly. when i open Word i see Word? - 123.docx for example. And even if I remove the question mark, the software is still stuck in this case. my code: [DllImport("user32.dll")] static extern IntPtr GetForegroundWindow(); [DllImport("user32.dll")] static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count); private string GetActiveWindowTitle() { const int nChars = 256; StringBuilder Buff = new StringBuilder(nChars); IntPtr handle = GetForegroundWindow(); if (GetWindowText(handle, Buff, nChars) > 0) { return Buff.ToString(); } return null; } [DllImport("user32.dll")] private static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("user32.dll")] private static extern bool SetForegroundWindow(IntPtr hWnd); public void Start(string NAME) { MSG = lblMSG.Text.Trim(); IntPtr zero = IntPtr.Zero; for (int i = 0; (i < 60) && (zero == IntPtr.Zero); i++) { Thread.Sleep(500); zero = FindWindow(null, NAME); } if (zero != IntPtr.Zero) { . . . } } what is the problem ? how to fix it ? thanks

    L 1 Reply Last reply
    0
    • G goldsoft

      hi I built Software that grabbing weight and throw into open window where the cursor is. Everything worked out well - I only have one problem annoying Receives a question mark **(?)** when I open **Word**. and Then the software hangs not recognize the window properly. when i open Word i see Word? - 123.docx for example. And even if I remove the question mark, the software is still stuck in this case. my code: [DllImport("user32.dll")] static extern IntPtr GetForegroundWindow(); [DllImport("user32.dll")] static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count); private string GetActiveWindowTitle() { const int nChars = 256; StringBuilder Buff = new StringBuilder(nChars); IntPtr handle = GetForegroundWindow(); if (GetWindowText(handle, Buff, nChars) > 0) { return Buff.ToString(); } return null; } [DllImport("user32.dll")] private static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("user32.dll")] private static extern bool SetForegroundWindow(IntPtr hWnd); public void Start(string NAME) { MSG = lblMSG.Text.Trim(); IntPtr zero = IntPtr.Zero; for (int i = 0; (i < 60) && (zero == IntPtr.Zero); i++) { Thread.Sleep(500); zero = FindWindow(null, NAME); } if (zero != IntPtr.Zero) { . . . } } what is the problem ? how to fix it ? thanks

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

      Are you sure that it is a question-mark, and not another character that it cannot/will not display?

      [DllImport("user32.dll", CharSet = CharSet.Unicode)]

      Try to add this attribute to your P/invokes and see if it helps.

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

      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