AutoHotkey Community

It is currently May 27th, 2012, 10:34 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 37 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject:
PostPosted: December 3rd, 2007, 4:31 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
The age old question: what is simpler? Majkinetor’s script creates a temp file, with all the associated difficulties: write permissions, overwriting existing files, disk quotas, etc. Also, the /p switch makes Notepad to print the document on the default printer, while selecting the Print menu item (or sending ^p) lets you choose the printer, therefore these scripts function differently, so you cannot compare their complexity.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 3rd, 2007, 4:57 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Imagine that I don't have open dialog in AHK and I want to open file.

Now, we have seen ways to do that as all dialogs are implemented in AHK. Using this kind of solution i would have to run notepad to pass it CTRL O, then let the user use the file, and finaly copy text from its edit to my own.

About your permissions and overwriting existing files: I can name file by guid, so that will eliminate overwriting question. Dis quotas ? cmon... Write Permission - this sound interesting, but again, you may need execute permision for Notepad, right?

I know that you are good in methaphisics, but please, lets get real.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 16th, 2007, 7:19 pm 
Offline

Joined: November 1st, 2007, 10:03 pm
Posts: 885
version 2.2 out


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 16th, 2007, 7:36 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
Interesting. You can also experiment with other window monitoring techniques:

Code:
; untested...

Print(txt) {
   Run, %A_WinDir%\notepad.exe, , Hide, pid
   WinWait, ahk_pid %pid%
   WinGet, id, ID, ahk_pid %pid%
   ControlSetText, Edit1, %txt%, ahk_id %id%
   WinMenuSelectItem, ahk_id %id%, , File, Print
   p = Print ahk_class #32770 ahk_pid %pid%
   WinWait, %p%
   WinWaitClose, Print ahk_class #32770 ahk_pid %pid%
   Sleep, 2500
   Process, Close, pid
   Return
}

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 25th, 2008, 11:07 pm 
Offline

Joined: November 1st, 2007, 10:03 pm
Posts: 885
cool hope you like it Titan and maj yours is not better (((((HAHA))))))


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 26th, 2008, 3:44 am 
Fry wrote:
maj yours is not better

obviously you have no sense of codes


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 26th, 2008, 3:49 am 
Offline

Joined: July 15th, 2007, 1:43 am
Posts: 1320
majkinetor wrote:
Laszlo wrote:
I understand that you can do it better, but you can hardly do it simpler.

Let me surprise you:

Code:
Print( edit ){
 FileAppend %edit%, tmp
 Run %A_Windows%\system32\NOTEPAD.EXE" /p tmp
 FileDelete, tmp
}


To my knowledge, all files in the System32 folder can be ran without a full file extension. i.e.

Code:
Run, Notepad ;Notepad >> %A_Windows%\system32\NOTEPAD.EXE
Run, Write ; Word Pad >> %A_Windows%\system32\Write.exe

The reason for this being, is that it either runs directly with, or on the same path as the Run (Win+R) box.

So you could simply put:

Code:
Run, Notepad /p File.txt

_________________
Religion is false. >_>


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 26th, 2008, 11:26 am 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
Ian wrote:
To my knowledge, all files in the System32 folder can be ran without a full file extension
The man. page for Run says this about the PID output variable parameter: "The variable will be made blank if the PID could not be determined, which usually happens if a system verb, document, or shortcut is launched rather than a direct executable file."

Since we need the PID and already know the absolute path we make it explicit.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 26th, 2008, 12:54 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Ian wrote:
The reason for this being, is that it either runs directly with, or on the same path as the Run (Win+R) box.

Not quite.

Kosovo wrote:
The man. page for Run says this about the PID output variable parameter: "The variable will be made blank if the PID could not be determined, which usually happens if a system verb, document, or shortcut is launched rather than a direct executable file."

Since we need the PID and already know the absolute path we make it explicit.

Why do you talk about my code and you don't even understand it (as always)?

The reason for Run command working like that is that simply A_WinDir is always in the PATH variable. You can use it like that with any executable.

path=%path%;c:\MyThing

Run MyThing.exe

_________________
Image


Last edited by majkinetor on January 26th, 2008, 4:27 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 26th, 2008, 1:08 pm 
Titan wrote:
Since we need the PID and already know the absolute path we make it explicit.

What PID has anything to do with the absolute path? Read about CreateProcess and ShellExecute(Ex).


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 26th, 2008, 9:23 pm 
Offline

Joined: July 15th, 2007, 1:43 am
Posts: 1320
Oh, and has everyone forgotten about Run, print?

Code:
Print(Edit) {
   IfExist, %Edit% ; Is File
   {
      Run, Print %Edit%
   }
   Else ; Is Text
   {
      FileAppend, %Edit%, %Temp%\tmp.txt
      Run, Print %Temp%\tmp.txt
      FileDelete, %Temp%\tmp.txt
   }
}


:)

Updated to handle both text and files.

_________________
Religion is false. >_>


Last edited by trik on January 26th, 2008, 9:42 pm, edited 4 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 26th, 2008, 9:36 pm 
Offline

Joined: November 1st, 2007, 10:03 pm
Posts: 885
:oops:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 26th, 2008, 9:45 pm 
Code:
PrintEBox(Edit) {
   Run notepad.exe,,,PID
   WinWait ahk_pid %PID%
   GuiControlGet, ToPrint,, %Edit%
   ControlSetText Edit1, %ToPrint%, ahk_pid %PID%
   WinMenuSelectItem ahk_pid %PID%,, File, Print
}

this is my version of this function


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 26th, 2008, 9:49 pm 
Offline

Joined: November 1st, 2007, 10:03 pm
Posts: 885
sarcastic RETARDDDDDDDD


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 26th, 2008, 10:01 pm 
Offline

Joined: June 26th, 2006, 6:14 pm
Posts: 1379
Location: USA
here is my version: (modified form Lexikos's code)
Code:
PrintEBox(Edit) {
   GuiControlGet, StringToPrint,, %Edit%
   Document_Name := A_ScriptName
   DllCall("LoadLibrary","str","comdlg32.dll")
   ;PRINTDIALOG_STRUCT
   VarSetCapacity(PRINTDIALOG_STRUCT,66,0), NumPut(66,PRINTDIALOG_STRUCT)
   ; PD_RETURNDEFAULT: Return hDevMode and hDevNames for default printer,
   ; instead of displaying the dialog.
   ; PD_RETURNDC: Return a printer device context.
   NumPut((PD_RETURNDC:=0x100),PRINTDIALOG_STRUCT,20) ; (PD_RETURNDC:=0x100)|(PD_RETURNDEFAULT:=0x400)
   if !DllCall("comdlg32\PrintDlgA","uint",&PRINTDIALOG_STRUCT)
      return
   ; Free unneeded (for now) structures created by PrintDlg().
   if (hDevMode := NumGet(PRINTDIALOG_STRUCT,8))
      DllCall("GlobalFree","uint",hDevMode)
   if (hDevNames := NumGet(PRINTDIALOG_STRUCT,12))
      DllCall("GlobalFree","uint",hDevNames)
   ; Get the newly created printer device context.
   if (hDC := NumGet(PRINTDIALOG_STRUCT,16))
      {
      VarSetCapacity(DOCUMENTINFO_STRUCT,20,0), NumPut(20,DOCUMENTINFO_STRUCT), NumPut(&Document_Name,DOCUMENTINFO_STRUCT,4)
      if DllCall("StartDoc","uint",hDC,"uint",&DOCUMENTINFO_STRUCT,"int") > 0
         {
         if DllCall("StartPage","uint",hDC,"int") > 0
            {
            DllCall("TextOut","uint",hDC,"int",xPos,"int",yPos,"str",StringToPrint,"int",StrLen(StringToPrint))
            DllCall("EndPage","uint",hDC,"int")
            }
         DllCall("EndDoc","uint",hDC)
         }
      DllCall("DeleteDC","uint",hDC)
      
      }
   }

_________________
Image
ʞɔпɟ əɥʇ ʇɐɥʍ


Last edited by ahklerner on January 26th, 2008, 10:12 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 37 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot] and 10 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group